Search in sources :

Example 1 with SAXConsumerAdapter

use of org.apache.cocoon.sax.util.SAXConsumerAdapter in project syncope by apache.

the class XSLTTransformer method setSAXConsumer.

/**
 * {@inheritDoc}
 */
@Override
protected void setSAXConsumer(final SAXConsumer consumer) {
    TransformerHandler transformerHandler;
    try {
        transformerHandler = TRAX_FACTORY.newTransformerHandler(this.templates);
    } catch (Exception e) {
        throw new SetupException("Could not initialize transformer handler.", e);
    }
    if (this.parameters != null) {
        final Transformer transformer = transformerHandler.getTransformer();
        this.parameters.forEach((name, values) -> {
            // is valid XSLT parameter name
            if (XSLT_PARAMETER_NAME_PATTERN.matcher(name).matches()) {
                transformer.setParameter(name, values);
            }
        });
    }
    final SAXResult result = new SAXResult();
    result.setHandler(consumer);
    // According to TrAX specs, all TransformerHandlers are LexicalHandlers
    result.setLexicalHandler(consumer);
    transformerHandler.setResult(result);
    final SAXConsumerAdapter saxConsumerAdapter = new SAXConsumerAdapter();
    saxConsumerAdapter.setContentHandler(transformerHandler);
    super.setSAXConsumer(saxConsumerAdapter);
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) SetupException(org.apache.cocoon.pipeline.SetupException) Transformer(javax.xml.transform.Transformer) AbstractSAXTransformer(org.apache.cocoon.sax.AbstractSAXTransformer) SAXResult(javax.xml.transform.sax.SAXResult) SAXConsumerAdapter(org.apache.cocoon.sax.util.SAXConsumerAdapter) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) SetupException(org.apache.cocoon.pipeline.SetupException)

Aggregations

Transformer (javax.xml.transform.Transformer)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 SAXResult (javax.xml.transform.sax.SAXResult)1 TransformerHandler (javax.xml.transform.sax.TransformerHandler)1 SetupException (org.apache.cocoon.pipeline.SetupException)1 AbstractSAXTransformer (org.apache.cocoon.sax.AbstractSAXTransformer)1 SAXConsumerAdapter (org.apache.cocoon.sax.util.SAXConsumerAdapter)1