Class XMLCatalog
- java.lang.Object
- 
- org.apache.tools.ant.ProjectComponent
- 
- org.apache.tools.ant.types.DataType
- 
- org.apache.tools.ant.types.XMLCatalog
 
 
 
- 
- All Implemented Interfaces:
- java.lang.Cloneable,- javax.xml.transform.URIResolver,- org.xml.sax.EntityResolver
 
 public class XMLCatalog extends DataType implements org.xml.sax.EntityResolver, javax.xml.transform.URIResolver 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 EntityResolverandURIResolverinterfaces 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 typesPUBLICandURIrespectively.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 calledcreateXMLCatalogwhich returns an instance ofXMLCatalog. Nested DTD and entity definitions are handled by the XMLCatalog object and must be labeleddtdandentityrespectively.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 XMLValidateTaskfor 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 SummaryFields Modifier and Type Field Description static java.lang.StringAPACHE_RESOLVERThe name of the bridge to the Apache xml-commons resolver class, used to determine whether resolver.jar is present in the classpath.static java.lang.StringCATALOG_RESOLVERResolver base class- 
Fields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
 
- 
 - 
Constructor SummaryConstructors Constructor Description XMLCatalog()Default constructor
 - 
Method SummaryModifier and Type Method Description voidaddConfiguredXMLCatalog(XMLCatalog catalog)Loads a nested<xmlcatalog>into our definition.voidaddDTD(ResourceLocation dtd)Creates the nested<dtd>element.voidaddEntity(ResourceLocation entity)Creates the nested<entity>element.PathcreateCatalogPath()Creates a nested<catalogpath>element.PathcreateClasspath()Allows nested classpath elements.protected voiddieOnCircularReference(java.util.Stack<java.lang.Object> stk, Project p)Check to see whether any DataType we hold references to is included in the Stack (which holds all DataType instances that directly or indirectly reference this instance, including this instance itself).PathgetCatalogPath()Returns the catalog path in which to attempt to resolve DTDs.javax.xml.transform.Sourceresolve(java.lang.String href, java.lang.String base)Implements the URIResolver.resolve() interface method.org.xml.sax.InputSourceresolveEntity(java.lang.String publicId, java.lang.String systemId)Implements the EntityResolver.resolveEntity() interface method.voidsetCatalogPathRef(Reference r)Allows catalogpath reference.voidsetClasspath(Path classpath)Allows simple classpath string.voidsetClasspathRef(Reference r)Allows classpath reference.voidsetRefid(Reference r)Makes this instance in effect a reference to another XMLCatalog instance.- 
Methods inherited from class org.apache.tools.ant.types.DataTypecheckAttributesAllowed, checkChildrenAllowed, circularReference, clone, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, pushAndInvokeCircularReferenceCheck, setChecked, tooManyAttributes, toString
 - 
Methods inherited from class org.apache.tools.ant.ProjectComponentgetDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
 
- 
 
- 
- 
- 
Field Detail- 
APACHE_RESOLVERpublic static final java.lang.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.- See Also:
- Constant Field Values
 
 - 
CATALOG_RESOLVERpublic static final java.lang.String CATALOG_RESOLVER Resolver base class- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
createClasspathpublic 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.- Returns:
- a Path instance to be configured.
 
 - 
setClasspathpublic 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.- Parameters:
- classpath- the classpath to use to look up entities.
 
 - 
setClasspathRefpublic 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.- Parameters:
- r- an Ant reference containing a classpath.
 
 - 
createCatalogPathpublic 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.- Returns:
- a path to be configured as the catalog path.
- Throws:
- BuildException- if this is a reference and no nested elements are allowed.
 
 - 
setCatalogPathRefpublic 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.- Parameters:
- r- an Ant reference containing a classpath to be used as the catalog path.
 
 - 
getCatalogPathpublic Path getCatalogPath() Returns the catalog path in which to attempt to resolve DTDs.- Returns:
- the catalog path
 
 - 
addDTDpublic 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.- Parameters:
- dtd- the information about the PUBLIC resource mapping to be added to the catalog
- Throws:
- BuildException- if this is a reference and no nested elements are allowed.
 
 - 
addEntitypublic 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.- Parameters:
- entity- the information about the URI resource mapping to be added to the catalog.
- Throws:
- BuildException- if this is a reference and no nested elements are allowed.
 
 - 
addConfiguredXMLCatalogpublic 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.- Parameters:
- catalog- Nested XMLCatalog
 
 - 
setRefidpublic 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. - Overrides:
- setRefidin class- DataType
- Parameters:
- r- the reference to which this catalog instance is associated
- Throws:
- BuildException- if this instance already has been configured.
 
 - 
resolveEntitypublic org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException, java.io.IOExceptionImplements the EntityResolver.resolveEntity() interface method.- Specified by:
- resolveEntityin interface- org.xml.sax.EntityResolver
- Parameters:
- publicId- the public id to resolve.
- systemId- the system id to resolve.
- Returns:
- the resolved entity.
- Throws:
- org.xml.sax.SAXException- if there is a parsing problem.
- java.io.IOException- if there is an IO problem.
- See Also:
- EntityResolver.resolveEntity(java.lang.String, java.lang.String)
 
 - 
resolvepublic javax.xml.transform.Source resolve(java.lang.String href, java.lang.String base) throws javax.xml.transform.TransformerExceptionImplements the URIResolver.resolve() interface method.- Specified by:
- resolvein interface- javax.xml.transform.URIResolver
- Parameters:
- href- an href attribute.
- base- the base URI.
- Returns:
- a Source object, or null if href cannot be resolved.
- Throws:
- javax.xml.transform.TransformerException- if an error occurs.
- See Also:
- URIResolver.resolve(java.lang.String, java.lang.String)
 
 - 
dieOnCircularReferenceprotected void dieOnCircularReference(java.util.Stack<java.lang.Object> stk, Project p) throws BuildExceptionDescription copied from class:DataTypeCheck to see whether any DataType we hold references to is included in the Stack (which holds all DataType instances that directly or indirectly reference this instance, including this instance itself).If one is included, throw a BuildException created by circularReference.This implementation is appropriate only for a DataType that cannot hold other DataTypes as children. The general contract of this method is that it shouldn't do anything if DataType.checkedis true and set it to true on exit.- Overrides:
- dieOnCircularReferencein class- DataType
- Parameters:
- stk- the stack of references to check.
- p- the project to use to dereference the references.
- Throws:
- BuildException- on error.
 
 
- 
 
-