git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@688091 13f79535-47bb-0310-9956-ffa450edef68master
@@ -138,6 +138,7 @@ Jesse Glick | |||||
Jesse Stockall | Jesse Stockall | ||||
Jim Allers | Jim Allers | ||||
Joerg Wassmer | Joerg Wassmer | ||||
Joey Richey | |||||
John Sisson | John Sisson | ||||
Jon Dickinson | Jon Dickinson | ||||
Jon S. Stevens | Jon S. Stevens | ||||
@@ -282,6 +282,9 @@ Other changes: | |||||
an URL. | an URL. | ||||
Bugzilla Report 28881 | Bugzilla Report 28881 | ||||
* <echoxml> now supports XML namespaces. | |||||
Bugzilla Report 36804. | |||||
Changes from Ant 1.7.0 TO Ant 1.7.1 | Changes from Ant 1.7.0 TO Ant 1.7.1 | ||||
============================================= | ============================================= | ||||
@@ -580,6 +580,10 @@ | |||||
<first>Joerg</first> | <first>Joerg</first> | ||||
<last>Wassmer</last> | <last>Wassmer</last> | ||||
</name> | </name> | ||||
<name> | |||||
<first>Joey</first> | |||||
<last>Richey</last> | |||||
</name> | |||||
<name> | <name> | ||||
<first>Jon</first> | <first>Jon</first> | ||||
<last>Dickinson</last> | <last>Dickinson</last> | ||||
@@ -45,6 +45,14 @@ | |||||
<td valign="top">Whether to append <code>file</code>, if specified.</td> | <td valign="top">Whether to append <code>file</code>, if specified.</td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </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> | </table> | ||||
<h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
Nested XML content is required. | Nested XML content is required. | ||||
@@ -23,6 +23,7 @@ import java.io.FileOutputStream; | |||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.BuildException; | 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.XMLFragment; | ||||
import org.apache.tools.ant.util.DOMElementWriter; | import org.apache.tools.ant.util.DOMElementWriter; | ||||
import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
@@ -35,7 +36,6 @@ import org.w3c.dom.Element; | |||||
* | * | ||||
* Known limitations: | * Known limitations: | ||||
* <ol> | * <ol> | ||||
* <li>Currently no XMLNS support</li> | |||||
* <li>Processing Instructions get ignored</li> | * <li>Processing Instructions get ignored</li> | ||||
* <li>Encoding is always UTF-8</li> | * <li>Encoding is always UTF-8</li> | ||||
* </ol> | * </ol> | ||||
@@ -46,6 +46,7 @@ public class EchoXML extends XMLFragment { | |||||
private File file; | private File file; | ||||
private boolean append; | private boolean append; | ||||
private NamespacePolicy namespacePolicy = NamespacePolicy.DEFAULT; | |||||
private static final String ERROR_NO_XML = "No nested XML specified"; | private static final String ERROR_NO_XML = "No nested XML specified"; | ||||
/** | /** | ||||
@@ -56,6 +57,16 @@ public class EchoXML extends XMLFragment { | |||||
file = f; | file = f; | ||||
} | } | ||||
/** | |||||
* 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. | * Set whether to append the output file. | ||||
* @param b boolean append flag. | * @param b boolean append flag. | ||||
@@ -68,7 +79,8 @@ public class EchoXML extends XMLFragment { | |||||
* Execute the task. | * Execute the task. | ||||
*/ | */ | ||||
public void execute() { | public void execute() { | ||||
DOMElementWriter writer = new DOMElementWriter(!append); | |||||
DOMElementWriter writer = | |||||
new DOMElementWriter(!append, namespacePolicy.getPolicy()); | |||||
OutputStream os = null; | OutputStream os = null; | ||||
try { | try { | ||||
if (file != null) { | if (file != null) { | ||||
@@ -90,4 +102,36 @@ public class EchoXML extends XMLFragment { | |||||
} | } | ||||
} | } | ||||
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); | |||||
} | |||||
} | |||||
} | |||||
} | } |
@@ -56,10 +56,35 @@ | |||||
</au:expectfailure> | </au:expectfailure> | ||||
</target> | </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> | </echoxml> | ||||
<au:assertResourceContains resource="${file}" value="a:something"/> | <au:assertResourceContains resource="${file}" value="a:something"/> | ||||
<au:assertResourceContains resource="${file}" value="antlib:a"/> | |||||
</target> | </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> | </project> |