Search in sources :

Example 26 with Templates

use of javax.xml.transform.Templates in project symja_android_library by axkr.

the class StylesheetManager method cacheImporterStylesheet.

private Templates cacheImporterStylesheet(final boolean requireXSLT20, final String... importUris) {
    Templates result;
    TransformerFactory transformerFactory = getTransformerFactory(requireXSLT20);
    if (stylesheetCache == null) {
        result = compileImporterStylesheet(transformerFactory, requireXSLT20, importUris);
    } else {
        String cacheKey = "snuggletex-importer(" + StringUtilities.join(importUris, ",") + ")";
        synchronized (stylesheetCache) {
            result = stylesheetCache.getStylesheet(cacheKey);
            if (result == null) {
                result = compileImporterStylesheet(transformerFactory, requireXSLT20, importUris);
                stylesheetCache.putStylesheet(cacheKey, result);
            }
        }
    }
    return result;
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) Templates(javax.xml.transform.Templates)

Example 27 with Templates

use of javax.xml.transform.Templates in project symja_android_library by axkr.

the class MathMLDownConverter method downConvertDOM.

public Document downConvertDOM(Document document) {
    /* If inlining CSS, create a document to hold the name/value pairs as described in
     * buildCSSPropertiesDocument(). Otherwise, we'll create an empty one to indicate
     * that nothing should be inlined */
    Document cssPropertiesDocument = XMLUtilities.createNSAwareDocumentBuilder().newDocument();
    if (cssProperties != null) {
        buildCSSPropertiesDocument(cssPropertiesDocument, cssProperties);
    }
    /* Create URI Resolver to let the XSLT get at this document */
    CSSPropertiesURIResolver uriResolver = new CSSPropertiesURIResolver(cssPropertiesDocument);
    /* Run the conversion XSLT */
    Templates templates = stylesheetManager.getStylesheet(Globals.MATHML_TO_XHTML_XSL_RESOURCE_NAME);
    Document result = XMLUtilities.createNSAwareDocumentBuilder().newDocument();
    try {
        Transformer transformer = templates.newTransformer();
        transformer.setURIResolver(uriResolver);
        transformer.transform(new DOMSource(document), new DOMResult(result));
    } catch (Exception e) {
        throw new SnuggleRuntimeException("Unexpected Exception down-converting DOM", e);
    }
    return result;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) SnuggleRuntimeException(uk.ac.ed.ph.snuggletex.SnuggleRuntimeException) Templates(javax.xml.transform.Templates) Document(org.w3c.dom.Document) SnuggleRuntimeException(uk.ac.ed.ph.snuggletex.SnuggleRuntimeException)

Example 28 with Templates

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

the class XSLTJaxbProvider method marshalToOutputStream.

@Override
protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, Annotation[] anns, MediaType mt) throws Exception {
    Templates t = createTemplates(getOutTemplates(anns, mt), outParamsMap, outProperties);
    if (t == null && supportJaxbOnly) {
        super.marshalToOutputStream(ms, obj, os, anns, mt);
        return;
    }
    org.apache.cxf.common.jaxb.JAXBUtils.setMinimumEscapeHandler(ms);
    TransformerHandler th;
    try {
        th = factory.newTransformerHandler(t);
    } catch (TransformerConfigurationException ex) {
        TemplatesImpl ti = (TemplatesImpl) t;
        th = factory.newTransformerHandler(ti.getTemplates());
        this.trySettingProperties(th, ti);
    }
    Result result = getStreamResult(os, anns, mt);
    if (systemId != null) {
        result.setSystemId(systemId);
    }
    th.setResult(result);
    if (getContext() == null) {
        th.startDocument();
    }
    ms.marshal(obj, th);
    if (getContext() == null) {
        th.endDocument();
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) Templates(javax.xml.transform.Templates) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) DOMResult(javax.xml.transform.dom.DOMResult)

Example 29 with Templates

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

the class XSLTJaxbProvider method getTemplatesFromAnnotation.

protected Templates getTemplatesFromAnnotation(Class<?> cls, Annotation[] anns, MediaType mt) {
    Templates t = null;
    XSLTTransform ann = getXsltTransformAnn(anns, mt);
    if (ann != null) {
        t = annotationTemplates.get(ann.value());
        if (t == null || refreshTemplates) {
            String path = ann.value();
            final String cp = "classpath:";
            if (!path.startsWith(cp)) {
                path = cp + path;
            }
            t = createTemplates(path);
            if (t == null) {
                createTemplates(ClassLoaderUtils.getResource(ann.value(), cls));
            }
            if (t != null) {
                annotationTemplates.put(ann.value(), t);
            }
        }
    }
    return t;
}
Also used : XSLTTransform(org.apache.cxf.jaxrs.ext.xml.XSLTTransform) Templates(javax.xml.transform.Templates)

Example 30 with Templates

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

the class XSLTJaxbProvider method getOutTemplates.

protected Templates getOutTemplates(Annotation[] anns, MediaType mt) {
    Templates t = createTemplatesFromContext();
    if (t != null) {
        return t;
    }
    t = outTemplates != null ? outTemplates : outMediaTemplates != null ? outMediaTemplates.get(mt.getType() + "/" + mt.getSubtype()) : null;
    if (t == null) {
        t = getAnnotationTemplates(anns);
    }
    return t;
}
Also used : 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