Search in sources :

Example 1 with CustomJAXPURIResolver

use of org.apache.synapse.util.resolver.CustomJAXPURIResolver in project wso2-synapse by wso2.

the class XSLTMediator method createTemplate.

/**
 * Create a XSLT template object and assign it to the cachedTemplates variable
 * @param synCtx current message
 * @param synLog logger to use
 * @param generatedXsltKey evaluated xslt key(real key value) for dynamic or static key
 * @return cached template
 */
private Templates createTemplate(MessageContext synCtx, SynapseLog synLog, String generatedXsltKey) {
    // Assign created template
    Templates cachedTemplates = null;
    // Set an error listener (SYNAPSE-307).
    transFact.setErrorListener(new ErrorListenerImpl(synLog, STYLESHEET_PARSING_ACTIVITY));
    // Allow xsl:import and xsl:include resolution
    transFact.setURIResolver(new CustomJAXPURIResolver(resourceMap, synCtx.getConfiguration(), synCtx));
    try {
        cachedTemplates = transFact.newTemplates(SynapseConfigUtils.getStreamSource(synCtx.getEntry(generatedXsltKey)));
        if (cachedTemplates == null) {
            // if cached template creation failed
            handleException("Error compiling the XSLT with key : " + xsltKey, synCtx);
        } else {
            if (useCache) {
                // if cached template is created then put it in to cachedTemplatesMap
                cachedTemplatesMap.put(generatedXsltKey, cachedTemplates);
            }
        }
    } catch (Exception e) {
        handleException("Error creating XSLT transformer using : " + xsltKey, e, synCtx);
    }
    return cachedTemplates;
}
Also used : Templates(javax.xml.transform.Templates) CustomJAXPURIResolver(org.apache.synapse.util.resolver.CustomJAXPURIResolver) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) SynapseException(org.apache.synapse.SynapseException)

Aggregations

Templates (javax.xml.transform.Templates)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 SynapseException (org.apache.synapse.SynapseException)1 CustomJAXPURIResolver (org.apache.synapse.util.resolver.CustomJAXPURIResolver)1