diff options
author | peter.danner <peter.danner@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2007-08-01 12:34:54 +0000 |
---|---|---|
committer | peter.danner <peter.danner@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2007-08-01 12:34:54 +0000 |
commit | 98bf749a15a9de6f63fc6324b9bba81dabafce95 (patch) | |
tree | 5195296984640ad82930688d856355879a9f5c52 /common/src/at | |
parent | dcc799b7a090d1a4e3a4f0ee1779bd86eedf7441 (diff) | |
download | moa-id-spss-98bf749a15a9de6f63fc6324b9bba81dabafce95.tar.gz moa-id-spss-98bf749a15a9de6f63fc6324b9bba81dabafce95.tar.bz2 moa-id-spss-98bf749a15a9de6f63fc6324b9bba81dabafce95.zip |
Enhanced serializeNode to set the line-break charakter(s) to use with future Xerces versions
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@875 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'common/src/at')
-rw-r--r-- | common/src/at/gv/egovernment/moa/util/DOMUtils.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/common/src/at/gv/egovernment/moa/util/DOMUtils.java b/common/src/at/gv/egovernment/moa/util/DOMUtils.java index ac22b4310..460658c5b 100644 --- a/common/src/at/gv/egovernment/moa/util/DOMUtils.java +++ b/common/src/at/gv/egovernment/moa/util/DOMUtils.java @@ -466,6 +466,25 @@ public class DOMUtils { } /** + * Serialize the given DOM node. + * + * The node will be serialized using the UTF-8 encoding. + * + * @param node The node to serialize. + * @param omitXmlDeclaration The boolean value for omitting the XML Declaration. + * @param lineSeperator Sets the line seperator String of the parser + * @return String The <code>String</code> representation of the given DOM + * node. + * @throws TransformerException An error occurred transforming the + * node to a <code>String</code>. + * @throws IOException An IO error occurred writing the node to a byte array. + */ + public static String serializeNode(Node node, boolean omitXmlDeclaration, String lineSeperator) + throws TransformerException, IOException { + return new String(serializeNode(node, "UTF-8", omitXmlDeclaration, lineSeperator), "UTF-8"); + } + + /** * Serialize the given DOM node to a byte array. * * @param node The node to serialize. @@ -495,6 +514,25 @@ public class DOMUtils { */ public static byte[] serializeNode(Node node, String xmlEncoding, boolean omitDeclaration) throws TransformerException, IOException { + return serializeNode(node, xmlEncoding, false, null); + } + + + /** + * Serialize the given DOM node to a byte array. + * + * @param node The node to serialize. + * @param xmlEncoding The XML encoding to use. + * @param omitDeclaration The boolean value for omitting the XML Declaration. + * @param lineSeperator Sets the line seperator String of the parser + * @return The serialized node, as a byte array. Using a compatible encoding + * this can easily be converted into a <code>String</code>. + * @throws TransformerException An error occurred transforming the node to a + * byte array. + * @throws IOException An IO error occurred writing the node to a byte array. + */ + public static byte[] serializeNode(Node node, String xmlEncoding, boolean omitDeclaration, String lineSeperator) + throws TransformerException, IOException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); @@ -504,6 +542,9 @@ public class DOMUtils { transformer.setOutputProperty(OutputKeys.ENCODING, xmlEncoding); String omit = omitDeclaration ? "yes" : "no"; transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omit); + if (null!=lineSeperator) { + transformer.setOutputProperty("{http://xml.apache.org/xalan}line-separator", lineSeperator);//does not work for xalan <= 2.5.1 + } transformer.transform(new DOMSource(node), new StreamResult(bos)); bos.flush(); |