@ComponentProfile(summary="Construct a new payload based on metadata and a template", tag="service,metadata", since="3.10.0") public class PayloadFromTemplateService extends ServiceImp
Takes the template stored in setTemplate(String)
and replaces parts of the template either by resolving the
%message
expression language or with values from various metadata keys specified in
setMetadataTokens(KeyValuePairSet)
to create a new payload. This replaces PayloadFromMetadataService
.
Since under the covers it uses the JDK regular expression engine, take care when your replacement may contain special regular
expression characters (such as \
and $
In the adapter configuration file this class is aliased as payload-from-template which is the preferred alternative to the fully qualified classname when building your configuration.
log
Constructor and Description |
---|
PayloadFromTemplateService() |
Modifier and Type | Method and Description |
---|---|
protected void |
closeService() |
void |
doService(AdaptrisMessage msg)
Apply the service to the message.
|
KeyValuePairSet |
getMetadataTokens() |
java.lang.Boolean |
getMultiLineExpression() |
java.lang.Boolean |
getQuiet() |
java.lang.Boolean |
getQuoteReplacement() |
java.lang.String |
getTemplate() |
protected void |
initService() |
protected boolean |
multiLineExpression() |
void |
prepare()
Prepare for initialisation.
|
protected boolean |
quoteReplacement() |
void |
setMetadataTokens(KeyValuePairSet metadataTokens)
Set the metadata tokens that will be used to perform metadata substitution.
|
void |
setMultiLineExpression(java.lang.Boolean b)
Whether or not to handle expressions using
Pattern#DOTALL mode for matching. |
void |
setQuiet(java.lang.Boolean quiet)
Normally this service logs everything that is being replaced with can lead to excessive logging.
|
void |
setQuoteReplacement(java.lang.Boolean b)
If any metadata value contains special characters then ensure that they are escaped.
|
void |
setTemplate(java.lang.String s)
Set the template document that will be used as the template for generating a new document.
|
<T extends PayloadFromTemplateService> |
withMetadataTokens(KeyValuePairSet tokens) |
<T extends PayloadFromTemplateService> |
withMetadataTokens(java.util.Map<java.lang.String,java.lang.String> tokens) |
<T extends PayloadFromTemplateService> |
withMultiLineExpression(java.lang.Boolean b) |
<T extends PayloadFromTemplateService> |
withQuietMode(java.lang.Boolean quiet) |
<T extends PayloadFromTemplateService> |
withQuoteReplacement(java.lang.Boolean b) |
<T extends PayloadFromTemplateService> |
withTemplate(java.lang.String b) |
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
public void doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
sprotected void initService() throws CoreException
initService
in class ServiceImp
CoreException
protected void closeService()
closeService
in class ServiceImp
public void prepare() throws CoreException
ComponentLifecycleExtension
CoreException
public KeyValuePairSet getMetadataTokens()
public void setMetadataTokens(KeyValuePairSet metadataTokens)
For the purposes of this service, the key to the key-value-pair is the metadata key, and the value is the token that will be replaced within the template
metadataTokens
- the metadataTokens to setpublic <T extends PayloadFromTemplateService> T withMetadataTokens(KeyValuePairSet tokens)
public <T extends PayloadFromTemplateService> T withMetadataTokens(java.util.Map<java.lang.String,java.lang.String> tokens)
public java.lang.String getTemplate()
public void setTemplate(java.lang.String s)
s
- the template to set (supports metadata expansion via %message{key}
).public <T extends PayloadFromTemplateService> T withTemplate(java.lang.String b)
public java.lang.Boolean getQuoteReplacement()
public void setQuoteReplacement(java.lang.Boolean b)
Set this flag to make sure that special characters are treated literally by the regular expression engine.
b
- the value to set, defaults to true if not explicitly configured.Matcher.quoteReplacement(String)
public <T extends PayloadFromTemplateService> T withQuoteReplacement(java.lang.Boolean b)
protected boolean quoteReplacement()
public java.lang.Boolean getQuiet()
public void setQuiet(java.lang.Boolean quiet)
quiet
- true or false, default false if not specified.public <T extends PayloadFromTemplateService> T withQuietMode(java.lang.Boolean quiet)
public java.lang.Boolean getMultiLineExpression()
public void setMultiLineExpression(java.lang.Boolean b)
Pattern#DOTALL
mode for matching.
The value here is passed to InterlokMessage.resolve(String, boolean)
. True will allow you to do replacements on
multi-line templates; It defaults to true which means that multi-line templates along the lines of will be supported.
{
"key": "%message{metadataKey}",
"key2: "%message{anotherMetadatKey}",
}
b
- true/false, default is true if not specified.public <T extends PayloadFromTemplateService> T withMultiLineExpression(java.lang.Boolean b)
protected boolean multiLineExpression()