public static Transformer getTransformer() throws Exception { return getTransformer(null); } public static Transformer getTransformer(Source src) throws Exception {
public static Transformer getTransformer() throws Exception { return getTransformer(null); } public static Transformer getTransformer(Source src) throws Exception {
public void serialize(OutputStream out) throws Exception { final Transformer idTransform = XmlTransformUtility.getTransformer(); Source input = new DOMSource(doc); Result output = new StreamResult(out); idTransform.transform(input, output); } }
public void serialize(OutputStream out) throws Exception { final Transformer idTransform = XmlTransformUtility.getTransformer(); Source input = new DOMSource(doc); Result output = new StreamResult(out); idTransform.transform(input, output); } }
public static void prettyPrintWithTransformer(Document doc, OutputStream out) { try { final Transformer serializer = XmlTransformUtility.getTransformer(); //Setup indenting to "pretty print" serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer .setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); DOMSource xmlSource = new DOMSource(doc); StreamResult outputTarget = new StreamResult(out); serializer.transform(xmlSource, outputTarget); } catch (Exception e) { logger.error(e.getMessage()); throw new RuntimeException(e); } }
public static void prettyPrintWithTransformer(Document doc, OutputStream out) { try { final Transformer serializer = XmlTransformUtility.getTransformer(); //Setup indenting to "pretty print" serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer .setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); DOMSource xmlSource = new DOMSource(doc); StreamResult outputTarget = new StreamResult(out); serializer.transform(xmlSource, outputTarget); } catch (Exception e) { logger.error(e.getMessage()); throw new RuntimeException(e); } }
public String getXMLResult() throws Exception { Writer w = new StringWriter(); PrintWriter out = new PrintWriter(w); final Transformer transformer = XmlTransformUtility.getTransformer(); Properties transProps = new Properties(); transProps.put("method", "xml"); transProps.put("indent", "yes"); transformer.setOutputProperties(transProps); transformer .transform(new DOMSource(rootElement), new StreamResult(out)); out.close(); return w.toString(); }
public String getXMLResult() throws Exception { Writer w = new StringWriter(); PrintWriter out = new PrintWriter(w); final Transformer transformer = XmlTransformUtility.getTransformer(); Properties transProps = new Properties(); transProps.put("method", "xml"); transProps.put("indent", "yes"); transformer.setOutputProperties(transProps); transformer .transform(new DOMSource(rootElement), new StreamResult(out)); out.close(); return w.toString(); }
/** * Convert the given DOM to an UTF-8 XML String. * * @param dom the Document to convert. * @param withXmlDeclaration if true, an XML-declaration is prepended. * @return the dom as an XML String. * @throws TransformerException if the dom could not be converted. */ // TODO: Consider optimizing this with ThreadLocal Transformers public static String domToString(Node dom, boolean withXmlDeclaration) throws Exception { Transformer t = XmlTransformUtility.getTransformer(); t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); if (withXmlDeclaration) { t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); } else { t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); } t.setOutputProperty(OutputKeys.METHOD, "xml"); /* Transformer */ StringWriter sw = new StringWriter(); t.transform(new DOMSource(dom), new StreamResult(sw)); return sw.toString(); }
/** * Convert the given DOM to an UTF-8 XML String. * * @param dom the Document to convert. * @param withXmlDeclaration if true, an XML-declaration is prepended. * @return the dom as an XML String. * @throws TransformerException if the dom could not be converted. */ // TODO: Consider optimizing this with ThreadLocal Transformers public static String domToString(Node dom, boolean withXmlDeclaration) throws Exception { Transformer t = XmlTransformUtility.getTransformer(); t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); if (withXmlDeclaration) { t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); } else { t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); } t.setOutputProperty(OutputKeys.METHOD, "xml"); /* Transformer */ StringWriter sw = new StringWriter(); t.transform(new DOMSource(dom), new StreamResult(sw)); return sw.toString(); }
transformer = XmlTransformUtility.getTransformer(ss); // xformPath } else { transformer.reset();
transformer = XmlTransformUtility.getTransformer(ss); // xformPath } else { transformer.reset();
@Test public void testTransformer() throws Exception { Transformer t = XmlTransformUtility.getTransformer(); t.setOutputProperty(OutputKeys.INDENT, "yes"); t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); }
XmlTransformUtility.getTransformer(preprocessorSource); ptransformer.setParameter("phase", phase); ptransformer.transform(rulesSource, new StreamResult(out));
XmlTransformUtility.getTransformer(preprocessorSource); ptransformer.setParameter("phase", phase); ptransformer.transform(rulesSource, new StreamResult(out));
/** * Default constructor. * * @throws PEPException */ public ListDatastreams() throws PEPException { super(); try { xFormer = XmlTransformUtility.getTransformer(); } catch (Exception e) { throw new PEPException("Error initialising SearchFilter", e); } tidy = new Tidy(); tidy.setShowWarnings(false); tidy.setQuiet(true); }
/** * Default constructor. * * @throws PEPException */ public FindObjects() throws PEPException { super(); try { xFormer = XmlTransformUtility.getTransformer(); } catch (Exception e) { throw new PEPException("Error initialising SearchFilter", e); } tidy = new Tidy(); tidy.setShowWarnings(false); tidy.setQuiet(true); }