Save This Page
Home » apache-ant-1.8.1 » org.apache.tools » ant » types » [javadoc | source]
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:

  1. In the local filesystem
  2. In the classpath
  3. Using the Apache xml-commons resolver (if it is available)
  4. 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 
Fields inherited from org.apache.tools.ant.types.DataType:
ref,  checked
Fields inherited from org.apache.tools.ant.ProjectComponent:
project,  location,  description
Constructor:
 public XMLCatalog() 
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 org.apache.tools.ant.ProjectComponent:
clone,   getDescription,   getLocation,   getProject,   log,   log,   setDescription,   setLocation,   setProject
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) 
    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 
    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 
    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() 
    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() 
    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 
 public Path getCatalogPath() 
    Returns the catalog path in which to attempt to resolve DTDs.
 public Source resolve(String href,
    String base) throws TransformerException 
    Implements the URIResolver.resolve() interface method.
 public InputSource resolveEntity(String publicId,
    String systemId) throws SAXException, IOException 
    Implements the EntityResolver.resolveEntity() interface method.
 public  void setCatalogPathRef(Reference r) 
    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) 
    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) 
    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 
    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.