ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r357908 - /ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java
Date Tue, 20 Dec 2005 04:50:18 GMT
Author: bodewig
Date: Mon Dec 19 20:50:14 2005
New Revision: 357908

URL: http://svn.apache.org/viewcvs?rev=357908&view=rev
Log:
better deal with elements that don't have a namespace URI

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java?rev=357908&r1=357907&r2=357908&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java Mon Dec 19 20:50:14
2005
@@ -33,6 +33,7 @@
 
 /**
  * Writes a DOM tree to a given Writer.
+ * warning: this utility currently does not declare XML Namespaces.
  * <p>Utility class used by {@link org.apache.tools.ant.XmlLogger
  * XmlLogger} and
  * org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter
@@ -278,7 +279,8 @@
         // Write element
         out.write("<");
         if (namespacePolicy.qualifyElements) {
-            String prefix = (String) nsPrefixMap.get(element.getNamespaceURI());
+            String uri = getNamespaceURI(element);
+            String prefix = (String) nsPrefixMap.get(uri);
             if (prefix == null) {
                 if (nsPrefixMap.isEmpty()) {
                     // steal default namespace
@@ -286,8 +288,8 @@
                 } else {
                     prefix = NS + (nextPrefix++);
                 }
-                nsPrefixMap.put(element.getNamespaceURI(), prefix);
-                addNSDefinition(element, element.getNamespaceURI());
+                nsPrefixMap.put(uri, prefix);
+                addNSDefinition(element, uri);
             }
             if (!"".equals(prefix)) {
                 out.write(prefix);
@@ -302,12 +304,12 @@
             Attr attr = (Attr) attrs.item(i);
             out.write(" ");
             if (namespacePolicy.qualifyAttributes) {
-                String prefix =
-                    (String) nsPrefixMap.get(attr.getNamespaceURI());
+                String uri = getNamespaceURI(attr);
+                String prefix = (String) nsPrefixMap.get(uri);
                 if (prefix == null) {
                     prefix = NS + (nextPrefix++);
-                    nsPrefixMap.put(attr.getNamespaceURI(), prefix);
-                    addNSDefinition(element, attr.getNamespaceURI());
+                    nsPrefixMap.put(uri, prefix);
+                    addNSDefinition(element, uri);
                 }
                 out.write(prefix);
                 out.write(":");
@@ -370,10 +372,9 @@
 
         // Write element close
         out.write("</");
-        if (namespacePolicy.qualifyElements
-            || namespacePolicy.qualifyAttributes) {
-            String prefix =
-                (String) nsPrefixMap.get(element.getNamespaceURI());
+        if (namespacePolicy.qualifyElements) {
+            String uri = getNamespaceURI(element);
+            String prefix = (String) nsPrefixMap.get(uri);
             if (prefix != null && !"".equals(prefix)) {
                 out.write(prefix);
                 out.write(":");
@@ -547,5 +548,14 @@
             nsURIByElement.put(element, al);
         }
         al.add(uri);
+    }
+
+    private static String getNamespaceURI(Node n) {
+        String uri = n.getNamespaceURI();
+        if (uri == null) {
+            // FIXME: Is "No Namespace is Empty Namespace" really OK?
+            uri = "";
+        }
+        return uri;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message