Search in sources :

Example 41 with Templates

use of javax.xml.transform.Templates in project bnd by bndtools.

the class Transform method transform.

public static void transform(TransformerFactory transformerFactory, URL xslt, InputStream in, OutputStream out) throws Exception {
    if (xslt == null)
        throw new IllegalArgumentException("No source template specified");
    Templates templates = cache.get(xslt.toURI());
    if (templates == null) {
        try (InputStream xsltIn = xslt.openStream()) {
            templates = transformerFactory.newTemplates(new StreamSource(xsltIn));
            cache.put(xslt.toURI(), templates);
        }
    }
    Result xmlResult = new StreamResult(out);
    Source xmlSource = new StreamSource(in);
    Transformer t = templates.newTransformer();
    t.transform(xmlSource, xmlResult);
    out.flush();
}
Also used : Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Templates(javax.xml.transform.Templates) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Example 42 with Templates

use of javax.xml.transform.Templates in project mondrian by pentaho.

the class DomBuilder method debug.

public static void debug(Document doc) {
    try {
        TransformerFactory tf = TransformerFactory.newInstance();
        StringReader input = new StringReader(PRETTY_PRINTER);
        Templates templates = tf.newTemplates(new StreamSource(input));
        OutputStream result = new ByteArrayOutputStream();
        templates.newTransformer().transform(new DOMSource(doc), new StreamResult(result));
        LOGGER.debug(result.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) Templates(javax.xml.transform.Templates)

Example 43 with Templates

use of javax.xml.transform.Templates in project cxf by apache.

the class XSLTJaxbProvider method getInTemplates.

protected Templates getInTemplates(Annotation[] anns, MediaType mt) {
    Templates t = createTemplatesFromContext();
    if (t != null) {
        return t;
    }
    t = inTemplates != null ? inTemplates : inMediaTemplates != null ? inMediaTemplates.get(mt.getType() + "/" + mt.getSubtype()) : null;
    if (t == null) {
        t = getAnnotationTemplates(anns);
    }
    return t;
}
Also used : Templates(javax.xml.transform.Templates)

Example 44 with Templates

use of javax.xml.transform.Templates in project camel by apache.

the class SchematronProducerTest method setUP.

@BeforeClass
public static void setUP() {
    SchematronEndpoint endpoint = new SchematronEndpoint();
    TransformerFactory fac = new TransformerFactoryImpl();
    fac.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR, endpoint.getUriResolver()));
    Templates templates = TemplatesFactory.newInstance().getTemplates(ClassLoader.getSystemResourceAsStream("sch/schematron-1.sch"), fac);
    endpoint.setRules(templates);
    producer = new SchematronProducer(endpoint);
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) TransformerFactoryImpl(net.sf.saxon.TransformerFactoryImpl) Templates(javax.xml.transform.Templates) ClassPathURIResolver(org.apache.camel.component.schematron.processor.ClassPathURIResolver) BeforeClass(org.junit.BeforeClass)

Example 45 with Templates

use of javax.xml.transform.Templates in project camel by apache.

the class SchematronProcessorTest method getProcessor.

/**
     * Returns schematron processor
     *
     * @param schematron
     * @param clientResolver
     * @return
     */
private SchematronProcessor getProcessor(final String schematron, final URIResolver clientResolver) {
    TransformerFactory factory = new TransformerFactoryImpl();
    factory.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR, clientResolver));
    Templates rules = TemplatesFactory.newInstance().getTemplates(ClassLoader.getSystemResourceAsStream(schematron), factory);
    return SchematronProcessorFactory.newScehamtronEngine(rules);
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) TransformerFactoryImpl(net.sf.saxon.TransformerFactoryImpl) Templates(javax.xml.transform.Templates)

Aggregations

Templates (javax.xml.transform.Templates)60 TransformerFactory (javax.xml.transform.TransformerFactory)25 StreamSource (javax.xml.transform.stream.StreamSource)25 Transformer (javax.xml.transform.Transformer)20 Source (javax.xml.transform.Source)19 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)17 StreamResult (javax.xml.transform.stream.StreamResult)16 TransformerException (javax.xml.transform.TransformerException)10 InputStream (java.io.InputStream)8 IOException (java.io.IOException)7 OutputStream (java.io.OutputStream)7 DOMResult (javax.xml.transform.dom.DOMResult)7 DOMSource (javax.xml.transform.dom.DOMSource)7 File (java.io.File)5 Result (javax.xml.transform.Result)5 SAXSource (javax.xml.transform.sax.SAXSource)5 FileOutputStream (java.io.FileOutputStream)4 StringReader (java.io.StringReader)4 BufferedOutputStream (java.io.BufferedOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3