ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r688091 - in /ant/core/trunk: CONTRIBUTORS WHATSNEW contributors.xml docs/manual/CoreTasks/echoxml.html src/main/org/apache/tools/ant/taskdefs/EchoXML.java src/tests/antunit/taskdefs/echoxml-test.xml
Date Fri, 22 Aug 2008 15:18:17 GMT
Author: bodewig
Date: Fri Aug 22 08:18:17 2008
New Revision: 688091

URL: http://svn.apache.org/viewvc?rev=688091&view=rev
Log:
Add namespace support to echoxml.  Based on patch by Joey Richey.  PR 36804.

Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/WHATSNEW
    ant/core/trunk/contributors.xml
    ant/core/trunk/docs/manual/CoreTasks/echoxml.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
    ant/core/trunk/src/tests/antunit/taskdefs/echoxml-test.xml

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=688091&r1=688090&r2=688091&view=diff
==============================================================================
Binary files - no diff available.

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=688091&r1=688090&r2=688091&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Aug 22 08:18:17 2008
@@ -282,6 +282,9 @@
    an URL.
    Bugzilla Report 28881
 
+ * <echoxml> now supports XML namespaces.
+   Bugzilla Report 36804.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=688091&r1=688090&r2=688091&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Fri Aug 22 08:18:17 2008
@@ -581,6 +581,10 @@
     <last>Wassmer</last>
   </name>
   <name>
+    <first>Joey</first>
+    <last>Richey</last>
+  </name>
+  <name>
     <first>Jon</first>
     <last>Dickinson</last>
   </name>

Modified: ant/core/trunk/docs/manual/CoreTasks/echoxml.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/echoxml.html?rev=688091&r1=688090&r2=688091&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/echoxml.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/echoxml.html Fri Aug 22 08:18:17 2008
@@ -45,6 +45,14 @@
     <td valign="top">Whether to append <code>file</code>, if specified.</td>
     <td valign="top" align="center">No</td>
   </tr>
+  <tr>
+    <td valign="top">namespacePolicy</td>
+    <td valign="top">Sets the namespace policy as defined
+    by <code>org.apache.tools.ant.util.DOMElementWriter.XmlNamespacePolicy</code>.
Valid
+    values are "ignore," "elementsOnly," or "all." Default is
+    "ignore".</td>
+    <td valign="top" align="center">No</td>
+  </tr>
 </table>
 <h3>Parameters specified as nested elements</h3>
 Nested XML content is required.

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java?rev=688091&r1=688090&r2=688091&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java Fri Aug 22 08:18:17
2008
@@ -23,6 +23,7 @@
 
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.util.XMLFragment;
 import org.apache.tools.ant.util.DOMElementWriter;
 import org.apache.tools.ant.util.FileUtils;
@@ -35,7 +36,6 @@
  *
  * Known limitations:
  * <ol>
- * <li>Currently no XMLNS support</li>
  * <li>Processing Instructions get ignored</li>
  * <li>Encoding is always UTF-8</li>
  * </ol>
@@ -46,6 +46,7 @@
 
     private File file;
     private boolean append;
+    private NamespacePolicy namespacePolicy = NamespacePolicy.DEFAULT;
     private static final String ERROR_NO_XML = "No nested XML specified";
 
     /**
@@ -57,6 +58,16 @@
     }
 
     /**
+     * Set the namespace policy for the xml file
+     * @param s namespace policy: "ignore," "elementsOnly," or "all"
+     * @see
+     * org.apache.tools.ant.util.DOMElementWriter.XmlNamespacePolicy
+     */
+    public void setNamespacePolicy(NamespacePolicy n) {
+        namespacePolicy = n;
+    }
+    
+    /**
      * Set whether to append the output file.
      * @param b boolean append flag.
      */
@@ -68,7 +79,8 @@
      * Execute the task.
      */
     public void execute() {
-        DOMElementWriter writer = new DOMElementWriter(!append);
+        DOMElementWriter writer =
+            new DOMElementWriter(!append, namespacePolicy.getPolicy());
         OutputStream os = null;
         try {
             if (file != null) {
@@ -90,4 +102,36 @@
         }
     }
 
+    public static class NamespacePolicy extends EnumeratedAttribute {
+        private static final String IGNORE = "ignore";
+        private static final String ELEMENTS = "elementsOnly";
+        private static final String ALL = "all";
+
+        public static final NamespacePolicy DEFAULT
+            = new NamespacePolicy(IGNORE);
+
+        public NamespacePolicy() {}
+
+        public NamespacePolicy(String s) {
+            setValue(s);
+        }
+        /** {@inheritDoc}. */
+        public String[] getValues() {
+            return new String[] {IGNORE, ELEMENTS, ALL};
+        }
+
+        public DOMElementWriter.XmlNamespacePolicy getPolicy() {
+            String s = getValue();
+            if (IGNORE.equalsIgnoreCase(s)) {
+                return DOMElementWriter.XmlNamespacePolicy.IGNORE;
+            } else if (ELEMENTS.equalsIgnoreCase(s)) {
+                return
+                    DOMElementWriter.XmlNamespacePolicy.ONLY_QUALIFY_ELEMENTS;
+            } else if (ALL.equalsIgnoreCase(s)) {
+                return DOMElementWriter.XmlNamespacePolicy.QUALIFY_ALL;
+            } else {
+                throw new BuildException("Invalid namespace policy: " + s);
+            }
+        }
+    }
 }

Modified: ant/core/trunk/src/tests/antunit/taskdefs/echoxml-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/echoxml-test.xml?rev=688091&r1=688090&r2=688091&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/echoxml-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/echoxml-test.xml Fri Aug 22 08:18:17 2008
@@ -56,10 +56,35 @@
     </au:expectfailure>
   </target>
   
-  <target name="test-ns"> <!-- comment this if you don't have the svn trunk of antunit
-->
-    <echoxml file="${file}" xmlns:a="antlib:a">
-      <a:something />
+ <!-- comment this and the next targets if you don't have the svn
+      trunk of antunit -->
+  <target name="test-ns-all">
+    <echoxml file="${file}" xmlns:a="antlib:a"
+             namespacepolicy="all">
+      <a:something a:foo="bar"/>
     </echoxml>
     <au:assertResourceContains resource="${file}" value="a:something"/>
+    <au:assertResourceContains resource="${file}" value="antlib:a"/>
   </target>
+
+  <target name="test-ns-elementsOnly">
+    <echoxml file="${file}" xmlns:a="antlib:a"
+             namespacepolicy="elementsOnly">
+      <a:something a:foo="bar"/>
+    </echoxml>
+    <au:assertResourceContains resource="${file}" value="a:something"/>
+    <au:assertResourceContains resource="${file}" value="antlib:a"/>
+  </target>
+
+  <target name="test-ns-ignore">
+    <echoxml file="${file}" xmlns:a="antlib:a"
+             namespacepolicy="ignore">
+      <a:something a:foo="bar"/>
+    </echoxml>
+    <au:assertResourceContains resource="${file}" value="a:something"/>
+    <au:assertFalse message="Didn't expecte ${file} to contain antlib:a">
+      <resourcecontains resource="${file}" substring="antlib:a"/>
+    </au:assertFalse>
+  </target>
+
 </project>



Mime
View raw message