org.apache.tools.ant.types
public class: XMLCatalog [javadoc |
source]
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.types.DataType
org.apache.tools.ant.types.XMLCatalog
All Implemented Interfaces:
URIResolver, Cloneable, EntityResolver
This data type provides a catalog of resource locations (such as
DTDs and XML entities), based on the
OASIS "Open Catalog" standard. The catalog entries are used
both for Entity resolution and URI resolution, in accordance with
the EntityResolver and URIResolver interfaces as defined
in the Java API for XML
Processing Specification.
Resource locations can be specified either in-line or in
external catalog file(s), or both. In order to use an external
catalog file, the xml-commons resolver library ("resolver.jar")
must be in your classpath. External catalog files may be either
plain text format or
XML format. If the xml-commons resolver library is not found
in the classpath, external catalog files, specified in
<catalogpath> paths, 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
correspond to OASIS catalog entry types PUBLIC and
URI respectively.
The following is a usage example:
<xmlcatalog>
<dtd publicId="" location="/path/to/file.jar" />
<dtd publicId="" location="/path/to/file2.jar" />
<entity publicId="" location="/path/to/file3.jar" />
<entity publicId="" location="/path/to/file4.jar" />
<catalogpath>
<pathelement location="/etc/sgml/catalog"/>
</catalogpath>
<catalogfiles dir="/opt/catalogs/" includes="**\catalog.xml" />
</xmlcatalog>
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
entity respectively.
The following is a description of the resolution algorithm:
entities/URIs/dtds are looked up in each of the following contexts,
stopping when a valid and readable resource is found:
- In the local filesystem
- In the classpath
- Using the Apache xml-commons resolver (if it is available)
- In URL-space
See XMLValidateTask for an example of a task that has integrated
support for XMLCatalogs.
Possible future extension could provide for additional OASIS
entry types to be specified inline.
| Field Summary |
|---|
| public static final String | APACHE_RESOLVER | The name of the bridge to the Apache xml-commons resolver
class, used to determine whether resolver.jar is present in the
classpath. |
| public static final String | CATALOG_RESOLVER | Resolver base class |
| Method from org.apache.tools.ant.types.XMLCatalog Summary: |
|---|
|
addConfiguredXMLCatalog, addDTD, addEntity, createCatalogPath, createClasspath, dieOnCircularReference, getCatalogPath, resolve, resolveEntity, setCatalogPathRef, setClasspath, setClasspathRef, setRefid |
| Methods from org.apache.tools.ant.types.DataType: |
|---|
|
checkAttributesAllowed, checkChildrenAllowed, circularReference, clone, dieOnCircularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, pushAndInvokeCircularReferenceCheck, setChecked, setRefid, toString, tooManyAttributes |
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.apache.tools.ant.types.XMLCatalog Detail: |
public void addConfiguredXMLCatalog(XMLCatalog catalog) {
if (isReference()) {
throw noChildrenAllowed();
}
// Add all nested elements to our catalog
Vector newElements = catalog.getElements();
Vector ourElements = getElements();
Enumeration e = newElements.elements();
while (e.hasMoreElements()) {
ourElements.addElement(e.nextElement());
}
// 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);
}
Loads a nested <xmlcatalog> into our
definition. 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 addDTD(ResourceLocation dtd) throws BuildException {
if (isReference()) {
throw noChildrenAllowed();
}
getElements().addElement(dtd);
setChecked(false);
}
Creates the nested <dtd> 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. |
public void addEntity(ResourceLocation entity) throws BuildException {
addDTD(entity);
}
Creates the nested <entity> 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. |
public Path createCatalogPath() {
if (isReference()) {
throw noChildrenAllowed();
}
if (this.catalogPath == null) {
this.catalogPath = new Path(getProject());
}
setChecked(false);
return this.catalogPath.createPath();
}
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. |
public Path createClasspath() {
if (isReference()) {
throw noChildrenAllowed();
}
if (this.classpath == null) {
this.classpath = new Path(getProject());
}
setChecked(false);
return this.classpath.createPath();
}
Allows nested classpath elements. 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. |
protected synchronized void dieOnCircularReference(Stack stk,
Project p) throws BuildException {
if (isChecked()) {
return;
}
if (isReference()) {
super.dieOnCircularReference(stk, p);
} else {
if (classpath != null) {
pushAndInvokeCircularReferenceCheck(classpath, stk, p);
}
if (catalogPath != null) {
pushAndInvokeCircularReferenceCheck(catalogPath, stk, p);
}
setChecked(true);
}
}
|
public Path getCatalogPath() {
return getRef().catalogPath;
}
Returns the catalog path in which to attempt to resolve DTDs. |
public Source resolve(String href,
String base) throws TransformerException {
if (isReference()) {
return getRef().resolve(href, base);
}
dieOnCircularReference();
SAXSource source = null;
String uri = removeFragment(href);
log("resolve: '" + uri + "' with base: '" + base + "'", Project.MSG_DEBUG);
source = (SAXSource) getCatalogResolver().resolve(uri, base);
if (source == null) {
log("No matching catalog entry found, parser will use: '"
+ href + "'", Project.MSG_DEBUG);
//
// Cannot return a null source, because we have to call
// setEntityResolver (see setEntityResolver javadoc comment)
//
source = new SAXSource();
URL baseURL = null;
try {
if (base == null) {
baseURL = FILE_UTILS.getFileURL(getProject().getBaseDir());
} else {
baseURL = new URL(base);
}
URL url = (uri.length() == 0 ? baseURL : new URL(baseURL, uri));
source.setInputSource(new InputSource(url.toString()));
} catch (MalformedURLException ex) {
// At this point we are probably in failure mode, but
// try to use the bare URI as a last gasp
source.setInputSource(new InputSource(uri));
}
}
setEntityResolver(source);
return source;
}
Implements the URIResolver.resolve() interface method. |
public InputSource resolveEntity(String publicId,
String systemId) throws SAXException, IOException {
if (isReference()) {
return getRef().resolveEntity(publicId, systemId);
}
dieOnCircularReference();
log("resolveEntity: '" + publicId + "': '" + systemId + "'",
Project.MSG_DEBUG);
InputSource inputSource =
getCatalogResolver().resolveEntity(publicId, systemId);
if (inputSource == null) {
log("No matching catalog entry found, parser will use: '"
+ systemId + "'", Project.MSG_DEBUG);
}
return inputSource;
}
Implements the EntityResolver.resolveEntity() interface method. |
public void setCatalogPathRef(Reference r) {
if (isReference()) {
throw tooManyAttributes();
}
createCatalogPath().setRefid(r);
setChecked(false);
}
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 setClasspath(Path classpath) {
if (isReference()) {
throw tooManyAttributes();
}
if (this.classpath == null) {
this.classpath = classpath;
} else {
this.classpath.append(classpath);
}
setChecked(false);
}
Allows simple classpath string. 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 setClasspathRef(Reference r) {
if (isReference()) {
throw tooManyAttributes();
}
createClasspath().setRefid(r);
setChecked(false);
}
Allows classpath 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 setRefid(Reference r) throws BuildException {
if (!elements.isEmpty()) {
throw tooManyAttributes();
}
super.setRefid(r);
}
Makes this instance in effect a reference to another XMLCatalog
instance.
You must not set another attribute or nest elements inside
this element if you make it a reference. That is, a catalog
cannot both refer to another and contain elements or
attributes. |