@@ -104,9 +104,13 @@ import org.xml.sax.XMLReader;
* 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 @@ import org.xml.sax.XMLReader;
* <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 @@ import org.xml.sax.XMLReader;
* @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
@@ -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 <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 @@ 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 <catalogfile> 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 <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