Package net.sf.saxon.lib
Class CatalogResourceResolver
- java.lang.Object
-
- net.sf.saxon.lib.CatalogResourceResolver
-
- All Implemented Interfaces:
ConfigurableResourceResolver
,ResourceResolver
,org.xml.sax.EntityResolver
,org.xml.sax.ext.EntityResolver2
public class CatalogResourceResolver extends java.lang.Object implements ResourceResolver, ConfigurableResourceResolver, org.xml.sax.EntityResolver, org.xml.sax.ext.EntityResolver2
The standard implementation of theResourceResolver
interface for use with catalogs.- Since:
- 11
-
-
Constructor Summary
Constructors Constructor Description CatalogResourceResolver()
Creates a new CatalogResourceResolver resolver with a defaultXMLResolverConfiguration
.CatalogResourceResolver(org.xmlresolver.Resolver resolver)
Creates a new CatlaogResourceResolver using the provided resolver as its underlying resolver.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.xml.sax.InputSource
getExternalSubset(java.lang.String name, java.lang.String baseURI)
Resolves an external subset.<T> T
getFeature(org.xmlresolver.ResolverFeature<T> feature)
CallsXMLResolverConfiguration.getFeature(org.xmlresolver.ResolverFeature<T>)
on the underlying resolver configuration.javax.xml.transform.Source
resolve(ResourceRequest request)
Resolve a resource request.org.xml.sax.InputSource
resolveEntity(java.lang.String publicId, java.lang.String systemId)
Resolves an entity.org.xml.sax.InputSource
resolveEntity(java.lang.String name, java.lang.String publicId, java.lang.String baseURI, java.lang.String systemId)
Resolves an entity.javax.xml.transform.Source
resolveNamespace(java.lang.String uri, java.lang.String nature, java.lang.String purpose)
Resolves a URI that is known to be a namespace URI.<T> void
setFeature(org.xmlresolver.ResolverFeature<T> feature, T value)
CallsXMLResolverConfiguration.setFeature(org.xmlresolver.ResolverFeature<T>, T)
on the underlying resolver configuration.
-
-
-
Constructor Detail
-
CatalogResourceResolver
public CatalogResourceResolver()
Creates a new CatalogResourceResolver resolver with a defaultXMLResolverConfiguration
. This default configuration will read a configuration file from the class path and interrogate system properties to determine its initial configuration. The configuration can be updated by callingsetFeature(org.xmlresolver.ResolverFeature<T>, T)
. Alternatively, the constructor can be passed an existing resolver.
-
CatalogResourceResolver
public CatalogResourceResolver(org.xmlresolver.Resolver resolver)
Creates a new CatlaogResourceResolver using the provided resolver as its underlying resolver.- Parameters:
resolver
- The resolver to wrap.
-
-
Method Detail
-
getFeature
public <T> T getFeature(org.xmlresolver.ResolverFeature<T> feature)
CallsXMLResolverConfiguration.getFeature(org.xmlresolver.ResolverFeature<T>)
on the underlying resolver configuration.- Specified by:
getFeature
in interfaceConfigurableResourceResolver
- Type Parameters:
T
- The feature type- Parameters:
feature
- The feature setting- Returns:
- The value for the specified feature.
-
setFeature
public <T> void setFeature(org.xmlresolver.ResolverFeature<T> feature, T value)
CallsXMLResolverConfiguration.setFeature(org.xmlresolver.ResolverFeature<T>, T)
on the underlying resolver configuration.- Specified by:
setFeature
in interfaceConfigurableResourceResolver
- Type Parameters:
T
- The feature type- Parameters:
feature
- The feature settingvalue
- The desired value for that feature- Throws:
java.lang.NullPointerException
- if the underlying resolver is null. Some features will also throw this exception if the value provided is null and that's not a meaningful feature value.
-
resolve
public javax.xml.transform.Source resolve(ResourceRequest request) throws XPathException
Resolve a resource request. If catalog resolution fails and a fallback URI resolver has been chained, the fallback resolver will be attempted.- Specified by:
resolve
in interfaceResourceResolver
- Parameters:
request
- details of the resource request- Returns:
- The resolved resource, or null if it could not be resolved.
- Throws:
XPathException
- if an error occurs during the attempt to resolve the URI.
-
getExternalSubset
public org.xml.sax.InputSource getExternalSubset(java.lang.String name, java.lang.String baseURI) throws org.xml.sax.SAXException, java.io.IOException
Resolves an external subset. This method is part of theEntityResolver2
interface. The resolver will attempt to find the external subset through the catalog resolver. If catalog resolution fails and a fallback EntityResolver2 resolver has been chained, the fallback resolver will be attempted.- Specified by:
getExternalSubset
in interfaceorg.xml.sax.ext.EntityResolver2
- Parameters:
name
- The doctype name.baseURI
- The base URI.- Returns:
- The external subset, or null if it could not be found.
- Throws:
org.xml.sax.SAXException
- If an error occurs during the attempt to resolve the external subset.java.io.IOException
- If it isn't possible to create the input source or if the base URI is invalid.
-
resolveEntity
public org.xml.sax.InputSource resolveEntity(java.lang.String name, java.lang.String publicId, java.lang.String baseURI, java.lang.String systemId) throws org.xml.sax.SAXException, java.io.IOException
Resolves an entity. This method attempts to resolve the entity with the catalog resolver. If catalog resolution fails and a fallback EntityResolver2 resolver has been chained, the fallback resolver will be attempted. If that fails and a further EntityResolver has been chained, that fallback will also be attempted. Depending on whether various aspects of the entity are provided (public and system identifiers, the name and baseURI, etc.), different aspects of the catalog will be queried. Not all parsers provide all of these parameters. It's common for the name and baseURI to be null, for example. If the parser doesn't provide them, then the catalog resolver will not be able to resolve with them.- Specified by:
resolveEntity
in interfaceorg.xml.sax.ext.EntityResolver2
- Parameters:
name
- The name of the entity, often nullpublicId
- The public identifier of the entity, often nullbaseURI
- The base URI of the entity, often nullsystemId
- The system identifier of the entity- Returns:
- The entity, or null if it could not be found.
- Throws:
org.xml.sax.SAXException
- If an error occurs during the attempt to resolve the external subset.java.io.IOException
- If it isn't possible to create the input source or if the base URI is invalid.
-
resolveEntity
public org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException, java.io.IOException
Resolves an entity. This method attempts to resolve the entity with the catalog resolver. If catalog resolution fails and a fallback EntityResolver2 resolver has been chained, the fallback resolver will be attempted. If that fails and a further EntityResolver has been chained, that fallback will also be attempted.- Specified by:
resolveEntity
in interfaceorg.xml.sax.EntityResolver
- Parameters:
publicId
- The public identifier of the entity, often nullsystemId
- The system identifier of the entity- Returns:
- The entity, or null if it could not be found.
- Throws:
org.xml.sax.SAXException
- If an error occurs during the attempt to resolve the external subset.java.io.IOException
- If it isn't possible to create the input source or if the base URI is invalid.
-
resolveNamespace
public javax.xml.transform.Source resolveNamespace(java.lang.String uri, java.lang.String nature, java.lang.String purpose) throws javax.xml.transform.TransformerException
Resolves a URI that is known to be a namespace URI. This intereface allows a resolver to request a particular kind of resource (one with a particular nature, possibly for a particular purpose) for a URI. The URI is usually the namespace URI. Namespace URIs are often not usefully resolvable on the web, but a catalog resolver can still offer resolution. If neither a nature or a purpose are provided, or if using them produces no results, this method simply attempts to lookup the URI in the catalog. If that also fails, and if a fallback namespace resolver has been chained, resolution will be attempted with the fallback resolver.- Parameters:
uri
- The namespace URInature
- The nature of the resource requested, for example, the URI of the media typepurpose
- The purpose of the request, for example "validation"- Returns:
- The resource or null if it could not be found.
- Throws:
javax.xml.transform.TransformerException
- if an error occurs during the attempt to resolve the URI.
-
-