FileDocCategorySizeDatePackage
ApacheCatalogResolver.javaAPI DocApache Ant 1.706434Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.types.resolver

ApacheCatalogResolver

public class ApacheCatalogResolver extends org.apache.xml.resolver.tools.CatalogResolver

This class extends the CatalogResolver class provided by Norman Walsh's resolver library in xml-commons. It provides the bridge between the Ant XMLCatalog datatype and the xml-commons Catalog class. XMLCatalog calls methods in this class using Reflection in order to avoid requiring the xml-commons resolver library in the path.

The {@link org.apache.tools.ant.types.resolver.ApacheCatalog ApacheCatalog} class is used to parse external catalog files, which can be in either plain text format or XML format.

For each entry found in an external catalog file, if any, an instance of {@link org.apache.tools.ant.types.ResourceLocation ResourceLocation} is created and added to the controlling XMLCatalog datatype. In this way, these entries will be included in XMLCatalog's lookup algorithm. See XMLCatalog.java for more details.

see
org.apache.tools.ant.types.XMLCatalog.CatalogResolver
see
org.apache.xml.resolver.CatalogManager
since
Ant 1.6

Fields Summary
private org.apache.tools.ant.types.XMLCatalog
xmlCatalog
The XMLCatalog object to callback.
Constructors Summary
Methods Summary
public voidaddPublicEntry(java.lang.String publicid, java.lang.String systemid, java.net.URL base)

Add a PUBLIC catalog entry to the controlling XMLCatalog instance. ApacheCatalog calls this for each PUBLIC entry found in an external catalog file.

param
publicid The public ID of the resource
param
systemid The system ID (aka location) of the resource
param
base The base URL of the resource. If the systemid specifies a relative URL/pathname, it is resolved using the base. The default base for an external catalog file is the directory in which the catalog is located.


        ResourceLocation dtd = new ResourceLocation();
        dtd.setBase(base);
        dtd.setPublicId(publicid);
        dtd.setLocation(systemid);

        xmlCatalog.addDTD(dtd);
    
public voidaddURIEntry(java.lang.String uri, java.lang.String altURI, java.net.URL base)

Add a URI catalog entry to the controlling XMLCatalog instance. ApacheCatalog calls this for each URI entry found in an external catalog file.

param
uri The URI of the resource
param
altURI The URI to which the resource should be mapped (aka the location)
param
base The base URL of the resource. If the altURI specifies a relative URL/pathname, it is resolved using the base. The default base for an external catalog file is the directory in which the catalog is located.


        ResourceLocation entity = new ResourceLocation();
        entity.setBase(base);
        entity.setPublicId(uri);
        entity.setLocation(altURI);

        xmlCatalog.addEntity(entity);
    
public voidparseCatalog(java.lang.String file)
XMLCatalog calls this to add an external catalog file for each file within a <catalogfiles> fileset.

param
file the external catalog file.


        Catalog catalog = getCatalog();
        if (!(catalog instanceof ApacheCatalog)) {
            throw new BuildException("Wrong catalog type found: " + catalog.getClass().getName());
        }
        ApacheCatalog apacheCatalog = (ApacheCatalog) catalog;

        // Pass in reference to ourselves so we can be called back.
        apacheCatalog.setResolver(this);

        try {
            apacheCatalog.parseCatalog(file);
        } catch (MalformedURLException ex) {
            throw new BuildException(ex);
        } catch (IOException ex) {
            throw new BuildException(ex);
        }
    
public voidsetXMLCatalog(org.apache.tools.ant.types.XMLCatalog xmlCatalog)
Set the XMLCatalog object to callback.

param
xmlCatalog the XMLCatalog to use.


     
        //
        // If you don't do this, you get all sorts of annoying
        // warnings about a missing properties file.  However, it
        // seems to work just fine with default values.  Ultimately,
        // we should probably include a "CatalogManager.properties"
        // file in the ant jarfile with some default property
        // settings.  See CatalogManager.java for more details.
        //
        CatalogManager.getStaticManager().setIgnoreMissingProperties(true);

        //
        // Make sure CatalogResolver instantiates ApacheCatalog,
        // rather than a plain Catalog
        //
        System.getProperties().put("xml.catalog.className",
                                   ApacheCatalog.class.getName());

        CatalogManager.getStaticManager().setUseStaticCatalog(false);

        // debug
        // CatalogManager.getStaticManager().setVerbosity(4);
    
        this.xmlCatalog = xmlCatalog;