Class XmlLoader
- java.lang.Object
-
- org.xmlresolver.loaders.XmlLoader
-
- All Implemented Interfaces:
CatalogLoader
public class XmlLoader extends java.lang.Object implements CatalogLoader
An XML catalog loader.This loader understands the XML Catalogs 1.1 specification XML catalog syntax.
-
-
Constructor Summary
Constructors Constructor Description XmlLoader(ResolverConfiguration config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete 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.static Resolver
getLoaderResolver()
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.
-
-
-
Constructor Detail
-
XmlLoader
public XmlLoader(ResolverConfiguration config)
-
-
Method Detail
-
setPreferPublic
public void setPreferPublic(boolean prefer)
Set the default "prefer public" status for this catalog.- Specified by:
setPreferPublic
in interfaceCatalogLoader
- Parameters:
prefer
- True if public identifiers are to be preferred.
-
getPreferPublic
public boolean getPreferPublic()
Return the current "prefer public" status.- Specified by:
getPreferPublic
in interfaceCatalogLoader
- Returns:
- The current "prefer public" status of this catalog loader.
-
setArchivedCatalogs
public void setArchivedCatalogs(boolean allow)
Description copied from interface:CatalogLoader
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.- Specified by:
setArchivedCatalogs
in interfaceCatalogLoader
- Parameters:
allow
- True if archived catalogs are to be allowed.
-
getArchivedCatalogs
public boolean getArchivedCatalogs()
Description copied from interface:CatalogLoader
Return whether archived catalogs are allowed.- Specified by:
getArchivedCatalogs
in interfaceCatalogLoader
- Returns:
- True if archived catalogs are allowed.
-
setEntityResolver
public void setEntityResolver(org.xml.sax.EntityResolver resolver)
Description copied from interface:CatalogLoader
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.
- Specified by:
setEntityResolver
in interfaceCatalogLoader
- Parameters:
resolver
- the resolver
-
getEntityResolver
public org.xml.sax.EntityResolver getEntityResolver()
Description copied from interface:CatalogLoader
Return the entity resolver used when loading catalogs.- Specified by:
getEntityResolver
in interfaceCatalogLoader
- Returns:
- resolver the resolver
-
getLoaderResolver
public static Resolver getLoaderResolver()
-
loadCatalog
public org.xmlresolver.catalog.entry.EntryCatalog loadCatalog(java.net.URI catalog)
Description copied from interface:CatalogLoader
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.
- Specified by:
loadCatalog
in interfaceCatalogLoader
- Parameters:
catalog
- The catalog URI.- Returns:
- The parsed catalog.
-
loadCatalog
public 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.
- Specified by:
loadCatalog
in interfaceCatalogLoader
- Parameters:
catalog
- The catalog URI.source
- The input source.- Returns:
- The parsed catalog.
-
loadCatalog
public 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.
- Specified by:
loadCatalog
in interfaceCatalogLoader
- Parameters:
catalog
- The catalog URI.producer
- The producer that delivers SAX events to the handlers.- Returns:
- The parsed catalog.
-
-