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;
}
use of javax.xml.transform.Templates in project wcomponents by BorderTech.
the class TransformXMLInterceptor method initTemplates.
/**
* Statically initialize the XSLT templates that are cached for all future transforms.
*
* @return the XSLT Templates.
*/
private static Templates initTemplates() {
try {
URL xsltURL = ThemeUtil.class.getResource(RESOURCE_NAME);
if (xsltURL != null) {
try (InputStream inStream = xsltURL.openStream()) {
Source xsltSource = new StreamSource(inStream, xsltURL.toExternalForm());
TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
Templates templates = factory.newTemplates(xsltSource);
LOG.debug("Generated XSLT templates for: " + RESOURCE_NAME);
return templates;
}
} else {
// Server-side XSLT enabled but theme resource not on classpath.
throw new IllegalStateException(RESOURCE_NAME + " not on classpath");
}
} catch (IOException | TransformerConfigurationException ex) {
throw new SystemException("Could not create transformer for " + RESOURCE_NAME, ex);
}
}
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();
}
}
use of javax.xml.transform.Templates in project mycore by MyCoRe-Org.
the class MCRXSLTransformer method getTransformHandlerList.
protected LinkedList<TransformerHandler> getTransformHandlerList(MCRParameterCollector parameterCollector) throws TransformerConfigurationException, SAXException, ParserConfigurationException {
checkTemplateUptodate();
LinkedList<TransformerHandler> xslSteps = new LinkedList<>();
// every transformhandler shares the same ErrorListener instance
MCRErrorListener errorListener = MCRErrorListener.getInstance();
for (Templates template : templates) {
TransformerHandler handler = tFactory.newTransformerHandler(template);
parameterCollector.setParametersTo(handler.getTransformer());
handler.getTransformer().setErrorListener(errorListener);
if (TRACE_LISTENER_ENABLED) {
TransformerImpl transformer = (TransformerImpl) handler.getTransformer();
TraceManager traceManager = transformer.getTraceManager();
try {
traceManager.addTraceListener(TRACE_LISTENER);
} catch (TooManyListenersException e) {
LOGGER.warn("Could not add MCRTraceListener.", e);
}
}
if (!xslSteps.isEmpty()) {
Result result = new SAXResult(handler);
xslSteps.getLast().setResult(result);
}
xslSteps.add(handler);
}
return xslSteps;
}
use of javax.xml.transform.Templates in project symja_android_library by axkr.
the class StylesheetManager method getStylesheet.
/**
* Obtains the XSLT stylesheet at the given ClassPathURI, using the {@link StylesheetCache} (if
* set) to cache stylesheets for efficiency.
*
* @param classPathUri location of the XSLT stylesheet in the ClassPath, following the URI scheme
* in {@link ClassPathURIResolver}.
* @param requireXSLT20 if false uses the JAXP default {@link TransformerFactory}, otherwise
* specifies that we require an XSLT 2.0-compliant transformer, of which the only currently
* supported implementation is SAXON 9.x.
* @return compiled XSLT stylesheet.
*/
public Templates getStylesheet(final String classPathUri, final boolean requireXSLT20) {
Templates result;
if (stylesheetCache == null) {
result = compileInternalStylesheet(classPathUri, requireXSLT20);
} else {
synchronized (stylesheetCache) {
result = stylesheetCache.getStylesheet(classPathUri);
if (result == null) {
result = compileInternalStylesheet(classPathUri, requireXSLT20);
stylesheetCache.putStylesheet(classPathUri, result);
}
}
}
return result;
}
Aggregations