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.Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
URIResourceLocator() |
Modifier and Type | Method and Description |
---|---|
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).
|
public static String SCHEME_CLASSPATH
public static final String BASE_URI_SYSKEY
public static final URI DEFAULT_BASE_URI
public InputStream getResource(String configName, String defaultUri) throws IllegalArgumentException, IOException
ContainerResourceLocator
getResource
in interface ContainerResourceLocator
configName
- The container configuration entry name whose value specifies
the location of the resource.defaultUri
- The default location for the resource.IllegalArgumentException
- Illegal argument. Check the cause exception for more
information.IOException
- Unable to get the resource stream.public InputStream getResource(String uri) throws IllegalArgumentException, IOException
ExternalResourceLocator
getResource
in interface ExternalResourceLocator
uri
- The location of the resource to be located.IllegalArgumentException
- Illegal argument. Check the cause exception for more
information.IOException
- Unable to get the org.milyn.resource stream.public URI resolveURI(String uri)
uri
- URI to be resolved.public void setBaseURI(URI baseURI)
baseURI
- New baseURI.public URI getBaseURI()
getBaseURI
in interface ContainerResourceLocator
public static URI getSystemBaseURI()
BASE_URI_SYSKEY
.public static URI extractBaseURI(String resourceURI)
resourceURI
- The resource URI.Copyright © 2020. All rights reserved.