Package net.sf.saxon.lib
Class CatalogResourceResolver
java.lang.Object
net.sf.saxon.lib.CatalogResourceResolver
- All Implemented Interfaces:
ConfigurableResourceResolver
,ResourceResolver
,EntityResolver
,EntityResolver2
public class CatalogResourceResolver
extends Object
implements ResourceResolver, ConfigurableResourceResolver, EntityResolver, EntityResolver2
The standard implementation of the
ResourceResolver
interface for use with catalogs.- Since:
- 11
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptiongetExternalSubset
(String name, 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.resolve
(ResourceRequest request) Resolve a resource request.resolveEntity
(String publicId, String systemId) Resolves an entity.resolveEntity
(String name, String publicId, String baseURI, String systemId) Resolves an entity.resolveNamespace
(String uri, String nature, String purpose) Resolves a URI that is known to be a namespace URI.void
setAllowedProtocols
(String protocols) CallsXMLResolverConfiguration.setFeature(org.xmlresolver.ResolverFeature<T>, T)
on the underlying resolver configuration to set the allowed protocols.<T> void
setFeature
(org.xmlresolver.ResolverFeature<T> feature, T value) CallsXMLResolverConfiguration.setFeature(org.xmlresolver.ResolverFeature<T>, T)
on the underlying resolver configuration.
-
Constructor Details
-
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 Details
-
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:
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.
-
setAllowedProtocols
CallsXMLResolverConfiguration.setFeature(org.xmlresolver.ResolverFeature<T>, T)
on the underlying resolver configuration to set the allowed protocols.Having a special method for this purpose on the CatalogResourceResolver allows us to route around an API inconsistency between the Java implementation of the resolver and the C# implementation.
- Parameters:
protocols
- The allowed protocols.
-
resolve
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
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 interfaceEntityResolver2
- Parameters:
name
- The doctype name.baseURI
- The base URI.- Returns:
- The external subset, or null if it could not be found.
- Throws:
SAXException
- If an error occurs during the attempt to resolve the external subset.IOException
- If it isn't possible to create the input source or if the base URI is invalid.
-
resolveEntity
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, 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 interfaceEntityResolver2
- 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:
SAXException
- If an error occurs during the attempt to resolve the external subset.IOException
- If it isn't possible to create the input source or if the base URI is invalid.
-
resolveEntity
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 interfaceEntityResolver
- 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:
SAXException
- If an error occurs during the attempt to resolve the external subset.IOException
- If it isn't possible to create the input source or if the base URI is invalid.
-
resolveNamespace
public Source resolveNamespace(String uri, String nature, String purpose) throws 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:
TransformerException
- if an error occurs during the attempt to resolve the URI.
-