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;
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations