/** * Returns a transformer handler that serializes incoming SAX events to * XHTML or HTML (depending the given method) using the given output encoding. * * @param encoding output encoding, or <code>null</code> for the platform default */ private static TransformerHandler getTransformerHandler(OutputStream out, String method, String encoding) throws TransformerConfigurationException { TransformerHandler transformerHandler = SAX_TRANSFORMER_FACTORY.newTransformerHandler(); Transformer transformer = transformerHandler.getTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, method); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); if (encoding != null) { transformer.setOutputProperty(OutputKeys.ENCODING, encoding); } transformerHandler.setResult(new StreamResult(new PrintStream(out))); return transformerHandler; }
Transformer trans = tHLast.getTransformer(); Properties outputProps = trans.getOutputProperties(); Serializer serializer = SerializerFactory.getSerializer(outputProps);
Templates tmpl = saxTFactory.newTemplates(new StreamSource(absURI)); TransformerHandler tHandler = saxTFactory.newTransformerHandler(tmpl); Transformer trans = tHandler.getTransformer();
private ContentHandler getXmlContentHandler(Writer writer) throws TransformerConfigurationException { SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler handler = factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml"); handler.setResult(new StreamResult(writer)); return handler; }
private static ContentHandler getXmlContentHandler(Writer writer) throws TransformerConfigurationException { SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler handler = factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml"); handler.setResult(new StreamResult(writer)); return handler; }
/** * Returns a transformer handler that serializes incoming SAX events * to XHTML or HTML (depending the given method) using the given output * encoding. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-277">TIKA-277</a> * @param output output stream * @param method "xml" or "html" * @param encoding output encoding, * or <code>null</code> for the platform default * @return {@link System#out} transformer handler * @throws TransformerConfigurationException * if the transformer can not be created */ private static TransformerHandler getTransformerHandler( OutputStream output, String method, String encoding, boolean prettyPrint) throws TransformerConfigurationException { SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler handler = factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, method); handler.getTransformer().setOutputProperty(OutputKeys.INDENT, prettyPrint ? "yes" : "no"); if (encoding != null) { handler.getTransformer().setOutputProperty( OutputKeys.ENCODING, encoding); } handler.setResult(new StreamResult(output)); return handler; }
/** * Create a processor that writes to the file named and may or may not * also output to the screen, as specified. * * @param out output stream to write * @throws IOException on any error */ public XmlEditsVisitor(OutputStream out) throws IOException { this.out = out; factory =(SAXTransformerFactory)SAXTransformerFactory.newInstance(); try { TransformerHandler handler = factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml"); handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8"); handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes"); handler.getTransformer().setOutputProperty(XML_INDENTATION_PROP, XML_INDENTATION_NUM); handler.getTransformer().setOutputProperty(OutputKeys.STANDALONE, "yes"); handler.setResult(new StreamResult(out)); contentHandler = handler; contentHandler.startDocument(); contentHandler.startElement("", "", "EDITS", new AttributesImpl()); } catch (TransformerConfigurationException e) { throw new IOException("SAXTransformer error: " + e.getMessage()); } catch (SAXException e) { throw new IOException("SAX error: " + e.getMessage()); } }
public void write(OutputStream outputStream) throws IOException, WebApplicationException { Writer writer = new OutputStreamWriter(outputStream, UTF_8); ContentHandler content; try { SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler handler = factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, format); handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes"); handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, UTF_8.name()); handler.setResult(new StreamResult(writer)); content = new ExpandedTitleContentHandler(handler); } catch (TransformerConfigurationException e) { throw new WebApplicationException(e); } parse(parser, LOG, info.getPath(), is, content, metadata, context); } };
SAXTransformerFactory.newInstance(); TransformerHandler handler = factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "html"); handler.setResult(new StreamResult(writer)); return new ContentHandlerDecorator(handler) {
SAXTransformerFactory.newInstance(); TransformerHandler handler = factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "html"); handler.setResult(new StreamResult(writer)); return new ContentHandlerDecorator(handler) {
throw new IOException(e); xmls.getTransformer().setOutputProperties(outputProps); xmls.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml"); xmls.setResult(new StreamResult(out));
throw new RuntimeException(e); xmls.getTransformer().setOutputProperty(OutputKeys.METHOD, "XML"); xmls.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true"); xmls.getTransformer().setOutputProperty(OutputKeys.INDENT, "true"); xmls.getTransformer().transform(new DOMSource(named.getElement()), new StreamResult(writer));
Transformer serializer = hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, CHARSET); serializer.setOutputProperty(OutputKeys.INDENT, "yes");
throw new RuntimeException(e); xmls.getTransformer().setOutputProperty(OutputKeys.METHOD, "XML"); xmls.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true"); xmls.getTransformer().setOutputProperty(OutputKeys.INDENT, "true"); xmls.getTransformer().transform(new DOMSource(named.getElement()), new StreamResult(writer));
throw new RuntimeException(e); xmls.getTransformer().setOutputProperty(OutputKeys.METHOD, "XML"); xmls.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true"); xmls.getTransformer().setOutputProperty(OutputKeys.INDENT, "true"); xmls.getTransformer().transform(new DOMSource(xsdType.getElement()), new StreamResult(writer));
throw new RuntimeException(e); xmls.getTransformer().setOutputProperty(OutputKeys.METHOD, "XML"); xmls.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true"); xmls.getTransformer().setOutputProperty(OutputKeys.INDENT, "true"); xmls.getTransformer().transform(new DOMSource(xsdType.getElement()), new StreamResult(writer));
xmls.getTransformer().setOutputProperties(outputProps); xmls.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml"); xmls.setResult(new StreamResult(out));
private TransformerHandler createTransformerHandler(FileOutputStream fileOuputStream) throws TransformerFactoryConfigurationError, TransformerConfigurationException, SAXException { SAXTransformerFactory transformerFact = (SAXTransformerFactory) SAXTransformerFactory .newInstance(); TransformerHandler saxHandler = transformerFact.newTransformerHandler(); saxHandler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8"); saxHandler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes"); saxHandler.setResult(new StreamResult(fileOuputStream)); return saxHandler; }
private static SAXWriter getSAXWriter(TransformerHandler th, Result result, SetupTransformer setup) { th.setResult(result); if (setup != null) setup.setup(th.getTransformer()); return new SAXWriter(th); }
private void writeAsXML(Attributes attrs, OutputStream out) throws Exception { TransformerHandler th = getTransformerHandler(); th.getTransformer().setOutputProperty(OutputKeys.INDENT, xmlIndent ? "yes" : "no"); th.setResult(new StreamResult(out)); SAXWriter saxWriter = new SAXWriter(th); saxWriter.setIncludeKeyword(xmlIncludeKeyword); saxWriter.setIncludeNamespaceDeclaration(xmlIncludeNamespaceDeclaration); saxWriter.write(attrs); }