List of usage examples for javax.xml.transform OutputKeys OMIT_XML_DECLARATION
String OMIT_XML_DECLARATION
To view the source code for javax.xml.transform OutputKeys OMIT_XML_DECLARATION.
Click Source Link
From source file:org.kuali.rice.krad.devtools.maintainablexml.MaintainableXMLConversionServiceImpl.java
private String transformSection(String xml) { String maintenanceAction = StringUtils.substringBetween(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">", "</" + MAINTENANCE_ACTION_ELEMENT_NAME + ">"); xml = StringUtils.substringBefore(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">"); try {/* w ww .ja va2 s .com*/ xml = upgradeBONotes(xml); if (classNameRuleMap == null) { setRuleMaps(); } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(new InputSource(new StringReader(xml))); removePersonObjects(document); for (Node childNode = document.getFirstChild(); childNode != null;) { Node nextChild = childNode.getNextSibling(); transformClassNode(document, childNode); childNode = nextChild; } TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer trans = transFactory.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); DOMSource source = new DOMSource(document); trans.transform(source, result); xml = writer.toString().replaceAll("(?m)^\\s+\\n", ""); } catch (Exception e) { e.printStackTrace(); } return xml + "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">" + maintenanceAction + "</" + MAINTENANCE_ACTION_ELEMENT_NAME + ">"; }
From source file:org.kuali.rice.krad.service.impl.MaintainableXMLConversionServiceImpl.java
@Override public String transformMaintainableXML(String xml) { String maintenanceAction = "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">" + StringUtils.substringAfter("<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">", xml); xml = StringUtils.substringBefore(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">"); if (StringUtils.isNotBlank(this.getConversionRuleFile())) { try {//w w w . j av a 2s . c om this.setRuleMaps(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(new InputSource(new StringReader(xml))); for (Node childNode = document.getFirstChild(); childNode != null;) { Node nextChild = childNode.getNextSibling(); transformClassNode(document, childNode); childNode = nextChild; } TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer trans = transFactory.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); DOMSource source = new DOMSource(document); trans.transform(source, result); xml = writer.toString().replaceAll("(?m)^\\s+\\n", ""); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } catch (XPathExpressionException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } } if (StringUtils.contains(xml, "edu.iu.uis.dp.bo.DataManager") || StringUtils.contains(xml, "edu.iu.uis.dp.bo.DataSteward")) { xml = StringUtils.replace(xml, "org.kuali.rice.kim.bo.impl.PersonImpl", "org.kuali.rice.kim.impl.identity.PersonImpl"); xml = xml.replaceAll("<autoIncrementSet.+", ""); xml = xml.replaceAll("<address.+", ""); } return xml + maintenanceAction; }
From source file:org.kuali.test.utils.Utils.java
public static String printElement(Element node) { String retval = ""; try {// w ww. ja v a 2 s. c o m TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, " "); transformer.transform(new DOMSource(node), new StreamResult(buffer)); retval = buffer.toString(); } catch (TransformerException ex) { retval = ex.toString(); } return retval; }
From source file:org.lareferencia.backend.indexer.IndexerImpl.java
private Transformer buildTransformer() throws IndexerException { Transformer trf;//from w w w .j a v a 2s. c om try { StreamSource stylesource = new StreamSource(stylesheet); trf = xformFactory.newTransformer(stylesource); trf = MedatadaDOMHelper.buildXSLTTransformer(stylesheet); trf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trf.setOutputProperty(OutputKeys.INDENT, "no"); trf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); } catch (TransformerConfigurationException e) { throw new IndexerException(e.getMessage(), e.getCause()); } return trf; }
From source file:org.meveo.service.billing.impl.InvoiceService.java
protected String getNodeXmlString(Node node) { try {/*from w w w. ja v a2 s .c om*/ TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(node), new StreamResult(buffer)); return buffer.toString(); } catch (Exception e) { log.error("Error converting xml node to its string representation. {}", e); throw new ConfigurationException(); } }
From source file:org.mule.ibeans.IBeansSupport.java
/** * Returns a formatted XML string representation of an XML Node or Document. This is useful for debugging or for * capturing data that can be used for Mock testing. * @param node the Xml to read// ww w . ja va2 s . c o m * @return a formated XML string */ public static String prettyPrintXml(Node node) { try { // Set up the output transformer TransformerFactory transfac = TransformerFactory.newInstance(); javax.xml.transform.Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); // Print the DOM node StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); DOMSource source = new DOMSource(node); trans.transform(source, result); return sw.toString(); } catch (TransformerException e) { e.printStackTrace(); return null; } }
From source file:org.ncbo.stanford.service.xml.impl.XMLSerializationServiceImpl.java
private String getNodeAsXML(Node node) throws TransformerException { TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(node); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); trans.transform(source, result);//from w w w .j a v a2 s .c o m return sw.toString(); }
From source file:org.niord.core.util.TextUtils.java
/** * Prints an XML document to the output stream * @param doc the document to print//w w w .j ava 2 s.c om * @param out the output stream */ public static void printDocument(org.w3c.dom.Document doc, OutputStream out) throws IOException, TransformerException { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8"))); }
From source file:org.ojbc.processor.FaultableSynchronousMessageProcessor.java
/** * TODO remove soap env string param if locations using it only really need the soap body *///w ww . j a va2s . com private FaultableSoapResponse getResponseFromExchangeOutHeaders(Exchange returnExchange) throws Exception { Map<String, Object> headerMap = returnExchange.getOut().getHeaders(); SoapMessage cxfMessage = (SoapMessage) headerMap.get("camelcxfmessage"); Node soapEnvelopeNode = cxfMessage.getContent(Node.class); TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); DOMSource source = new DOMSource(soapEnvelopeNode); trans.transform(source, result); String sSoapEnvelopeMessgae = sw.toString(); Exception exchangeException = returnExchange.getException(); Document soapBodyDoc = getSoapBodyDocFromSoapEnv(soapEnvelopeNode); FaultableSoapResponse rFaultableSoapResponse = null; if (exchangeException != null || StringUtils.isNotBlank(sSoapEnvelopeMessgae)) { rFaultableSoapResponse = new FaultableSoapResponse(exchangeException, sSoapEnvelopeMessgae, soapBodyDoc); } return rFaultableSoapResponse; }
From source file:org.ojbc.util.camel.helper.OJBUtils.java
public static String getStringFromDocument(Document doc) { try {//from w w w. ja v a 2s . co m DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(domSource, result); return writer.toString(); } catch (TransformerException ex) { ex.printStackTrace(); return null; } }