Search in sources :

Example 1 with XsltUriResolver

use of org.apache.camel.builder.xml.XsltUriResolver in project camel by apache.

the class SaxonUriResolverTest method test.

@Test
public void test() throws Exception {
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    Source xsl = fromClasspath(XSL_PATH);
    xsl.setSystemId("classpath:/" + XSL_PATH);
    Source xml = fromString(XML_DATA);
    TransformerFactory factory = new TransformerFactoryImpl();
    Transformer transformer = factory.newTransformer(xsl);
    transformer.setURIResolver(new XsltUriResolver(context(), XSL_PATH));
    transformer.transform(xml, result);
    Assert.assertEquals(XML_RESP, writer.toString());
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) TransformerFactoryImpl(net.sf.saxon.TransformerFactoryImpl) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) XsltUriResolver(org.apache.camel.builder.xml.XsltUriResolver) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 2 with XsltUriResolver

use of org.apache.camel.builder.xml.XsltUriResolver in project camel by apache.

the class XsltAggregationStrategy method initialize.

protected void initialize(CamelContext context) throws Exception {
    // set the default property name if not set
    this.propertyName = ObjectHelper.isNotEmpty(propertyName) ? propertyName : DEFAULT_PROPERTY_NAME;
    // initialize the XsltBuilder
    this.xslt = context.getInjector().newInstance(XsltBuilder.class);
    if (transformerFactoryClass != null) {
        Class<?> factoryClass = context.getClassResolver().resolveMandatoryClass(transformerFactoryClass, XsltAggregationStrategy.class.getClassLoader());
        TransformerFactory factory = (TransformerFactory) context.getInjector().newInstance(factoryClass);
        xslt.getConverter().setTransformerFactory(factory);
    }
    if (uriResolver == null) {
        uriResolver = new XsltUriResolver(context, xslFile);
    }
    xslt.setUriResolver(uriResolver);
    xslt.setFailOnNullBody(true);
    xslt.transformerCacheSize(0);
    xslt.setAllowStAX(true);
    configureOutput(xslt, output.name());
    loadResource(xslFile);
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) XsltUriResolver(org.apache.camel.builder.xml.XsltUriResolver) XsltBuilder(org.apache.camel.builder.xml.XsltBuilder)

Aggregations

TransformerFactory (javax.xml.transform.TransformerFactory)2 XsltUriResolver (org.apache.camel.builder.xml.XsltUriResolver)2 StringWriter (java.io.StringWriter)1 Source (javax.xml.transform.Source)1 Transformer (javax.xml.transform.Transformer)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 TransformerFactoryImpl (net.sf.saxon.TransformerFactoryImpl)1 XsltBuilder (org.apache.camel.builder.xml.XsltBuilder)1 Test (org.junit.Test)1