public static Templates getTransformerTemplate( javax.xml.transform.Source xsltSource) throws TransformerConfigurationException { return transformerFactory.newTemplates(xsltSource); }
SAXTransformerFactory stf = (SAXTransformerFactory)TransformerFactory.newInstance(); // These templates objects could be reused and obtained from elsewhere. Templates templates1 = stf.newTemplates(new StreamSource( getClass().getResourceAsStream("MyStylesheet1.xslt"))); Templates templates2 = stf.newTemplates(new StreamSource( getClass().getResourceAsStream("MyStylesheet1.xslt"))); TransformerHandler th1 = stf.newTransformerHandler(templates1); TransformerHandler th2 = stf.newTransformerHandler(templates2); th1.setResult(new SAXResult(th2)); th2.setResult(new StreamResult(System.out)); Transformer t = stf.newTransformer(); t.transform(new StreamSource(System.in), new SAXResult(th1)); // th1 feeds th2, which in turn feeds System.out.
public void startup() throws Exception { setWarnClient(true); // !! where should that be decided? if (stylesheet == null) { TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource stylesheetStream = new StreamSource(this.getClass().getResourceAsStream("sable-to-mary.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (dbFactory == null) { dbFactory = DocumentBuilderFactory.newInstance(); } if (docBuilder == null) { docBuilder = dbFactory.newDocumentBuilder(); } super.startup(); }
public void startup() throws Exception { setWarnClient(true); // !! where should that be decided? if (stylesheet == null) { TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource stylesheetStream = new StreamSource(this.getClass().getResourceAsStream("ssml-to-mary.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (dbFactory == null) { dbFactory = DocumentBuilderFactory.newInstance(); } if (docBuilder == null) { docBuilder = dbFactory.newDocumentBuilder(); } super.startup(); }
public void startup() throws Exception { setWarnClient(true); // !! where should that be decided? if (stylesheet == null) { TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource stylesheetStream = new StreamSource(this.getClass().getResourceAsStream("sable-to-mary.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (dbFactory == null) { dbFactory = DocumentBuilderFactory.newInstance(); } if (docBuilder == null) { docBuilder = dbFactory.newDocumentBuilder(); } super.startup(); }
public void startup() throws Exception { setWarnClient(true); // !! where should that be decided? if (stylesheet == null) { TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource stylesheetStream = new StreamSource(this.getClass().getResourceAsStream("emotionml-to-maryxml.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (dbFactory == null) { dbFactory = DocumentBuilderFactory.newInstance(); } if (docBuilder == null) { docBuilder = dbFactory.newDocumentBuilder(); } super.startup(); }
public void startup() throws Exception { setWarnClient(true); // !! where should that be decided? if (stylesheet == null) { TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource stylesheetStream = new StreamSource(this.getClass().getResourceAsStream("emotionml-to-maryxml.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (dbFactory == null) { dbFactory = DocumentBuilderFactory.newInstance(); } if (docBuilder == null) { docBuilder = dbFactory.newDocumentBuilder(); } super.startup(); }
public void startup() throws Exception { setWarnClient(true); // !! where should that be decided? if (stylesheet == null) { TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource stylesheetStream = new StreamSource(this.getClass().getResourceAsStream("ssml-to-mary.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (dbFactory == null) { dbFactory = DocumentBuilderFactory.newInstance(); } if (docBuilder == null) { docBuilder = dbFactory.newDocumentBuilder(); } super.startup(); }
/** * Start up the static parts, and compile the normalise-maryxml XSLT stylesheet which can then be used by multiple threads. * * @exception TransformerFactoryConfigurationError * if the TransformerFactory cannot be instanciated. * @exception FileNotFoundException * if the stylesheet file cannot be found. * @exception TransformerConfigurationException * if the templates stylesheet cannot be generated. */ private static void startup() throws TransformerFactoryConfigurationError, TransformerConfigurationException { // only start the stuff if it hasn't been started yet. if (tFactory == null) { tFactory = TransformerFactory.newInstance(); } if (stylesheet == null) { StreamSource stylesheetStream = new StreamSource( MaryNormalisedWriter.class.getResourceAsStream("normalise-maryxml.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (logger == null) logger = MaryUtils.getLogger("MaryNormalisedWriter"); }
/** * Start up the static parts, and compile the normalise-maryxml XSLT stylesheet which can then be used by multiple threads. * * @exception TransformerFactoryConfigurationError * if the TransformerFactory cannot be instanciated. * @exception FileNotFoundException * if the stylesheet file cannot be found. * @exception TransformerConfigurationException * if the templates stylesheet cannot be generated. */ private static void startup() throws TransformerFactoryConfigurationError, TransformerConfigurationException { // only start the stuff if it hasn't been started yet. if (tFactory == null) { tFactory = TransformerFactory.newInstance(); } if (stylesheet == null) { StreamSource stylesheetStream = new StreamSource( MaryNormalisedWriter.class.getResourceAsStream("normalise-maryxml.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (logger == null) logger = MaryUtils.getLogger("MaryNormalisedWriter"); }
public void startup() throws Exception { setWarnClient(true); // !! where should that be decided? if (stylesheet == null) { TransformerFactory tFactory = TransformerFactory.newInstance(); tFactory.setURIResolver(new URIResolver() { public Source resolve(String href, String base) { if (href.endsWith("emotion-to-mary.xsl")) { return new StreamSource(this.getClass().getResourceAsStream("emotion-to-mary.xsl")); } else { return null; } } }); StreamSource stylesheetStream = new StreamSource(this.getClass().getResourceAsStream("apml-to-mary.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (dbFactory == null) { dbFactory = DocumentBuilderFactory.newInstance(); } if (docBuilder == null) { docBuilder = dbFactory.newDocumentBuilder(); } super.startup(); }
public void startup() throws Exception { setWarnClient(true); // !! where should that be decided? if (stylesheet == null) { TransformerFactory tFactory = TransformerFactory.newInstance(); tFactory.setURIResolver(new URIResolver() { public Source resolve(String href, String base) { if (href.endsWith("emotion-to-mary.xsl")) { return new StreamSource(this.getClass().getResourceAsStream("emotion-to-mary.xsl")); } else { return null; } } }); StreamSource stylesheetStream = new StreamSource(this.getClass().getResourceAsStream("apml-to-mary.xsl")); stylesheet = tFactory.newTemplates(stylesheetStream); } if (dbFactory == null) { dbFactory = DocumentBuilderFactory.newInstance(); } if (docBuilder == null) { docBuilder = dbFactory.newDocumentBuilder(); } super.startup(); }
Templates templates = m_tfactory.newTemplates(new StreamSource(xslbuf)); Transformer transformer = templates.newTransformer(); transformer.transform(new StreamSource(xmlbuf), new StreamResult(pw));
private Templates newTemplates(final ProcessContext context, final String path) throws TransformerConfigurationException, LookupFailureException { final Boolean secureProcessing = context.getProperty(SECURE_PROCESSING).asBoolean(); TransformerFactory factory = TransformerFactory.newInstance(); final boolean isFilename = context.getProperty(XSLT_FILE_NAME).isSet(); if (secureProcessing) { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); // don't be overly DTD-unfriendly forcing http://apache.org/xml/features/disallow-doctype-decl factory.setFeature("http://saxon.sf.net/feature/parserFeature?uri=http://xml.org/sax/features/external-parameter-entities", false); factory.setFeature("http://saxon.sf.net/feature/parserFeature?uri=http://xml.org/sax/features/external-general-entities", false); } if(isFilename) { return factory.newTemplates(new StreamSource(path)); } else { final String coordinateKey = lookupService.get().getRequiredKeys().iterator().next(); final Optional<String> attributeValue = lookupService.get().lookup(Collections.singletonMap(coordinateKey, path)); if (attributeValue.isPresent() && StringUtils.isNotBlank(attributeValue.get())) { return factory.newTemplates(new StreamSource(new ByteArrayInputStream(attributeValue.get().getBytes(StandardCharsets.UTF_8)))); } else { throw new TransformerConfigurationException("No XSLT definition is associated to " + path + " in the lookup controller service."); } } }
/** * Load the {@link Templates} instance for the stylesheet at the configured location. */ private Templates loadTemplates() throws ApplicationContextException { Source stylesheetSource = getStylesheetSource(); try { Templates templates = getTransformerFactory().newTemplates(stylesheetSource); return templates; } catch (TransformerConfigurationException ex) { throw new ApplicationContextException("Can't load stylesheet from '" + getUrl() + "'", ex); } finally { closeSourceIfNecessary(stylesheetSource); } }
/** * Read in templates from the stylesheet */ private void readTemplates() throws IOException, TransformerConfigurationException, ParserConfigurationException, SAXException { // Use a stream so that you can close it yourself quickly // and avoid keeping the handle until the object is garbaged. // (always keep control), otherwise you won't be able to delete // the file quickly on windows. try (InputStream xslStream = new BufferedInputStream(stylesheet.getInputStream())) { templatesModTime = stylesheet.getLastModified(); final Source src = getSource(xslStream, stylesheet); templates = getFactory().newTemplates(src); } }
/** * Load the {@link Templates} instance for the stylesheet at the configured location. */ private Templates loadTemplates() throws ApplicationContextException { Source stylesheetSource = getStylesheetSource(); try { Templates templates = getTransformerFactory().newTemplates(stylesheetSource); return templates; } catch (TransformerConfigurationException ex) { throw new ApplicationContextException("Can't load stylesheet from '" + getUrl() + "'", ex); } finally { closeSourceIfNecessary(stylesheetSource); } }
Node xslDOM = docBuilder.parse(new InputSource(xslFileName)); stylesheet = tfactory.newTemplates(new DOMSource(xslDOM, xslFileName)); stylesheet = tfactory.newTemplates(new StreamSource(xslFileName)); stylesheet = tfactory.newTemplates(source); else
try { Templates template = factory.newTemplates( new StreamSource( xslInputStream ) );
private Templates getXslTemplates() throws Exception { TransformerFactory transformerFactory = TransformerFactory.newInstance(); String xsl = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + " <xsl:template match=\"order\">" + " <bob>test</bob>" + " </xsl:template>" + "</xsl:stylesheet>"; return transformerFactory.newTemplates(new StringSource(xsl)); }