Class TemplateProcessor
- java.lang.Object
-
- org.apache.synapse.mediators.transform.pfutils.TemplateProcessor
-
- Direct Known Subclasses:
FreeMarkerTemplateProcessor
,RegexTemplateProcessor
public abstract class TemplateProcessor extends Object
Abstract TemplateProcessor. This is the class using by the
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
ESCAPE_BACK_SLASH_WITH_SIXTEEN_BACK_SLASHES
protected static String
ESCAPE_BACKSPACE_WITH_EIGHT_BACK_SLASHES
protected static String
ESCAPE_CRETURN_WITH_EIGHT_BACK_SLASHES
protected static String
ESCAPE_DOLLAR_WITH_SIX_BACK_SLASHES
protected static String
ESCAPE_DOLLAR_WITH_TEN_BACK_SLASHES
protected static String
ESCAPE_DOUBLE_QUOTE_WITH_FIVE_BACK_SLASHES
protected static String
ESCAPE_DOUBLE_QUOTE_WITH_NINE_BACK_SLASHES
protected static String
ESCAPE_FORMFEED_WITH_EIGHT_BACK_SLASHES
protected static String
ESCAPE_NEWLINE_WITH_EIGHT_BACK_SLASHES
protected static String
ESCAPE_TAB_WITH_EIGHT_BACK_SLASHES
protected XMLInputFactory
inputFactory
protected static String
JSON_TYPE
protected static String
STRING_TYPE
protected static String
TEXT_TYPE
protected static String
XML_TYPE
-
Constructor Summary
Constructors Constructor Description TemplateProcessor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addPathArgument(Argument arg)
protected org.apache.axiom.om.OMElement
convertStringToOM(String value)
Converts String to OMElementprotected String
escapeSpecialCharactersOfJson(String jsonString)
Replace special characters of a JSON string.protected String
escapeSpecialCharactersOfXml(String xmlString)
Replace special characters of a XML string.protected String
escapeSpecialChars(String replaceString)
Helper method to replace required char values with escape characters.protected String
escapeXMLSpecialChars(String replaceString)
Helper method to replace required char values with escape characters for XML.protected HashMap<String,ArgumentDetails>[]
getArgValues(String mediaType, MessageContext synCtx)
Goes through SynapsePath argument list, evaluating each by calling stringValueOf and returns a HashMap String, String array where each item will contain a hash map with key "evaluated expression" and value "SynapsePath type".String
getFormat()
String
getMediaType()
List<Argument>
getPathArgumentList()
abstract boolean
getTemplateStatus()
protected void
handleException(String msg)
protected String
inferReplacementType(Map.Entry<String,ArgumentDetails> entry)
Helper function that takes a Map of String, ArgumentDetails where key contains the value of an evaluated SynapsePath expression and value contains the type of SynapsePath + deepcheck status in use.abstract void
init()
Execute pre-processing steps if neededprotected boolean
isEscapeXmlChars()
protected boolean
isJson(String value)
Helper function that returns true if value passed is of JSON type.protected boolean
isXML(String value)
Helper function that returns true if value passed is of XML Type.protected String
prepareReplacementValue(String mediaType, MessageContext synCtx, Map.Entry<String,ArgumentDetails> replacementEntry)
Preprocess and converty types of the given arg value.abstract String
processTemplate(String template, String mediaType, MessageContext synCtx)
Process the given template and return the output as Stringvoid
readInputFactoryProperties()
Read XMLInputFactory properties from XMLInputFactory.properties file.void
setEscapeXmlChars(boolean escapeXmlChars)
void
setFormat(String format)
void
setMediaType(String mediaType)
-
-
-
Field Detail
-
JSON_TYPE
protected static final String JSON_TYPE
- See Also:
- Constant Field Values
-
XML_TYPE
protected static final String XML_TYPE
- See Also:
- Constant Field Values
-
TEXT_TYPE
protected static final String TEXT_TYPE
- See Also:
- Constant Field Values
-
STRING_TYPE
protected static final String STRING_TYPE
- See Also:
- Constant Field Values
-
ESCAPE_DOUBLE_QUOTE_WITH_FIVE_BACK_SLASHES
protected static final String ESCAPE_DOUBLE_QUOTE_WITH_FIVE_BACK_SLASHES
- See Also:
- Constant Field Values
-
ESCAPE_DOUBLE_QUOTE_WITH_NINE_BACK_SLASHES
protected static final String ESCAPE_DOUBLE_QUOTE_WITH_NINE_BACK_SLASHES
- See Also:
- Constant Field Values
-
ESCAPE_BACK_SLASH_WITH_SIXTEEN_BACK_SLASHES
protected static final String ESCAPE_BACK_SLASH_WITH_SIXTEEN_BACK_SLASHES
- See Also:
- Constant Field Values
-
ESCAPE_DOLLAR_WITH_SIX_BACK_SLASHES
protected static final String ESCAPE_DOLLAR_WITH_SIX_BACK_SLASHES
- See Also:
- Constant Field Values
-
ESCAPE_DOLLAR_WITH_TEN_BACK_SLASHES
protected static final String ESCAPE_DOLLAR_WITH_TEN_BACK_SLASHES
- See Also:
- Constant Field Values
-
ESCAPE_BACKSPACE_WITH_EIGHT_BACK_SLASHES
protected static final String ESCAPE_BACKSPACE_WITH_EIGHT_BACK_SLASHES
- See Also:
- Constant Field Values
-
ESCAPE_FORMFEED_WITH_EIGHT_BACK_SLASHES
protected static final String ESCAPE_FORMFEED_WITH_EIGHT_BACK_SLASHES
- See Also:
- Constant Field Values
-
ESCAPE_NEWLINE_WITH_EIGHT_BACK_SLASHES
protected static final String ESCAPE_NEWLINE_WITH_EIGHT_BACK_SLASHES
- See Also:
- Constant Field Values
-
ESCAPE_CRETURN_WITH_EIGHT_BACK_SLASHES
protected static final String ESCAPE_CRETURN_WITH_EIGHT_BACK_SLASHES
- See Also:
- Constant Field Values
-
ESCAPE_TAB_WITH_EIGHT_BACK_SLASHES
protected static final String ESCAPE_TAB_WITH_EIGHT_BACK_SLASHES
- See Also:
- Constant Field Values
-
inputFactory
protected final XMLInputFactory inputFactory
-
-
Method Detail
-
processTemplate
public abstract String processTemplate(String template, String mediaType, MessageContext synCtx)
Process the given template and return the output as String- Parameters:
template
- Template stringmediaType
- Output media typesynCtx
- MessageContext- Returns:
- The processed output
-
init
public abstract void init()
Execute pre-processing steps if needed
-
getArgValues
protected HashMap<String,ArgumentDetails>[] getArgValues(String mediaType, MessageContext synCtx)
Goes through SynapsePath argument list, evaluating each by calling stringValueOf and returns a HashMap String, String array where each item will contain a hash map with key "evaluated expression" and value "SynapsePath type".- Parameters:
synCtx
- MessageContext- Returns:
-
prepareReplacementValue
protected String prepareReplacementValue(String mediaType, MessageContext synCtx, Map.Entry<String,ArgumentDetails> replacementEntry)
Preprocess and converty types of the given arg value.- Parameters:
mediaType
- Output media typesynCtx
- Message contextreplacementEntry
- Argument- Returns:
- Preprocessed value
-
inferReplacementType
protected String inferReplacementType(Map.Entry<String,ArgumentDetails> entry)
Helper function that takes a Map of String, ArgumentDetails where key contains the value of an evaluated SynapsePath expression and value contains the type of SynapsePath + deepcheck status in use.It returns the type of conversion required (XML | JSON | String) based on the actual returned value and the path type.
- Parameters:
entry
-- Returns:
-
isJson
protected boolean isJson(String value)
Helper function that returns true if value passed is of JSON type.- Parameters:
value
-- Returns:
-
isXML
protected boolean isXML(String value)
Helper function that returns true if value passed is of XML Type.- Parameters:
value
-- Returns:
-
convertStringToOM
protected org.apache.axiom.om.OMElement convertStringToOM(String value) throws XMLStreamException, org.apache.axiom.om.OMException
Converts String to OMElement- Parameters:
value
- String value to convert- Returns:
- parsed OMElement
- Throws:
XMLStreamException
org.apache.axiom.om.OMException
-
escapeSpecialChars
protected String escapeSpecialChars(String replaceString)
Helper method to replace required char values with escape characters.- Parameters:
replaceString
-- Returns:
- replacedString
-
escapeSpecialCharactersOfJson
protected String escapeSpecialCharactersOfJson(String jsonString)
Replace special characters of a JSON string.- Parameters:
jsonString
- JSON string.- Returns:
-
escapeSpecialCharactersOfXml
protected String escapeSpecialCharactersOfXml(String xmlString)
Replace special characters of a XML string.- Parameters:
xmlString
- XML string.- Returns:
-
escapeXMLSpecialChars
protected String escapeXMLSpecialChars(String replaceString)
Helper method to replace required char values with escape characters for XML.- Parameters:
replaceString
-- Returns:
- replacedString
-
isEscapeXmlChars
protected boolean isEscapeXmlChars()
-
setEscapeXmlChars
public void setEscapeXmlChars(boolean escapeXmlChars)
-
addPathArgument
public void addPathArgument(Argument arg)
-
getFormat
public String getFormat()
-
setFormat
public void setFormat(String format)
-
getMediaType
public String getMediaType()
-
setMediaType
public void setMediaType(String mediaType)
-
handleException
protected void handleException(String msg)
-
getTemplateStatus
public abstract boolean getTemplateStatus()
-
readInputFactoryProperties
public void readInputFactoryProperties()
Read XMLInputFactory properties from XMLInputFactory.properties file.
-
-