/** * Creates a new identity transformer. */ static Transformer createTransformer(boolean disableSecureProcessing) { try { SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing); return tf.newTransformer(); } catch (TransformerConfigurationException e) { throw new Error(e); // impossible } }
Transformer serializer = stf.newTransformer(); serializer.setErrorListener(new DefaultErrorHandler(false));
public static ContentHandler newHandler(OutputStream out, String encoding, boolean indent) throws TransformerConfigurationException { SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler hd = tf.newTransformerHandler(); Transformer serializer = tf.newTransformer(); StreamResult stream = new StreamResult(out); serializer.setOutputProperty(OutputKeys.ENCODING, encoding); serializer.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no"); hd.setResult(stream); return hd; }
/** * Create a Transformer object that from the input stylesheet * Uses the org.apache.xalan.processor.TransformerFactory. * @param source the stylesheet. * @return A Transformer object. */ public Transformer newTransformer(Source source) throws TransformerConfigurationException { if (_xalanFactory == null) { createXalanTransformerFactory(); } if (_errorlistener != null) { _xalanFactory.setErrorListener(_errorlistener); } if (_uriresolver != null) { _xalanFactory.setURIResolver(_uriresolver); } _currFactory = _xalanFactory; return _currFactory.newTransformer(source); }
/** * Create a Transformer object that copies the input document to the * result. Uses the org.apache.xalan.processor.TransformerFactory. * @return A Transformer object. */ public Transformer newTransformer() throws TransformerConfigurationException { if (_xalanFactory == null) { createXalanTransformerFactory(); } if (_errorlistener != null) { _xalanFactory.setErrorListener(_errorlistener); } if (_uriresolver != null) { _xalanFactory.setURIResolver(_uriresolver); } _currFactory = _xalanFactory; return _currFactory.newTransformer(); }
/** * Creates a new identity transformer. */ static Transformer createTransformer(boolean disableSecureProcessing) { try { SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing); return tf.newTransformer(); } catch (TransformerConfigurationException e) { throw new Error(e); // impossible } }
/** * Parse a file and send the sax events to the content handler. * @param file * @param handler * @throws TransformerException */ public static final void parse(final InputStream file, final ContentHandler handler) throws TransformerException { final Transformer transformer = FACTORY.newTransformer(); transformer.transform( new StreamSource( file ), new SAXResult( handler ) ); }
public void transform() throws TransformerException { if (source == null) { return; } if (result == null) { return; } if (transformerFactory == null) { transformerFactory = (SAXTransformerFactory) TransformerFactory.newInstance(); } Transformer transformer = transformerFactory.newTransformer(); transformer.transform(source, result); }
/** * Creates a new identity transformer. */ static Transformer createTransformer(boolean disableSecureProcessing) { try { SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing); return tf.newTransformer(); } catch (TransformerConfigurationException e) { throw new Error(e); // impossible } }
/** * Creates a new identity transformer. */ static Transformer createTransformer(boolean disableSecureProcessing) { try { SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing); return tf.newTransformer(); } catch (TransformerConfigurationException e) { throw new Error(e); // impossible } }
/** * Create a new Transformer from an XSLT. * @param source the source of the XSLT. * @return a new Transformer * @throws TransformerConfigurationException if there was a problem creating the Transformer from the XSLT */ public static Transformer newTransformer(Source source) throws TransformerConfigurationException { Transformer transformer = TRANSFORMER_FACTORY.newTransformer(source); // Although newTansformer() is not allowed to return null, Xalan does. // Trap that here by throwing the expected TransformerConfigurationException. if (transformer == null) { throw new TransformerConfigurationException("newTransformer returned null. XSLT may be invalid."); } return transformer; }
private void init(final AbstractPipelineInput input) { try { final File styleFile = new File(input.getAttribute(ANT_INVOKER_EXT_PARAM_STYLE)); templates = transformerFactory.newTemplates(new StreamSource(styleFile)); serializer = transformerFactory.newTransformer(); } catch (TransformerConfigurationException e) { throw new RuntimeException(e); } if (fileInfoFilter == null) { fileInfoFilter = fileInfo -> fileInfo.format != null && fileInfo.format.equals(ATTR_FORMAT_VALUE_DITAMAP); } }
/** * Creates a resource bundle from an InputStream. * @param in the stream to read from * @throws IOException if an I/O error occurs */ public XMLResourceBundle(InputStream in) throws IOException { try { Transformer transformer = tFactory.newTransformer(); StreamSource src = new StreamSource(in); SAXResult res = new SAXResult(new CatalogueHandler()); transformer.transform(src, res); } catch (TransformerException e) { throw new IOException("Error while parsing XML resource bundle: " + e.getMessage()); } }
private static Transformer createTransformer(String encoding) { try { SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, encoding); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}" + "indent-amount", "2"); return transformer; } catch (TransformerConfigurationException e) { throw new ConfigurationError("Error creating Transformer", e); } catch (TransformerFactoryConfigurationError e) { throw new ConfigurationError("Error creating Transformer", e); } }
public void embedXml(Element element) throws TransformerException, SAXException { Transformer transformer = LocalTransformerFactory.get().newTransformer(); transformer.transform(new DOMSource(element), new SAXResult(new StripDocumentHandler(result))); newLine(); }
/** * Parses an intermediate file (area tree XML) into an AreaTreeModel instance by adding * pages to it. * @param src the Source instance pointing to the intermediate file * @param treeModel the AreaTreeModel that the parsed pages are added to * @param userAgent the user agent * @throws TransformerException if an error occurs while parsing the area tree XML */ public void parse(Source src, AreaTreeModel treeModel, FOUserAgent userAgent) throws TransformerException { Transformer transformer = tFactory.newTransformer(); transformer.setErrorListener(new DefaultErrorListener(log)); SAXResult res = new SAXResult(getContentHandler(treeModel, userAgent)); transformer.transform(src, res); }
/** * Create a new Transformer from an XSLT. * @param source the source of the XSLT. * @param uriResolver * @return a new Transformer * @throws TransformerConfigurationException if there was a problem creating the Transformer from the XSLT */ public static Transformer newTransformer(Source source, JstlUriResolver uriResolver) throws TransformerConfigurationException { TRANSFORMER_FACTORY.setURIResolver(uriResolver); Transformer transformer = TRANSFORMER_FACTORY.newTransformer(source); // Although newTansformer() is not allowed to return null, Xalan does. // Trap that here by throwing the expected TransformerConfigurationException. if (transformer == null) { throw new TransformerConfigurationException("newTransformer returned null. XSLT may be invalid."); } return transformer; }
/** * Parses an event model file into an EventModel instance. * @param src the Source instance pointing to the XML file * @return the created event model structure * @throws TransformerException if an error occurs while parsing the XML file */ public static EventModel parse(Source src) throws TransformerException { Transformer transformer = tFactory.newTransformer(); transformer.setErrorListener(new DefaultErrorListener(LOG)); EventModel model = new EventModel(); SAXResult res = new SAXResult(getContentHandler(model)); transformer.transform(src, res); return model; }
/** * Create a Transformer object that copies the input document to the * result. Uses the com.sun.org.apache.xalan.internal.processor.TransformerFactory. * @return A Transformer object. */ public Transformer newTransformer() throws TransformerConfigurationException { if (_xalanFactory == null) { createXalanTransformerFactory(); } if (_errorlistener != null) { _xalanFactory.setErrorListener(_errorlistener); } if (_uriresolver != null) { _xalanFactory.setURIResolver(_uriresolver); } _currFactory = _xalanFactory; return _currFactory.newTransformer(); }
/** * Create a Transformer object that copies the input document to the * result. Uses the org.apache.xalan.processor.TransformerFactory. * @return A Transformer object. */ public Transformer newTransformer() throws TransformerConfigurationException { if (_xalanFactory == null) { createXalanTransformerFactory(); } if (_errorlistener != null) { _xalanFactory.setErrorListener(_errorlistener); } if (_uriresolver != null) { _xalanFactory.setURIResolver(_uriresolver); } _currFactory = _xalanFactory; return _currFactory.newTransformer(); }