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 Details

    • CatalogResourceResolver

      public CatalogResourceResolver()
      Creates a new CatalogResourceResolver resolver with a default XMLResolverConfiguration. 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 calling setFeature(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)
      Calls XMLResolverConfiguration.getFeature(org.xmlresolver.ResolverFeature<T>) on the underlying resolver configuration.
      Specified by:
      getFeature in interface ConfigurableResourceResolver
      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)
      Calls XMLResolverConfiguration.setFeature(org.xmlresolver.ResolverFeature<T>, T) on the underlying resolver configuration.
      Specified by:
      setFeature in interface ConfigurableResourceResolver
      Type Parameters:
      T - The feature type
      Parameters:
      feature - The feature setting
      value - 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

      public void setAllowedProtocols(String protocols)
      Calls XMLResolverConfiguration.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

      public 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 interface ResourceResolver
      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 InputSource getExternalSubset(String name, String baseURI) throws SAXException, IOException
      Resolves an external subset. This method is part of the EntityResolver2 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 interface EntityResolver2
      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 interface EntityResolver2
      Parameters:
      name - The name of the entity, often null
      publicId - The public identifier of the entity, often null
      baseURI - The base URI of the entity, often null
      systemId - 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

      public InputSource resolveEntity(String publicId, 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.
      Specified by:
      resolveEntity in interface EntityResolver
      Parameters:
      publicId - The public identifier of the entity, often null
      systemId - 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 URI
      nature - The nature of the resource requested, for example, the URI of the media type
      purpose - 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.