org.milyn.resource
Class URIResourceLocator

java.lang.Object
  extended by org.milyn.resource.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/milyn/x/my-resource.xml" references a "/org/milyn/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.milyn.resource.baseuri". The default base URI is simply "./", which has no effect on the input URI when resolved against it.

Author:
tfennelly

Field Summary
static String BASE_URI_SYSKEY
          System property key for the base URI.
static URI DEFAULT_BASE_URI
           
static String SCHEME_CLASSPATH
          Scheme name for classpath based resources.
 
Constructor Summary
URIResourceLocator()
           
 
Method Summary
static URI extractBaseURI(String resourceURI)
          Extract the base URI from the supplied resource URI.
static URI extractBaseURI(URI resourceURI)
          Extract the base URI from the supplied resource URI.
 URI getBaseURI()
          Get the base URI for this locator instance.
 InputStream getResource(String uri)
          Get the stream specified by the 'uri' parameter.
 InputStream getResource(String configName, String defaultUri)
          Get the resource specified by the container 'config' value.
static URI getSystemBaseURI()
          Get the system defined base URI.
 URI resolveURI(String uri)
          Resolve the supplied uri against the baseURI.
 void setBaseURI(URI baseURI)
          Allows overriding of the baseURI (current dir).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCHEME_CLASSPATH

public static String SCHEME_CLASSPATH
Scheme name for classpath based resources.


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

getResource

public InputStream getResource(String configName,
                               String defaultUri)
                        throws IllegalArgumentException,
                               IOException
Description copied from interface: ContainerResourceLocator
Get the resource specified by the container 'config' value.

If the config value isn't specified, uses the defaultLocation.

Specified by:
getResource in interface ContainerResourceLocator
Parameters:
configName - The container configuration entry name whose value specifies the location of the resource.
defaultUri - The default location for the resource.
Returns:
The InputStream associated with resource.
Throws:
IllegalArgumentException - Illegal argument. Check the cause exception for more information.
IOException - Unable to get the resource stream.

getResource

public InputStream getResource(String uri)
                        throws IllegalArgumentException,
                               IOException
Description copied from interface: ExternalResourceLocator
Get the stream specified by the 'uri' parameter.

Specified by:
getResource in interface ExternalResourceLocator
Parameters:
uri - The location of the resource to be located.
Returns:
The InputStream associated with the org.milyn.resource.
Throws:
IllegalArgumentException - Illegal argument. Check the cause exception for more information.
IOException - Unable to get the org.milyn.resource stream.

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.


Copyright © 2018. All rights reserved.