List of usage examples for javax.xml.transform OutputKeys STANDALONE
String STANDALONE
To view the source code for javax.xml.transform OutputKeys STANDALONE.
Click Source Link
From source file:org.openestate.io.core.XmlUtils.java
/** * Write a {@link Document} to an {@link OutputStream}. * * @param doc/*from ww w . j a v a2s . c o m*/ * the document to write * * @param output * the output, where the document is written to * * @param prettyPrint * if pretty printing is enabled for the generated XML code * * @throws TransformerException * if XML transformation failed */ public static void write(Document doc, OutputStream output, boolean prettyPrint) throws TransformerException { XmlUtils.clean(doc); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, (prettyPrint) ? "yes" : "no"); if (prettyPrint) { transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); } transformer.transform(new DOMSource(doc), new StreamResult(output)); }
From source file:org.openestate.io.core.XmlUtils.java
/** * Write a {@link Document} to a {@link Writer}. * * @param doc/*ww w . j a va 2s .c om*/ * the document to write * * @param output * the output, where the document is written to * * @param prettyPrint * if pretty printing is enabled for the generated XML code * * @throws TransformerException * if XML transformation failed */ public static void write(Document doc, Writer output, boolean prettyPrint) throws TransformerException { XmlUtils.clean(doc); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, (prettyPrint) ? "yes" : "no"); if (prettyPrint) { transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); } transformer.transform(new DOMSource(doc), new StreamResult(output)); }
From source file:org.tizzit.util.xml.SAXHelper.java
/** * @param node the string to stream.// w w w . j av a 2 s .c o m * @param handler the content handler. * @since tizzit-common 15.10.2009 */ public static void string2sax(String node, ContentHandler handler) { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); t.setOutputProperty(OutputKeys.STANDALONE, "no"); t.setOutputProperty(OutputKeys.METHOD, "xml"); StreamSource source = new StreamSource(new StringReader(node)); SAXResult result = new SAXResult(new OmitXmlDeclarationContentHandler(handler)); t.transform(source, result); } catch (Exception exe) { log.error("unknown error occured", exe); } }
From source file:org.tizzit.util.xml.SAXHelper.java
/** * @param node the string to stream.//from www .j a va 2 s .c o m * @param handler the content handler. * @since tizzit-common 15.10.2009 */ public static void string2sax(String node, ContentHandler handler, String encoding) { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); t.setOutputProperty(OutputKeys.STANDALONE, "no"); t.setOutputProperty(OutputKeys.METHOD, "xml"); if (!"".equals(encoding) && encoding != null) { t.setOutputProperty(OutputKeys.ENCODING, encoding); } StreamSource source = new StreamSource(new StringReader(node)); SAXResult result = new SAXResult(new OmitXmlDeclarationContentHandler(handler)); t.transform(source, result); } catch (Exception exe) { log.error("unknown error occured", exe); } }
From source file:pl.otros.vfs.browser.auth.AuthStoreUtils.java
public void save(AuthStore authStore, OutputStream out) throws IOException { Collection<UserAuthenticationInfo> all = authStore.getAll(); for (UserAuthenticationInfo userAuthenticationInfo : all) { UserAuthenticationData userAuthenticationData = authStore .getUserAuthenticationData(userAuthenticationInfo); }//from w w w .j a v a 2 s . com DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = null; try { documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element root = document.createElement("root"); document.appendChild(root); for (UserAuthenticationInfo userAuthenticationInfo : all) { UserAuthenticationDataWrapper userAuthenticationData = authStore .getUserAuthenticationData(userAuthenticationInfo); Element entry = document.createElement(ENTRY); entry.setAttribute(PROTOCOL, userAuthenticationInfo.getProtocol()); entry.setAttribute(HOST, userAuthenticationInfo.getHost()); entry.setAttribute(USER, userAuthenticationInfo.getUser()); Map<UserAuthenticationData.Type, char[]> addedTypes = userAuthenticationData.getAddedTypes(); for (UserAuthenticationData.Type type : addedTypes.keySet()) { Element elementUserAuthenticationData = document.createElement(USER_AUTHENTICATION_DATA); char[] data = userAuthenticationData.getData(type); String value; // if (UserAuthenticationData.PASSWORD.equals(type)) { // if (password == null){ // password = passwordProvider.getPassword("Enter password for password store"); // } // if (password == null || password.length==0){ // throw new IOException("Password for password store not entered"); // } // value = saltAndEncrypt(data); // } else { // value = new String(data); // } value = new String(data); Element elementType = document.createElement(TYPE); elementType.setTextContent(type.toString()); Element elementData = document.createElement(DATA); elementData.setTextContent(value); elementUserAuthenticationData.appendChild(elementType); elementUserAuthenticationData.appendChild(elementData); entry.appendChild(elementUserAuthenticationData); } root.appendChild(entry); } TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(out); transformer.transform(source, result); } catch (Exception e) { throw new IOException(e); } }
From source file:telecom.sudparis.eu.paas.client.APIClient.java
private static String prettyFormat(String input, int indent) { try {//from w w w. j ava2s . c om Source xmlInput = new StreamSource(new StringReader(input)); StringWriter stringWriter = new StringWriter(); StreamResult xmlOutput = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number", indent); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.transform(xmlInput, xmlOutput); return xmlOutput.getWriter().toString(); } catch (Exception e) { throw new RuntimeException(e); } }