peterreilly 2004/09/10 01:50:25
Modified: . WHATSNEW CONTRIBUTORS
src/main/org/apache/tools/ant/taskdefs XmlProperty.java
docs/manual/CoreTasks xmlproperty.html
src/etc/testcases/taskdefs xmlproperty.xml
src/testcases/org/apache/tools/ant/taskdefs
XmlPropertyTest.java
Added: src/etc/testcases/taskdefs xmlproperty_needscat.xml
skinconfig.dtd
Log:
add xmlcatalog nested element to the xmlproperty task
PR: 27053
Obtained from: David Crossley and Dave Brondsema
Revision Changes Path
1.658 +2 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.657
retrieving revision 1.658
diff -u -r1.657 -r1.658
--- WHATSNEW 6 Sep 2004 09:14:41 -0000 1.657
+++ WHATSNEW 10 Sep 2004 08:50:25 -0000 1.658
@@ -69,6 +69,8 @@
* Allow file attribute of <move> to rename a directory.
Bugzilla Report 22863.
+* Add xmlcatalog nested element to XmlProperty. Bugzilla report 27053.
+
Fixed bugs:
-----------
1.30 +1 -0 ant/CONTRIBUTORS
Index: CONTRIBUTORS
===================================================================
RCS file: /home/cvs/ant/CONTRIBUTORS,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- CONTRIBUTORS 2 Aug 2004 14:32:43 -0000 1.29
+++ CONTRIBUTORS 10 Sep 2004 08:50:25 -0000 1.30
@@ -39,6 +39,7 @@
Davanum Srinivas
Dave Brondsema
David A. Herman
+David Crossley
David Kavanagh
David Maclean
David Rees
1.23 +66 -4
ant/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java
Index: XmlProperty.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- XmlProperty.java 9 Mar 2004 16:48:07 -0000 1.22
+++ XmlProperty.java 10 Sep 2004 08:50:25 -0000 1.23
@@ -21,10 +21,12 @@
import java.io.IOException;
import java.util.Hashtable;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.XMLCatalog;
import org.apache.tools.ant.util.FileUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -32,6 +34,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
+import org.xml.sax.EntityResolver;
/**
* Loads property values from a valid XML file, generating the
@@ -178,6 +181,7 @@
private File rootDirectory = null;
private FileUtils fileUtils = FileUtils.newFileUtils();
private Hashtable addedAttributes = new Hashtable();
+ private XMLCatalog xmlCatalog = new XMLCatalog();
private static final String ID = "id";
private static final String REF_ID = "refid";
@@ -202,6 +206,15 @@
public void init() {
super.init();
+ xmlCatalog.setProject(getProject());
+ }
+
+
+ /**
+ * @return the xmlCatalog as the entityresolver.
+ */
+ protected EntityResolver getEntityResolver() {
+ return xmlCatalog;
}
/**
@@ -226,7 +239,9 @@
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setValidating(validate);
factory.setNamespaceAware(false);
- Document document = factory.newDocumentBuilder().parse(src);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver(getEntityResolver());
+ Document document = builder.parse(src);
Element topElement = document.getDocumentElement();
// Keep a hashtable of attributes added by this task.
@@ -571,48 +586,95 @@
this.collapseAttributes = collapseAttributes;
}
- public void setSemanticAttributes (boolean semanticAttributes) {
+ /**
+ * Attribute to enable special handling of attributes - see ant manual.
+ * @param semanticAttributes if true enable the special handling.
+ */
+ public void setSemanticAttributes(boolean semanticAttributes) {
this.semanticAttributes = semanticAttributes;
}
- public void setRootDirectory (File rootDirectory) {
+ /**
+ * The directory to use for resolving file references.
+ * Ignored if semanticAttributes is not set to true.
+ * @param rootDirectory the directory.
+ */
+ public void setRootDirectory(File rootDirectory) {
this.rootDirectory = rootDirectory;
}
- public void setIncludeSemanticAttribute (boolean
includeSemanticAttribute) {
+ /**
+ * Include the semantic attribute name as part of the property name.
+ * Ignored if semanticAttributes is not set to true.
+ * @param includeSemanticAttribute if true include the sematic attribute
+ * name.
+ */
+ public void setIncludeSemanticAttribute(boolean
includeSemanticAttribute) {
this.includeSemanticAttribute = includeSemanticAttribute;
}
+ /**
+ * add an XMLCatalog as a nested element; optional.
+ * @param catalog the XMLCatalog to use
+ */
+ public void addConfiguredXMLCatalog(XMLCatalog catalog) {
+ xmlCatalog.addConfiguredXMLCatalog(catalog);
+ }
+
/* Expose members for extensibility */
+ /**
+ * @return the file attribute.
+ */
protected File getFile () {
return this.src;
}
+ /**
+ * @return the prefix attribute.
+ */
protected String getPrefix () {
return this.prefix;
}
+ /**
+ * @return the keeproot attribute.
+ */
protected boolean getKeeproot () {
return this.keepRoot;
}
+ /**
+ * @return the validate attribute.
+ */
protected boolean getValidate () {
return this.validate;
}
+ /**
+ * @return the collapse attributes attribute.
+ */
protected boolean getCollapseAttributes () {
return this.collapseAttributes;
}
+ /**
+ * @return the semantic attributes attribute.
+ */
protected boolean getSemanticAttributes () {
return this.semanticAttributes;
}
+ /**
+ * @return the root directory attribute.
+ */
protected File getRootDirectory () {
return this.rootDirectory;
}
+ /**
+ * @return the include semantic attribute.
+ */
protected boolean getIncludeSementicAttribute () {
return this.includeSemanticAttribute;
}
1.8 +6 -1 ant/docs/manual/CoreTasks/xmlproperty.html
Index: xmlproperty.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/xmlproperty.html,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- xmlproperty.html 9 Feb 2004 21:50:06 -0000 1.7
+++ xmlproperty.html 10 Sep 2004 08:50:25 -0000 1.8
@@ -131,6 +131,11 @@
</tr>
</table>
+<h3><a name="nested">Nested Elements</a></h3>
+<h4>xmlcatalog</h4>
+<p>The <a href="../CoreTypes/xmlcatalog.html"><tt><xmlcatalog></tt></a>
+element is used to perform entity resolution.</p>
+
<a name="examples">
<h3>Examples</h3>
</a>
@@ -257,4 +262,4 @@
Reserved.</p>
</body>
-</html>
\ No newline at end of file
+</html>
1.3 +10 -0 ant/src/etc/testcases/taskdefs/xmlproperty.xml
Index: xmlproperty.xml
===================================================================
RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/xmlproperty.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- xmlproperty.xml 23 Jul 2003 12:11:09 -0000 1.2
+++ xmlproperty.xml 10 Sep 2004 08:50:25 -0000 1.3
@@ -7,4 +7,14 @@
<target name="testdtd">
<xmlproperty file="xmlproperty_withdtd.xml"/>
</target>
+
+ <target name="testneedscat">
+ <xmlproperty file="xmlproperty_needscat.xml">
+ <xmlcatalog>
+ <dtd publicId="-//FOO//DTD Skin Configuration V0.1//EN"
+ location="skinconfig.dtd"/>
+ </xmlcatalog>
+ </xmlproperty>
+ </target>
+
</project>
1.1 ant/src/etc/testcases/taskdefs/xmlproperty_needscat.xml
Index: xmlproperty_needscat.xml
===================================================================
<?xml version="1.0"?>
<!DOCTYPE skinconfig PUBLIC "-//FOO//DTD Skin Configuration V0.1//EN"
"http://example-no-dtd.com/dtd/skinconfig.dtd">
<skinconfig>
<foo>true</foo>
<bar>false</bar>
</skinconfig>
1.1 ant/src/etc/testcases/taskdefs/skinconfig.dtd
Index: skinconfig.dtd
===================================================================
<!ELEMENT skinconfig (foo, bar?)>
<!ELEMENT foo (#PCDATA)>
<!ELEMENT bar (#PCDATA)>
1.13 +5 -0
ant/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
Index: XmlPropertyTest.java
===================================================================
RCS file:
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- XmlPropertyTest.java 9 Mar 2004 16:48:57 -0000 1.12
+++ XmlPropertyTest.java 10 Sep 2004 08:50:25 -0000 1.13
@@ -104,6 +104,11 @@
doTest("testSemanticInclude", false, false, true, false, true);
}
+ public void testNeedsCatalog() {
+ executeTarget("testneedscat");
+ assertEquals("true", getProject().getProperty("skinconfig.foo"));
+ }
+
/**
* Actually run a test, finding all input files (and corresponding
* goldfile)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]