use of org.apache.cocoon.pipeline.SetupException in project syncope by apache.
the class XSLTTransformer method load.
private void load(final Source source, final String localCacheKey, final Map<String, Object> attributes) {
LOG.debug("{} local cache miss: {}", getClass().getSimpleName(), localCacheKey);
// XSLT has to be parsed
final SAXTransformerFactory transformerFactory;
if (attributes == null || attributes.isEmpty()) {
transformerFactory = TRAX_FACTORY;
} else {
transformerFactory = createNewSAXTransformerFactory();
attributes.forEach((key, values) -> {
transformerFactory.setAttribute(key, values);
});
}
try {
this.templates = transformerFactory.newTemplates(source);
} catch (TransformerConfigurationException e) {
throw new SetupException("Impossible to read XSLT from '" + source + "', see nested exception", e);
}
}
use of org.apache.cocoon.pipeline.SetupException 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);
}
Aggregations