(no commit message)
[utils] / support / src / org / wamblee / xml / DomUtils.java
index 75ba7f6ddefeb1d4a20a35e9f30651d05608d5b7..05eae128640fa9b70a829a7e7c33814e379ca891 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.wamblee.xml;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -29,6 +30,8 @@ import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.xml.serialize.OutputFormat;
 import org.apache.xml.serialize.XMLSerializer;
 import org.dom4j.DocumentException;
@@ -48,6 +51,8 @@ import org.xml.sax.SAXException;
  */
 public final class DomUtils {
     
+    private static final Log LOG = LogFactory.getLog(DomUtils.class);
+    
     /**
      * Disabled default constructor. 
      *
@@ -56,6 +61,15 @@ public final class DomUtils {
         // Empty. 
     }
     
+    /**
+     * Parses an XML document from a string. 
+     * @param aDocument document. 
+     * @return 
+     */
+    public static Document read(String aDocument) throws SAXException, ParserConfigurationException, IOException {
+        ByteArrayInputStream is = new ByteArrayInputStream(aDocument.getBytes());
+        return read(is);          
+    }
     
     /**
      * Parses an XML document from a stream. 
@@ -139,7 +153,7 @@ public final class DomUtils {
         for (int i = 0; i < attributes.getLength(); i++) {
             Attr attribute = (Attr) attributes.item(i);
             if (uniqueAttributes.containsKey(attribute.getNodeName())) {
-                System.out.println("Detected duplicate attribute '"
+                LOG.info("Detected duplicate attribute (will be removed)'"
                         + attribute.getNodeName() + "'");
             }
             uniqueAttributes.put(attribute.getNodeName(), attribute);