@Override public ValidationResult validate(final String subject, final String input, final ValidationContext validationContext) { final Tuple<String, ValidationResult> lastResult = this.cachedResult; if (lastResult != null && lastResult.getKey().equals(input)) { return lastResult.getValue(); } else { String error = null; final File stylesheet = new File(input); final TransformerFactory tFactory = new net.sf.saxon.TransformerFactoryImpl(); final StreamSource styleSource = new StreamSource(stylesheet); try { tFactory.newTransformer(styleSource); } catch (final Exception e) { error = e.toString(); } this.cachedResult = new Tuple<>(input, new ValidationResult.Builder() .input(input) .subject(subject) .valid(error == null) .explanation(error) .build()); return this.cachedResult.getValue(); } } }
public static void saxonTransform(String xsltDir, String source, String xslt, String dest, URIResolver alt, Map<String, String> params) throws FileNotFoundException, TransformerException { TransformerFactoryImpl f = new net.sf.saxon.TransformerFactoryImpl(); f.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE); StreamSource xsrc = new StreamSource(new FileInputStream(xslt)); f.setURIResolver(new MyURIResolver(xsltDir, alt)); Transformer t = f.newTransformer(xsrc); if (params != null) { for (Map.Entry<String, String> entry : params.entrySet()) { t.setParameter(entry.getKey(), entry.getValue()); } } t.setURIResolver(new MyURIResolver(xsltDir, alt)); StreamSource src = new StreamSource(new FileInputStream(source)); StreamResult res = new StreamResult(new FileOutputStream(dest)); t.transform(src, res); }
public static String saxonTransform(String source, String xslt) throws TransformerException, FileNotFoundException { TransformerFactoryImpl f = new net.sf.saxon.TransformerFactoryImpl(); f.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE); StreamSource xsrc = new StreamSource(new FileInputStream(xslt)); Transformer t = f.newTransformer(xsrc); StreamSource src = new StreamSource(new FileInputStream(source)); StreamResult res = new StreamResult(new ByteArrayOutputStream()); t.transform(src, res); return res.getOutputStream().toString(); }
TransformerFactoryImpl transformerFactoryImpl = new TransformerFactoryImpl(); Transformer transformer = transformerFactoryImpl.newTransformer(); transformer.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
/** * Compile a document containing a stylesheet module into a stylesheet that can be used to perform * transformations * * @param context the XPath dynamic evaluation context * @param doc the document containing the stylesheet to be compiled * @return the compiled stylesheet */ public static Templates compileStylesheet(XPathContext context, DocumentInfo doc) throws XPathException { if (doc == null) { return null; } try { TransformerFactoryImpl factory = new TransformerFactoryImpl(context.getConfiguration()); return factory.newTemplates(doc); } catch (TransformerConfigurationException e) { throw XPathException.makeXPathException(e); } }
source = standardURIResolver.resolve(href, baseURI); TransformerFactoryImpl factory = new TransformerFactoryImpl(); factory.setConfiguration(config); next = (PreparedStylesheet)factory.newTemplates(source); preparedStylesheet.putCachedStylesheet(href, baseURI, next);
TransformerFactoryImpl transformerFactory = new TransformerFactoryImpl(); Configuration config = transformerFactory.getConfiguration(); config.registerExtensionFunction(new DateExtensionFunction());
TransformerFactoryImpl factory = new TransformerFactoryImpl(); factory.getConfiguration().registerExtensionFunction(new DateExtensionFunction()); String xsl = "<e xsl:version='3.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " + "result='{Q{http://date.com}getFormattedNow()}'/>"; Templates t = factory.newTemplates(new StreamSource(new StringReader(xsl))); StringWriter sw = new StringWriter(); t.newTransformer().transform(new StreamSource(new StringReader("<a/>")), new StreamResult(sw));
System.err.println(factory.getConfiguration().getProductTitle()); factory.setAttribute( FeatureKeys.TIMING, Boolean.TRUE); if (args.length < i+2) badUsage("No style parser class"); String styleParserName = args[i++]; factory.setAttribute( FeatureKeys.STYLE_PARSER_CLASS, styleParserName); if (args.length < i+2) badUsage("No URIResolver class"); String r = args[i++]; factory.setURIResolver(factory.getConfiguration().makeURIResolver(r)); factory.setAttribute(FeatureKeys.XML_VERSION, "1.1"); if (useURLs || styleFileName.startsWith("http:") || styleFileName.startsWith("file:")) { styleSource = factory.getURIResolver().resolve(styleFileName, null); if (styleSource == null) { styleSource = factory.getConfiguration().getSystemURIResolver().resolve(styleFileName, null); styleSource = new SAXSource(factory.getConfiguration().getStyleParser(), eis); Templates sheet = factory.newTemplates(styleSource);
public static ByteArrayOutputStream transformXML( ByteArrayInputStream inputStream,String xslt) throws ParserConfigurationException, IOException, SAXException, TransformerException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Source xslSource = new StreamSource(inputStream); TransformerFactory transFact = TransformerFactory.newInstance(); ((TransformerFactoryImpl) transFact).getConfiguration().setMessageEmitterClass(Log4jEmitter.class.getName()); // Templates templates = transFact.newTemplates(xslSource); Transformer trans = StylesheetCache.newTransformer(xslt); Source xmlSource = new StreamSource(inputStream); trans.transform(xmlSource, new StreamResult(outputStream)); return outputStream; }
/** * Create an XMLFilter that uses the given Source as the * transformation instructions. * * @param src The Source of the transformation instructions. * * @return An XMLFilter object, or null if this feature is not supported. * * @throws TransformerConfigurationException If for some reason the * XMLFilter cannot be created. */ public XMLFilter newXMLFilter(Source src) throws TransformerConfigurationException { Templates tmpl = newTemplates(src); return newXMLFilter(tmpl); }
/** * Get a TransformerHandler object that can process SAX * ContentHandler events into a Result, based on the transformation * instructions specified by the argument. * * @param src The Source of the transformation instructions. * * @return TransformerHandler ready to transform SAX events. * * @throws TransformerConfigurationException If for some reason the * TransformerHandler can not be created. */ public TransformerHandler newTransformerHandler(Source src) throws TransformerConfigurationException { Templates tmpl = newTemplates(src); return newTransformerHandler(tmpl); }
Source style = factory.getAssociatedStylesheet(sourceInput, null, null, null); Templates sheet = factory.newTemplates(style); if (showTime) { System.err.println("Prepared associated stylesheet " + style.getSystemId());
/** * Process the Source into a Transformer object. Care must * be given not to use this object in multiple threads running concurrently. * Different TransformerFactories can be used concurrently by different * threads. * * @param source An object that holds a URI, input stream, etc. * * @return A Transformer object that may be used to perform a transformation * in a single thread, never null. * * @exception TransformerConfigurationException May throw this during the parse * when it is constructing the Templates object and fails. */ public Transformer newTransformer(Source source) throws TransformerConfigurationException { Templates templates = newTemplates(source); return templates.newTransformer(); }
private Transformer getTransformer(StreamSource streamSource) throws TransformerConfigurationException { return this.transformerFactory.newTransformer(streamSource); }
TransformerFactoryImpl transformerFactoryImpl = new TransformerFactoryImpl(); Transformer transformer = transformerFactoryImpl.newTransformer();
/** * Compile a document containing a stylesheet module into a stylesheet that can be used to perform * transformations * * @param context the XPath dynamic evaluation context * @param doc the document containing the stylesheet to be compiled * @return the compiled stylesheet */ public static Templates compileStylesheet(XPathContext context, DocumentInfo doc) throws XPathException { if (doc == null) { return null; } try { TransformerFactoryImpl factory = new TransformerFactoryImpl(context.getConfiguration()); return factory.newTemplates(doc); } catch (TransformerConfigurationException e) { throw XPathException.makeXPathException(e); } }
public static String saxonTransform(String source, String xslt) throws TransformerException, FileNotFoundException { TransformerFactoryImpl f = new net.sf.saxon.TransformerFactoryImpl(); f.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE); StreamSource xsrc = new StreamSource(new FileInputStream(xslt)); Transformer t = f.newTransformer(xsrc); StreamSource src = new StreamSource(new FileInputStream(source)); StreamResult res = new StreamResult(new ByteArrayOutputStream()); t.transform(src, res); return res.getOutputStream().toString(); }
source = standardURIResolver.resolve(href, baseURI); TransformerFactoryImpl factory = new TransformerFactoryImpl(); factory.setConfiguration(config); next = (PreparedStylesheet)factory.newTemplates(source); preparedStylesheet.putCachedStylesheet(href, baseURI, next);
System.err.println(factory.getConfiguration().getProductTitle()); factory.setAttribute( FeatureKeys.TIMING, Boolean.TRUE); if (args.length < i+2) badUsage("No style parser class"); String styleParserName = args[i++]; factory.setAttribute( FeatureKeys.STYLE_PARSER_CLASS, styleParserName); if (args.length < i+2) badUsage("No URIResolver class"); String r = args[i++]; factory.setURIResolver(factory.getConfiguration().makeURIResolver(r)); factory.setAttribute(FeatureKeys.XML_VERSION, "1.1"); if (useURLs || styleFileName.startsWith("http:") || styleFileName.startsWith("file:")) { styleSource = factory.getURIResolver().resolve(styleFileName, null); if (styleSource == null) { styleSource = factory.getConfiguration().getSystemURIResolver().resolve(styleFileName, null); styleSource = new SAXSource(factory.getConfiguration().getStyleParser(), eis); Templates sheet = factory.newTemplates(styleSource);