Class TemplateProcessor

    • Constructor Detail

      • TemplateProcessor

        public TemplateProcessor()
    • 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 string
        mediaType - Output media type
        synCtx - 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 type
        synCtx - Message context
        replacementEntry - 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)
      • getPathArgumentList

        public List<Argument> getPathArgumentList()
      • 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)