changeset 80:21a7efe056b4 3.0.7

Add toString to httpclients XMLUtils Useful for debugging in the GWT Client
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 31 May 2013 15:16:40 +0200
parents e4a595d53a52
children 0afb5f0195a6
files src/main/java/org/dive4elements/artifacts/httpclient/utils/XMLUtils.java
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/dive4elements/artifacts/httpclient/utils/XMLUtils.java	Tue May 28 16:01:41 2013 +0200
+++ b/src/main/java/org/dive4elements/artifacts/httpclient/utils/XMLUtils.java	Fri May 31 15:16:40 2013 +0200
@@ -11,6 +11,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.StringWriter;
 
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
@@ -316,5 +317,29 @@
         }
         return false;
     }
+
+    public static String toString(Document document) {
+        try {
+            Transformer transformer =
+                TransformerFactory.newInstance().newTransformer();
+            DOMSource    source = new DOMSource(document);
+            StringWriter out    = new StringWriter();
+            StreamResult result = new StreamResult(out);
+            transformer.transform(source, result);
+            out.flush();
+            return out.toString();
+        }
+        catch (TransformerConfigurationException tce) {
+            logger.error(tce.getLocalizedMessage(), tce);
+        }
+        catch (TransformerFactoryConfigurationError tfce) {
+            logger.error(tfce.getLocalizedMessage(), tfce);
+        }
+        catch (TransformerException te) {
+            logger.error(te.getLocalizedMessage(), te);
+        }
+
+        return null;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org