Search in sources :

Example 1 with XMLConsumerAdapter

use of org.apache.cocoon.pipeline.component.sax.XMLConsumerAdapter in project sling by apache.

the class SlingTransformer method setXMLConsumer.

@Override
protected void setXMLConsumer(XMLConsumer consumer) {
    TransformerHandler transformerHandler;
    try {
        transformerHandler = this.createTransformerHandler();
    } catch (Exception ex) {
        throw new RuntimeException("Could not initialize transformer handler.", ex);
    }
    final Map<String, Object> map = this.getLogicSheetParameters();
    if (map != null) {
        final Transformer transformer = transformerHandler.getTransformer();
        for (Entry<String, Object> entry : map.entrySet()) {
            transformer.setParameter(entry.getKey(), entry.getValue());
        }
    }
    final SAXResult result = new SAXResult();
    result.setHandler(consumer);
    // According to TrAX specs, all TransformerHandlers are LexicalHandlers
    result.setLexicalHandler(consumer);
    transformerHandler.setResult(result);
    super.setXMLConsumer(new XMLConsumerAdapter(transformerHandler, transformerHandler));
}
Also used : XMLConsumerAdapter(org.apache.cocoon.pipeline.component.sax.XMLConsumerAdapter) TransformerHandler(javax.xml.transform.sax.TransformerHandler) Transformer(javax.xml.transform.Transformer) AbstractTransformer(org.apache.cocoon.pipeline.component.sax.AbstractTransformer) SAXResult(javax.xml.transform.sax.SAXResult)

Aggregations

Transformer (javax.xml.transform.Transformer)1 SAXResult (javax.xml.transform.sax.SAXResult)1 TransformerHandler (javax.xml.transform.sax.TransformerHandler)1 AbstractTransformer (org.apache.cocoon.pipeline.component.sax.AbstractTransformer)1 XMLConsumerAdapter (org.apache.cocoon.pipeline.component.sax.XMLConsumerAdapter)1