org.openbp.common.resource
Class ResourceMgr

java.lang.Object
  extended by org.openbp.common.resource.ResourceMgr

public class ResourceMgr
extends java.lang.Object

The resource manager class provides a way of accessing resources bundled with the application.

Author:
Heiko Erhardt

Field Summary
static int CLASSPATH_RESOURCE_PROVIDER_PRIO
          Assign a low priority for the default classpath resource provider (100)
static int ROOTDIR_RESOURCE_PROVIDER_PRIO
          Assign a medium priority for the default root dir resource provider (50)
static int USERHOMEDIR_RESOURCE_PROVIDER_PRIO
          Assign a high priority for the user's HOME dir resource provider (25)
 
Constructor Summary
ResourceMgr()
          Default constructor.
ResourceMgr(org.springframework.core.io.ResourceLoader resourceLoader)
          Value constructor.
 
Method Summary
 org.springframework.core.io.Resource[] findResources(java.lang.String resourceLocation)
          Finds resources according to the given resource location pattern, preferably in the class path.
static ResourceMgr getDefaultInstance()
          Gets the singleton instance of this class.
 org.springframework.core.io.Resource getResource(java.lang.String resourceLocation)
          Gets the specified resource.
 org.springframework.core.io.ResourceLoader getResourceLoader()
          Gets the resource loader.
 ResourceResolver getResourceResolver()
          Gets the value of the resourceResolver property.
 java.net.URL getURL(java.lang.String resourceLocation)
          Returns the URL of the provided resource.
 byte[] loadByteResource(org.springframework.core.io.Resource res)
          Loads the specified resource as array of bytes.
 byte[] loadByteResource(java.lang.String resourceLocation)
          Loads the specified resource as array of bytes.
 java.io.InputStream openResource(java.lang.String resourceLocation)
          Opens an input stream to the specified resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USERHOMEDIR_RESOURCE_PROVIDER_PRIO

public static final int USERHOMEDIR_RESOURCE_PROVIDER_PRIO
Assign a high priority for the user's HOME dir resource provider (25)

See Also:
Constant Field Values

ROOTDIR_RESOURCE_PROVIDER_PRIO

public static final int ROOTDIR_RESOURCE_PROVIDER_PRIO
Assign a medium priority for the default root dir resource provider (50)

See Also:
Constant Field Values

CLASSPATH_RESOURCE_PROVIDER_PRIO

public static final int CLASSPATH_RESOURCE_PROVIDER_PRIO
Assign a low priority for the default classpath resource provider (100)

See Also:
Constant Field Values
Constructor Detail

ResourceMgr

public ResourceMgr()
Default constructor.


ResourceMgr

public ResourceMgr(org.springframework.core.io.ResourceLoader resourceLoader)
Value constructor.

Parameters:
resourceLoader - Resource loader
Method Detail

getDefaultInstance

public static ResourceMgr getDefaultInstance()
Gets the singleton instance of this class.


getResource

public org.springframework.core.io.Resource getResource(java.lang.String resourceLocation)
Gets the specified resource. Merely constructs a resource object from the resource name.

Parameters:
resourceLocation - Resource location; this can be a resource name that is expected to be resolved by the underlying resource loader (e. g. "conf/MyResource.xml" that would be resolved to a component of a Jar file by a classpath-based loader) or an explicit resource url specification (e. g. "classpath:conf/MyResource.xml"). For details on this format, see the Spring reference guide.
Returns:
The resource; use Resource.exists to check if the resource really exists
Throws:
ResourceMgrException - If no such resource could be found

openResource

public java.io.InputStream openResource(java.lang.String resourceLocation)
                                 throws ResourceMgrException
Opens an input stream to the specified resource.

Parameters:
resourceLocation - Resource location
Returns:
The input stream
Throws:
ResourceMgrException - If the resource does not exist
ResourceMgrException - If no such resoure could be found

loadByteResource

public byte[] loadByteResource(java.lang.String resourceLocation)
                        throws ResourceMgrException
Loads the specified resource as array of bytes.

Parameters:
resourceLocation - Resource location
Returns:
The byte array that makes up the content of the resource
Throws:
ResourceMgrException - On read error or if the resource does not exist

loadByteResource

public byte[] loadByteResource(org.springframework.core.io.Resource res)
                        throws ResourceMgrException
Loads the specified resource as array of bytes.

Parameters:
res - Resource
Returns:
The byte array that makes up the content of the resource
Throws:
ResourceMgrException - On read error or if the resource does not exist

findResources

public org.springframework.core.io.Resource[] findResources(java.lang.String resourceLocation)
                                                     throws ResourceMgrException
Finds resources according to the given resource location pattern, preferably in the class path.

Parameters:
resourceLocation - Resource location pattern
This may specify either a file, jar url or classpath resource location, optionally using an ant-style search pattern. Examples:
"classpath*:META-INF/*-beans.xml" Will find all resources that end with "-beans.xml" in all class path entries (classes dirs or jar files)
"file:C:/Programs/MyProg/conf/*.xml" Will find all XML resources in the configuration directory of a program.
If no URL type has been prepended, "classpath*:" is assumed.
Returns:
The array of resources that has been found
Throws:
ResourceMgrException - On I/O errors

getURL

public java.net.URL getURL(java.lang.String resourceLocation)
Returns the URL of the provided resource. Merely constructs a resource object from the resource name.

Parameters:
resourceLocation - Resource location; this can be a resource name that is expected to be resolved by the underlying resource loader (e. g. "conf/MyResource.xml" that would be resolved to a component of a Jar file by a classpath-based loader) or an explicit resource url specification (e. g. "classpath:conf/MyResource.xml"). For details on this format, see the Spring reference guide.
Returns:
url to the specified filename

getResourceLoader

public org.springframework.core.io.ResourceLoader getResourceLoader()
Gets the resource loader.


getResourceResolver

public ResourceResolver getResourceResolver()
Gets the value of the resourceResolver property.

Returns:
The property value


Copyright © 2011. All Rights Reserved.