You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2002/12/02 17:06:09 UTC
cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional XmlValidateTest.java
bodewig 2002/12/02 08:06:09
Modified: docs/manual/CoreTypes xmlcatalog.html
src/etc/testcases/taskdefs/optional xmlvalidate.xml
src/main/org/apache/tools/ant/types XMLCatalog.java
src/testcases/org/apache/tools/ant/taskdefs/optional
XmlValidateTest.java
Log:
Add <catalogpath> to <xmlcatalog>.
PR: 14978
Submitted by: Jeff Turner <jefft at apache.org>
Revision Changes Path
1.6 +32 -23 jakarta-ant/docs/manual/CoreTypes/xmlcatalog.html
Index: xmlcatalog.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTypes/xmlcatalog.html,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- xmlcatalog.html 20 Nov 2002 10:15:23 -0000 1.5
+++ xmlcatalog.html 2 Dec 2002 16:06:09 -0000 1.6
@@ -63,8 +63,8 @@
<p>XMLCatalogs are specified as either a reference to another
XMLCatalog, defined previously in a build file, or as a list of
<code>dtd</code> or <code>entity</code> locations. In addition,
-external catalog files may be specified in <code>catalogfiles</code>
-filesets, but they will be ignored unless the resolver library from
+external catalog files may be specified in a nested <code>catalogpath</code> ,
+but they will be ignored unless the resolver library from
xml-commons is available in the system classpath. <b>Due to backwards
incompatible changes in the resolver code after the release of
resolver 1.0, Ant will not support resolver.jar in version 1.0 - we
@@ -84,9 +84,10 @@
plain text format</a> or <a
href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
XML format</a>. If the xml-commons resolver library is not found in the
-classpath, external catalog files, specified in <code>catalogfiles</code>
-filesets, will be ignored and a warning will be logged. In this case, however,
-processing of inline entries will proceed normally.</p>
+classpath, external catalog files, specified in <code>catalogpath</code> (or
+the deprecated <code>catalogfiles</code>) , will be ignored and a warning
+will be logged. In this case, however, processing of inline entries will
+proceed normally.</p>
<p>Currently, only <code><dtd></code> and
<code><entity></code> elements may be specified inline; these
roughly correspond to OASIS catalog entry types <code>PUBLIC</code> and
@@ -207,21 +208,25 @@
<p>The classpath to use for <a href="#ResolverAlgorithm">entity
resolution</a>. The nested <code><classpath></code> is a
<a href="../using.html#path">path</a>-like structure.</p>
-<h4>catalogfiles</h4>
+<h4>catalogpath</h4>
<p>
-The nested <code>catalogfiles</code> element specifies a <a
-href="../CoreTypes/fileset.html">FileSet</a>. All files included in
-this fileset are assumed to be OASIS catalog files, in either
+The nested <code>catalogpath</code> element is a <a
+href="using.html#path">path</a>-like structure listing catalog files to
+search. All files in this path are assumed to be OASIS catalog files, in
+either
<a href="http://oasis-open.org/committees/entity/background/9401.html">
plain text format</a> or <a
href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
-XML format</a>. Multiple <code>catalogfiles</code> filesets may be
-specified. Of course, if you use wildcards in your fileset, you will
-want to use some sort of naming convention to ensure that you don't
-accidentally match non-catalog files. If the resolver library from
-xml-commons is not available in the classpath, all
-<code>catalogfiles</code> will be ignored and a warning will be
-logged.
+XML format</a>. Entries specifying nonexistent files will be ignored. If the
+resolver library from xml-commons is not available in the classpath, all
+<code>catalogpaths</code> will be ignored and a warning will be logged.
+</p>
+<h4>catalogfiles (deprecated)</h4>
+<p>
+The nested <code>catalogfiles</code> element specifies a <a
+href="../CoreTypes/fileset.html">FileSet</a>. This is equivalent to
+specifying a <code><fileset></code> inside a <code>catalogpath</code>,
+and is retained for backwards-compatibility.
</p>
<h3>Examples</h3>
<p>Set up an XMLCatalog with a single dtd referenced locally in a user's
@@ -260,13 +265,17 @@
<entity
publicId="LargeLogo"
location="com/arielpartners/images/ariel-logo-large.gif"/>
- <xmlcatalog refid="commonDTDs"/>
- <catalogfiles
- dir="/anetwork/drive"
- includes="**/catalog"/>
- <catalogfiles
- dir="/my/catalogs"
- includes="**/catalog.xml"/>
+ <xmlcatalog refid="commonDTDs"/>
+ <catalogpath>
+ <pathelement location="/etc/sgml/catalog"/>
+ <fileset
+ dir="/anetwork/drive"
+ includes="**/catalog"/>
+ <fileset
+ dir="/my/catalogs"
+ includes="**/catalog.xml"/>
+ </catalogpath>
+ </xmlcatalog>
</xmlcatalog>
</pre></blockquote>
<p>To reference the above XMLCatalog in an <code>xslt</code> task:<p>
1.9 +13 -0 jakarta-ant/src/etc/testcases/taskdefs/optional/xmlvalidate.xml
Index: xmlvalidate.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/optional/xmlvalidate.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- xmlvalidate.xml 27 Nov 2002 16:38:56 -0000 1.8
+++ xmlvalidate.xml 2 Dec 2002 16:06:09 -0000 1.9
@@ -49,6 +49,19 @@
</xmlcatalog>
</xmlvalidate>
</target>
+
+ <target name="xmlcatalogpath">
+ <xmlvalidate warn="false">
+ <fileset dir="xml" includes="**/about.xml"/>
+ <xmlcatalog classpath="xml">
+ <catalogpath>
+ <pathelement location="xml/catalog"/>
+ </catalogpath>
+ <dtd publicID="-//stevo//DTD doc 1.0//EN"
+ location="doc.dtd"/>
+ </xmlcatalog>
+ </xmlvalidate>
+ </target>
<target name="testSchemaGood">
<xmlvalidate warn="false" lenient="no" >
1.18 +95 -7 jakarta-ant/src/main/org/apache/tools/ant/types/XMLCatalog.java
Index: XMLCatalog.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/XMLCatalog.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- XMLCatalog.java 8 Nov 2002 09:53:21 -0000 1.17
+++ XMLCatalog.java 2 Dec 2002 16:06:09 -0000 1.18
@@ -104,9 +104,13 @@
* href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
* XML format</a>. If the xml-commons resolver library is not found
* in the classpath, external catalog files, specified in
- * <code><catalogfiles></code> filesets, will be ignored and a
- * warning will be logged. In this case, however, processing of
- * inline entries will proceed normally.</p>
+ * <code><catalogfiles></code> filesets and
+ * <code><catalogpath></code> paths, will be ignored and a warning will
+ * be logged. In this case, however, processing of inline entries will proceed
+ * normally.</p>
+ * <p>Note that, as <code><catalogpath></code> can contain nested
+ * filesets, it is more general than <code><catalogfiles></code>, which
+ * should be considered deprecated.</p>
*
* <p>Currently, only <code><dtd></code> and
* <code><entity></code> elements may be specified inline; these
@@ -121,12 +125,14 @@
* <dtd publicId="" location="/path/to/file2.jar" /><br>
* <entity publicId="" location="/path/to/file3.jar" /><br>
* <entity publicId="" location="/path/to/file4.jar" /><br>
- * <catalogfiles dir="${basedir}" includes="**\catalog" /><br>
+ * <catalogpath><br>
+ * <pathelement location="/etc/sgml/catalog"/><br>
+ * </catalogpath><br>
* <catalogfiles dir="/opt/catalogs/" includes="**\catalog.xml" /><br>
* </xmlcatalog><br>
* </code>
* <p>
- * The object implemention <code>sometask</code> must provide a method called
+ * Tasks wishing to use <code><xmlcatalog></code> must provide a method called
* <code>createXMLCatalog</code> which returns an instance of
* <code>XMLCatalog</code>. Nested DTD and entity definitions are handled by
* the XMLCatalog object and must be labeled <code>dtd</code> and
@@ -154,6 +160,7 @@
* @author dIon Gillard
* @author Erik Hatcher
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
+ * @author Jeff Turner
* @version $Id$
*/
public class XMLCatalog extends DataType
@@ -170,6 +177,11 @@
private Path classpath;
/**
+ * Path listing external catalog files to search when resolving entities
+ */
+ private Path catalogPath;
+
+ /**
* The name of the bridge to the Apache xml-commons resolver
* class, used to determine whether resolver.jar is present in the
* classpath.
@@ -285,6 +297,52 @@
getElements().addElement(fs);
}
+
+ /** Creates a nested <code><catalogpath></code> element.
+ * Not allowed if this catalog is itself a reference to another
+ * catalog -- that is, a catalog cannot both refer to another
+ * <em>and</em> contain elements or other attributes.
+ *
+ * @param fs the fileset of external catalogs.
+ * @exception BuildException
+ * if this is a reference and no nested elements are allowed.
+ */
+ public Path createCatalogPath() {
+ if (isReference()) {
+ throw noChildrenAllowed();
+ }
+ if (this.catalogPath == null) {
+ this.catalogPath = new Path(getProject());
+ }
+ setChecked( false );
+ return this.catalogPath.createPath();
+ }
+
+ /**
+ * Allows catalogpath reference. Not allowed if this catalog is
+ * itself a reference to another catalog -- that is, a catalog
+ * cannot both refer to another <em>and</em> contain elements or
+ * other attributes.
+ */
+ public void setCatalogPathRef(Reference r) {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ createCatalogPath().setRefid(r);
+ setChecked( false );
+ }
+
+
+ /**
+ * Returns the catalog path in which to attempt to resolve DTDs.
+ *
+ * @return the catalog path
+ */
+ public Path getCatalogPath() {
+ return this.catalogPath;
+ }
+
+
/**
* Creates the nested <code><dtd></code> element. Not
* allowed if this catalog is itself a reference to another
@@ -344,6 +402,10 @@
// Append the classpath of the nested catalog
Path nestedClasspath = catalog.getClasspath();
createClasspath().append(nestedClasspath);
+
+ // Append the catalog path of the nested catalog
+ Path nestedCatalogPath = catalog.getCatalogPath();
+ createCatalogPath().append(nestedCatalogPath);
setChecked( false );
}
@@ -510,6 +572,12 @@
break;
}
}
+ if (getCatalogPath() != null &&
+ getCatalogPath().list().length != 0) {
+ log("Warning: catalogpath listing external catalogs"+
+ " will be ignored",
+ Project.MSG_WARN);
+ }
}
}
return catalogResolver;
@@ -1075,6 +1143,7 @@
throw new BuildException(ex);
}
+ // Parse each catalog listed in nested <catalogfile> elements.
Enumeration enum = getElements().elements();
while (enum.hasMoreElements()) {
Object o = enum.nextElement();
@@ -1096,9 +1165,28 @@
}
}
}
+
+ // Parse each catalog listed in nested <catalogpath> elements
+ Path catPath = getCatalogPath();
+ if (catPath != null) {
+ log("Using catalogpath '" + getCatalogPath()+"'", Project.MSG_DEBUG);
+ String[] catPathList = getCatalogPath().list();
+
+ for (int i=0; i< catPathList.length; i++) {
+ File catFile = new File(catPathList[i]);
+ log("Parsing "+catFile, Project.MSG_DEBUG);
+ try {
+ parseCatalog.invoke(resolverImpl,
+ new Object[]
+ { catFile.getPath() });
+ }
+ catch (Exception ex) {
+ throw new BuildException(ex);
+ }
+ }
+ }
}
externalCatalogsProcessed = true;
}
}
-
} //-- XMLCatalog
1.8 +11 -0 jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
Index: XmlValidateTest.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XmlValidateTest.java 27 Nov 2002 16:38:57 -0000 1.7
+++ XmlValidateTest.java 2 Dec 2002 16:06:09 -0000 1.8
@@ -133,6 +133,17 @@
}
/**
+ * Test nested catalogpath.
+ * It should be ignored if resolver.jar is not
+ * present, but will be used if it is. either
+ * way, test should work b/c we have a nested
+ * dtd with the same entity
+ */
+ public void testXmlCatalogPath() {
+ executeTarget("xmlcatalogpath");
+ }
+
+ /**
* Test nested xmlcatalog definitions
*/
public void testXmlCatalogNested() {
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>