diff --git a/docs/manual/CoreTypes/xmlcatalog.html b/docs/manual/CoreTypes/xmlcatalog.html index 7581dd632..83f2041e9 100644 --- a/docs/manual/CoreTypes/xmlcatalog.html +++ b/docs/manual/CoreTypes/xmlcatalog.html @@ -63,8 +63,8 @@ task uses XMLCatalogs for both entity and URI resolution.

XMLCatalogs are specified as either a reference to another XMLCatalog, defined previously in a build file, or as a list of dtd or entity locations. In addition, -external catalog files may be specified in catalogfiles -filesets, but they will be ignored unless the resolver library from +external catalog files may be specified in a nested catalogpath , +but they will be ignored unless the resolver library from xml-commons is available in the system classpath. 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 @@ href="http://oasis-open.org/committees/entity/background/9401.html"> plain text format or XML format. If the xml-commons resolver library is not found in the -classpath, external catalog files, specified in catalogfiles -filesets, will be ignored and a warning will be logged. In this case, however, -processing of inline entries will proceed normally.

+classpath, external catalog files, specified in catalogpath (or +the deprecated catalogfiles) , will be ignored and a warning +will be logged. In this case, however, processing of inline entries will +proceed normally.

Currently, only <dtd> and <entity> elements may be specified inline; these roughly correspond to OASIS catalog entry types PUBLIC and @@ -207,21 +208,25 @@ basedir.

The classpath to use for entity resolution. The nested <classpath> is a path-like structure.

-

catalogfiles

+

catalogpath

-The nested catalogfiles element specifies a FileSet. All files included in -this fileset are assumed to be OASIS catalog files, in either +The nested catalogpath element is a path-like structure listing catalog files to +search. All files in this path are assumed to be OASIS catalog files, in +either plain text format or -XML format. Multiple catalogfiles 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 -catalogfiles will be ignored and a warning will be -logged. +XML format. Entries specifying nonexistent files will be ignored. If the +resolver library from xml-commons is not available in the classpath, all +catalogpaths will be ignored and a warning will be logged. +

+

catalogfiles (deprecated)

+

+The nested catalogfiles element specifies a FileSet. This is equivalent to +specifying a <fileset> inside a catalogpath, +and is retained for backwards-compatibility.

Examples

Set up an XMLCatalog with a single dtd referenced locally in a user's @@ -260,13 +265,17 @@ formats:

<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>

To reference the above XMLCatalog in an xslt task:

diff --git a/src/etc/testcases/taskdefs/optional/xmlvalidate.xml b/src/etc/testcases/taskdefs/optional/xmlvalidate.xml index eebf17218..53a583944 100644 --- a/src/etc/testcases/taskdefs/optional/xmlvalidate.xml +++ b/src/etc/testcases/taskdefs/optional/xmlvalidate.xml @@ -49,6 +49,19 @@ + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/types/XMLCatalog.java b/src/main/org/apache/tools/ant/types/XMLCatalog.java index b403a80d0..838f6bfb9 100644 --- a/src/main/org/apache/tools/ant/types/XMLCatalog.java +++ b/src/main/org/apache/tools/ant/types/XMLCatalog.java @@ -104,9 +104,13 @@ import org.xml.sax.XMLReader; * href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html"> * XML format. If the xml-commons resolver library is not found * in the classpath, external catalog files, specified in - * <catalogfiles> filesets, will be ignored and a - * warning will be logged. In this case, however, processing of - * inline entries will proceed normally.

+ * <catalogfiles> filesets and + * <catalogpath> paths, will be ignored and a warning will + * be logged. In this case, however, processing of inline entries will proceed + * normally.

+ *

Note that, as <catalogpath> can contain nested + * filesets, it is more general than <catalogfiles>, which + * should be considered deprecated.

* *

Currently, only <dtd> and * <entity> elements may be specified inline; these @@ -121,12 +125,14 @@ import org.xml.sax.XMLReader; *   <dtd publicId="" location="/path/to/file2.jar" />
*   <entity publicId="" location="/path/to/file3.jar" />
*   <entity publicId="" location="/path/to/file4.jar" />
- *   <catalogfiles dir="${basedir}" includes="**\catalog" />
+ *   <catalogpath>
+ *     <pathelement location="/etc/sgml/catalog"/>
+ *   </catalogpath>
*   <catalogfiles dir="/opt/catalogs/" includes="**\catalog.xml" />
* </xmlcatalog>
* *

- * The object implemention sometask must provide a method called + * Tasks wishing to use <xmlcatalog> must provide a method called * createXMLCatalog which returns an instance of * XMLCatalog. Nested DTD and entity definitions are handled by * the XMLCatalog object and must be labeled dtd and @@ -154,6 +160,7 @@ import org.xml.sax.XMLReader; * @author dIon Gillard * @author Erik Hatcher * @author Craeg Strong + * @author Jeff Turner * @version $Id$ */ public class XMLCatalog extends DataType @@ -169,6 +176,11 @@ public class XMLCatalog extends DataType */ 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 @@ -285,6 +297,52 @@ public class XMLCatalog extends DataType getElements().addElement(fs); } + + /** Creates a nested <catalogpath> element. + * Not allowed if this catalog is itself a reference to another + * catalog -- that is, a catalog cannot both refer to another + * and 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 and 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 <dtd> element. Not * allowed if this catalog is itself a reference to another @@ -344,6 +402,10 @@ public class XMLCatalog extends DataType // 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 @@ public class XMLCatalog extends DataType 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 @@ public class XMLCatalog extends DataType throw new BuildException(ex); } + // Parse each catalog listed in nested elements. Enumeration enum = getElements().elements(); while (enum.hasMoreElements()) { Object o = enum.nextElement(); @@ -1096,9 +1165,28 @@ public class XMLCatalog extends DataType } } } + + // Parse each catalog listed in nested 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 diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java index 954e59d75..cbbd15e30 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java @@ -132,6 +132,17 @@ public class XmlValidateTest extends BuildFileTest { executeTarget("xmlcatalogfiles"); } + /** + * 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 */