Class StandardURIResolver

java.lang.Object
net.sf.saxon.lib.StandardURIResolver
All Implemented Interfaces:
URIResolver, NonDelegatingURIResolver

public class StandardURIResolver extends Object implements NonDelegatingURIResolver
This class provides the service of converting a URI into an Source. It is used to get stylesheet modules referenced by xsl:import and xsl:include, and source documents referenced by the document() function. The standard version handles anything that the java URL class will handle, plus the classpath URI scheme defined in the Spring framework, and the data URI scheme defined in RFC 2397.

You can write a subclass to handle other kinds of URI, for example references to data in a database, or to handle standard URIs in non-standard ways, for example by supplying authentication credentials.

  • Constructor Details

    • StandardURIResolver

      public StandardURIResolver()
      Create a StandardURIResolver, with no reference to a Configuration. Note: it is preferable but not essential to supply a Configuration, either in the constructor or in a subsequent call of setConfiguration()
    • StandardURIResolver

      public StandardURIResolver(Configuration config)
      Create a StandardURIResolver, with a reference to a Configuration
      Parameters:
      config - The Configuration object. May be null. This is used (if available) to get a reusable SAX Parser for a source XML document
  • Method Details

    • setRecognizeQueryParameters

      public void setRecognizeQueryParameters(boolean recognize)
      Indicate that query parameters (such as validation=strict) are to be recognized
      Parameters:
      recognize - Set to true if query parameters in the URI are to be recognized and acted upon. The default (for compatibility and interoperability reasons) is false.
    • queryParametersAreRecognized

      public boolean queryParametersAreRecognized()
      Determine whether query parameters (such as validation=strict) are to be recognized
      Returns:
      true if query parameters are recognized and interpreted by Saxon.
    • setAllowedUriTest

      public void setAllowedUriTest(Predicate<URI> test)
      Set a Predicate that is applied to a URI to determine whether the resolver should accept it.

      It is possible to set the default predicate by means of the configuration property Feature.ALLOWED_PROTOCOLS.

      Parameters:
      test - the predicate to be applied to the absolute URI.
    • getPlatform

      protected Platform getPlatform()
      Get the relevant platform
      Returns:
      the platform
    • setConfiguration

      public void setConfiguration(Configuration config)
      Set the configuration
      Parameters:
      config - the configuration
    • getConfiguration

      public Configuration getConfiguration()
      Get the configuration if available
      Returns:
      the configuration
    • resolve

      public Source resolve(String href, String base) throws XPathException
      Resolve a URI
      Specified by:
      resolve in interface URIResolver
      Parameters:
      href - The relative or absolute URI. May be an empty string. May contain a fragment identifier starting with "#", which must be the value of an ID attribute in the referenced XML document.
      base - The base URI that should be used. May be null if uri is absolute.
      Returns:
      a Source object representing an XML document
      Throws:
      XPathException
    • setSAXInputSource

      protected void setSAXInputSource(SAXSource source, String uriString)
      Set the InputSource part of the returned SAXSource. This is done in a separate method to allow subclassing. The default implementation checks for the (Spring-defined) "classpath" URI scheme, and if this is in use, it attempts to locate the resource on the classpath and set the supplied SAXSource to use the corresponding input stream. In other cases it simply places the URI in the InputSource, allowing the XML parser to take responsibility for the dereferencing. A subclass may choose to dereference the URI at this point and place an InputStream in the SAXSource.
      Parameters:
      source - the SAXSource being initialized
      uriString - the absolute (resolved) URI to be used