Class URIResourceLocator

  • All Implemented Interfaces:
    ContainerResourceLocator, ExternalResourceLocator

    public class URIResourceLocator
    extends Object
    implements ContainerResourceLocator
    URI resource locator.

    Loads resources from a URI i.e. "file://", "http://", "classpath:/" etc.

    Note, it adds support for referencing classpath based resources through a URI e.g. "classpath:/org/smooks/x/my-resource.xml" references a "/org/smooks/x/my-resource.xml" resource on the classpath.

    This class resolves resources based on whether or not the requested resource URI has a URI scheme specified. If it has a scheme, it simply resolves the resource by creating a URL instance from the URI and opening a stream on that URL. If the URI doesn't have a scheme, this class will attempt to resolve the resource against the local filesystem and classpath (in that order). In all cases (scheme or no scheme), the resource URI is first resolved against base URI, with the resulting URI being the one that's used.

    As already stated, all resource URIs are resolved against a "base URI". This base URI can be set through the setBaseURI(java.net.URI) method, or via the System property "org.smooks.resource.baseuri". The default base URI is simply "./", which has no effect on the input URI when resolved against it.

    Author:
    tfennelly
    • Field Detail

      • SCHEME_CLASSPATH

        public static final String SCHEME_CLASSPATH
        Scheme name for classpath based resources.
        See Also:
        Constant Field Values
      • BASE_URI_SYSKEY

        public static final String BASE_URI_SYSKEY
        System property key for the base URI. Defaults to "./".
        See Also:
        Constant Field Values
      • DEFAULT_BASE_URI

        public static final URI DEFAULT_BASE_URI
    • Constructor Detail

      • URIResourceLocator

        public URIResourceLocator()
    • Method Detail

      • resolveURI

        public URI resolveURI​(String uri)
        Resolve the supplied uri against the baseURI.

        Only resolved against the base URI if 'uri' is not absolute.

        Parameters:
        uri - URI to be resolved.
        Returns:
        The resolved URI.
      • setBaseURI

        public void setBaseURI​(URI baseURI)
        Allows overriding of the baseURI (current dir).
        Parameters:
        baseURI - New baseURI.
      • getBaseURI

        public URI getBaseURI()
        Get the base URI for this locator instance.
        Specified by:
        getBaseURI in interface ContainerResourceLocator
        Returns:
        The base URI for the locator instance.
      • getSystemBaseURI

        public static URI getSystemBaseURI()
        Get the system defined base URI.

        Defined by the system property BASE_URI_SYSKEY.

        Returns:
        System base URI.
      • extractBaseURI

        public static URI extractBaseURI​(String resourceURI)
        Extract the base URI from the supplied resource URI.
        Parameters:
        resourceURI - The resource URI.
        Returns:
        The base URI for the supplied resource URI.
      • extractBaseURI

        public static URI extractBaseURI​(URI resourceURI)
        Extract the base URI from the supplied resource URI.
        Parameters:
        resourceURI - The resource URI.
        Returns:
        The base URI for the supplied resource URI.