Interface CatalogLoader

  • All Known Implementing Classes:
    ValidatingXmlLoader, XmlLoader

    public interface CatalogLoader
    The catalog loader interface.

    The loader interface provides two entry points to load catalogs, one with a URI and one with both a URI and an input source (in case the catalog comes from some source that cannot be directly accessed by a URI, or the URI is unknown).

    The catalog specification mandates that it must be possible to specify the default "prefer public" behavior of any catalog, so that is supported as well.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean getArchivedCatalogs()
      Return whether archived catalogs are allowed.
      org.xml.sax.EntityResolver getEntityResolver()
      Return the entity resolver used when loading catalogs.
      boolean getPreferPublic()
      Return the current "prefer public" status.
      org.xmlresolver.catalog.entry.EntryCatalog loadCatalog​(java.net.URI catalog)
      Load the specified catalog.
      org.xmlresolver.catalog.entry.EntryCatalog loadCatalog​(java.net.URI catalog, org.xml.sax.InputSource source)
      Load the specified catalog from a given input source.
      org.xmlresolver.catalog.entry.EntryCatalog loadCatalog​(java.net.URI catalog, org.xmlresolver.utils.SaxProducer producer)
      Load the specified catalog by sending events to the ContentHandler.
      void setArchivedCatalogs​(boolean allow)
      Allow archived catalogs on the catalog path.
      void setEntityResolver​(org.xml.sax.EntityResolver resolver)
      Set the entity resolver used when loading catalogs.
      void setPreferPublic​(boolean prefer)
      Set the default "prefer public" status for this catalog.
    • Method Detail

      • loadCatalog

        org.xmlresolver.catalog.entry.EntryCatalog loadCatalog​(java.net.URI catalog)
        Load the specified catalog.

        The manager maintains a set of the catalogs that it has loaded. If an attempt is made to load a catalog twice, the previously loaded catalog is returned.

        Parameters:
        catalog - The catalog URI.
        Returns:
        The parsed catalog.
      • loadCatalog

        org.xmlresolver.catalog.entry.EntryCatalog loadCatalog​(java.net.URI catalog,
                                                               org.xml.sax.InputSource source)
        Load the specified catalog from a given input source.

        This method exists so that a catalog can be loaded even if it doesn't have a URI that can be dereferenced. It must still have a URI.

        The manager maintains a set of the catalogs that it has loaded. If an attempt is made to load a catalog twice, the previously loaded catalog is returned.

        Parameters:
        catalog - The catalog URI.
        source - The input source.
        Returns:
        The parsed catalog.
      • loadCatalog

        org.xmlresolver.catalog.entry.EntryCatalog loadCatalog​(java.net.URI catalog,
                                                               org.xmlresolver.utils.SaxProducer producer)
        Load the specified catalog by sending events to the ContentHandler.

        This method exists so that a catalog can be loaded even if it doesn't have a URI that can be dereferenced. It must still have a URI because relative URIs in the catalog will be resolved against it. (If all of the URIs in the catalog are absolute, the catalog URI is irrelevant.)

        To use this approach, you must both add the catalog to the resolver and then explicitly load the catalog:

        For example:

           XMLResolverConfiguration config = new XMLResolverConfiguration();
           CatalogManager manager = config.getFeature(ResolverFeature.CATALOG_MANAGER);
        
           URI caturi = URI.create("https://example.com/absolute/uri/catalog.xml");
           config.addCatalog(caturi.toString());
        
           SaxProducer producer = new CatalogProducer();
           manager.loadCatalog(caturi, producer);

        If you don't add the catalog to the resolver, it won't be used. If you don't explicitly load the catalog, the resolver will try to dereference the URI the first time it needs the catalog. The manager maintains a set of the catalogs that it has loaded so it won't attempt to load a catalog twice, the previously loaded catalog will be used.

        Parameters:
        catalog - The catalog URI.
        producer - The producer that delivers SAX events to the handlers.
        Returns:
        The parsed catalog.
      • setPreferPublic

        void setPreferPublic​(boolean prefer)
        Set the default "prefer public" status for this catalog.
        Parameters:
        prefer - True if public identifiers are to be preferred.
      • getPreferPublic

        boolean getPreferPublic()
        Return the current "prefer public" status.
        Returns:
        The current "prefer public" status of this catalog loader.
      • setArchivedCatalogs

        void setArchivedCatalogs​(boolean allow)
        Allow archived catalogs on the catalog path.

        If allowed, then ZIP files may be specified as catalogs. The loader will return the catalog associated with the /catalog.xml or /org/xmlresolver/catalog.xml within the ZIP file.

        Parameters:
        allow - True if archived catalogs are to be allowed.
      • getArchivedCatalogs

        boolean getArchivedCatalogs()
        Return whether archived catalogs are allowed.
        Returns:
        True if archived catalogs are allowed.
      • setEntityResolver

        void setEntityResolver​(org.xml.sax.EntityResolver resolver)
        Set the entity resolver used when loading catalogs.

        When the resolver loads a catalog, it can't use itself as the entity resolver because that would cause an infinite loop. Instead, it uses this resolver. The only entities that this resolver needs to be able to handle are the ones used in document type declarations for the catalogs themselves.

        Parameters:
        resolver - the resolver
      • getEntityResolver

        org.xml.sax.EntityResolver getEntityResolver()
        Return the entity resolver used when loading catalogs.
        Returns:
        resolver the resolver