Package org.smooks.resource
Class URIResourceLocator
- java.lang.Object
-
- org.smooks.resource.URIResourceLocator
-
- All Implemented Interfaces:
ContainerResourceLocator
,ExternalResourceLocator
public class URIResourceLocator extends Object implements ContainerResourceLocator
URI
resource locator. Loads resources from aURI
i.e. "file://", "http://", "classpath:/" etc. Note, it adds support for referencing classpath based resources through aURI
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 resourceURI
has a URI scheme specified. If it has a scheme, it simply resolves the resource by creating aURL
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 areresolved
against a "base URI". This base URI can be set through thesetBaseURI(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 Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description URIResourceLocator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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).
-
-
-
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
-
-
Method Detail
-
getResource
public InputStream getResource(String configName, String defaultURI) throws SmooksException, 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 interfaceContainerResourceLocator
- 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:
IOException
- Unable to get the resource stream.SmooksException
-
getResource
public InputStream getResource(String uri) throws SmooksException, IOException
Description copied from interface:ExternalResourceLocator
Get the stream specified by the 'uri' parameter.- Specified by:
getResource
in interfaceExternalResourceLocator
- Parameters:
uri
- The location of the resource to be located.- Returns:
- The InputStream associated with the org.smooks.resource.
- Throws:
IOException
- Unable to get the org.smooks.resource stream.SmooksException
-
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 interfaceContainerResourceLocator
- Returns:
- The base URI for the locator instance.
-
getSystemBaseURI
public static URI getSystemBaseURI()
Get the system defined base URI. Defined by the system propertyBASE_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.
-
-