org.openbp.common.rc
Class ResourceCollection

java.lang.Object
  extended by org.openbp.common.rc.ResourceCollection

public class ResourceCollection
extends java.lang.Object

Implements the ResourceCollection interface.

Author:
Andreas Putz

Field Summary
static java.lang.String ATTRIBUTE_GROUP_NAME
          XML attribute for the group tag getting the name
static java.lang.String ATTRIBUTE_IMPORT_CONTAINER
          XML attribute for the import tag to get the container of the import resource (optional)
static java.lang.String ATTRIBUTE_IMPORT_RESOURCE
          XML attribute for the import tag to get the import resource (required)
static java.lang.String ATTRIBUTE_PRELOAD
          XML attribute for the root tag for preloading resource item generally
protected  java.lang.String containerName
          Resource container name
protected  ResourceCollection parentResourceCollection
          Parent resource
protected static java.lang.String RESOURCE_EXTENSION
          Property file extension
static java.lang.String TAG_GROUP
          XML tag property is a resource group
static java.lang.String TAG_IMPORT
          XML tag property is a import of another resource
static java.lang.String TAG_RESOURCE
          XML tag properties is the document root
static java.lang.String TAG_RESOURCE_ITEM
          XML tag property is a resource item
 
Constructor Summary
ResourceCollection(java.lang.String containerName, java.lang.String resourceName, java.util.Locale locale, ResourceCollectionMgr resourceCollectionMgr, java.io.InputStream stream)
          Constructor.
 
Method Summary
 void addImport(ResourceCollection importedResourceCollection)
          Add a imported resource to this resource.
 void addResourceItem(ResourceItem item)
          Adds the resource item to the resource.
protected  ResourceItem createResourceItem(org.w3c.dom.Element resourceItemNode, java.lang.String group, boolean preload)
          Create a resource object.
 java.lang.String getContainerName()
          Gets the resource container name.
 java.lang.String getErrorName()
          Returns a string that identifies the resource in error messages.
 java.util.Iterator getKeys()
          Get all resource keys.
 java.util.Locale getLocale()
          Gets the locale.
 java.lang.String getName()
          Gets the name of the resource.
 java.lang.Object getOptionalObject(java.lang.String resourceItemName)
          Gets a resource value.
 java.lang.Object getOptionalObject(java.lang.String resourceItemName, java.lang.Object dflt)
          Gets a resource value.
 java.lang.String getOptionalString(java.lang.String resourceItemName)
          Gets a resource value as string.
 java.lang.String getOptionalString(java.lang.String resourceItemName, java.lang.String dflt)
          Gets a resource value as string.
 ResourceCollection getParentResource()
          Gets the parent resource.
 java.lang.Object getRequiredObject(java.lang.String resourceItemName)
          Gets a resource value.
 java.lang.String getRequiredString(java.lang.String resourceItemName)
          Gets a resource value as string.
 ResourceCollectionMgr getResourceCollectionMgr()
          Gets the locale resource manager.
 ResourceItem getResourceItem(java.lang.String resourceItemName)
          Gets the resource item specified by its name.
 java.lang.String getResourceItemPath(java.lang.String relativePath)
          Determines the file path of a file within a container for error message output.
protected  java.lang.Object getResourceObject(java.lang.String resourceItemName)
          Get an object from a resource.
 java.lang.String getResourcePath()
          Gets the path of the resource folder this resource resides in.
protected  void parseResource(org.w3c.dom.Element parentNode, java.lang.String groupPath, boolean preload)
          Parses the DOM tree of a resource and adds all resource items it finds.
protected  void readFromInput(java.io.InputStream stream)
          Reads the DOM tree of a resource and adds all resource items it finds.
 byte[] readResourceItem(java.lang.String relativePath)
          Reads the (byte data) content of a resource collection item.
 void setParentResource(ResourceCollection parentResourceCollection)
          Sets the parent resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_EXTENSION

protected static final java.lang.String RESOURCE_EXTENSION
Property file extension

See Also:
Constant Field Values

TAG_RESOURCE

public static final java.lang.String TAG_RESOURCE
XML tag properties is the document root

See Also:
Constant Field Values

ATTRIBUTE_PRELOAD

public static final java.lang.String ATTRIBUTE_PRELOAD
XML attribute for the root tag for preloading resource item generally

See Also:
Constant Field Values

TAG_RESOURCE_ITEM

public static final java.lang.String TAG_RESOURCE_ITEM
XML tag property is a resource item

See Also:
Constant Field Values

TAG_IMPORT

public static final java.lang.String TAG_IMPORT
XML tag property is a import of another resource

See Also:
Constant Field Values

ATTRIBUTE_IMPORT_RESOURCE

public static final java.lang.String ATTRIBUTE_IMPORT_RESOURCE
XML attribute for the import tag to get the import resource (required)

See Also:
Constant Field Values

ATTRIBUTE_IMPORT_CONTAINER

public static final java.lang.String ATTRIBUTE_IMPORT_CONTAINER
XML attribute for the import tag to get the container of the import resource (optional)

See Also:
Constant Field Values

TAG_GROUP

public static final java.lang.String TAG_GROUP
XML tag property is a resource group

See Also:
Constant Field Values

ATTRIBUTE_GROUP_NAME

public static final java.lang.String ATTRIBUTE_GROUP_NAME
XML attribute for the group tag getting the name

See Also:
Constant Field Values

containerName

protected java.lang.String containerName
Resource container name


parentResourceCollection

protected ResourceCollection parentResourceCollection
Parent resource

Constructor Detail

ResourceCollection

public ResourceCollection(java.lang.String containerName,
                          java.lang.String resourceName,
                          java.util.Locale locale,
                          ResourceCollectionMgr resourceCollectionMgr,
                          java.io.InputStream stream)
                   throws java.io.IOException,
                          org.xml.sax.SAXException
Constructor. Determines the container and the parent resource.

Parameters:
containerName - Resource container name or null
resourceName - Name of the resource
locale - Locale
resourceCollectionMgr - Resource mgr
stream - Input stream of the resource XML file
Throws:
java.io.IOException - On i/o error
org.xml.sax.SAXException - On XML error
Method Detail

getResourcePath

public java.lang.String getResourcePath()
Gets the path of the resource folder this resource resides in.


getName

public java.lang.String getName()
Gets the name of the resource.

Returns:
Resource name

getContainerName

public java.lang.String getContainerName()
Gets the resource container name.


getLocale

public java.util.Locale getLocale()
Gets the locale.


getParentResource

public ResourceCollection getParentResource()
Gets the parent resource.


setParentResource

public void setParentResource(ResourceCollection parentResourceCollection)
Sets the parent resource.


getResourceCollectionMgr

public ResourceCollectionMgr getResourceCollectionMgr()
Gets the locale resource manager.


getRequiredString

public java.lang.String getRequiredString(java.lang.String resourceItemName)
Gets a resource value as string. Writes a log message if no such item exists.

Parameters:
resourceItemName - Name of the resource item to get
Returns:
The string value of the item or the resource item name if no such item exists

getRequiredObject

public java.lang.Object getRequiredObject(java.lang.String resourceItemName)
Gets a resource value. Writes a log message if no such item exists.

Parameters:
resourceItemName - Name of the resource item to get
Returns:
The string value of the item or null if no such item exists

getOptionalString

public java.lang.String getOptionalString(java.lang.String resourceItemName)
Gets a resource value as string.

Parameters:
resourceItemName - Name of the resource item to get
Returns:
The string value of the item or null if no such item exists

getOptionalString

public java.lang.String getOptionalString(java.lang.String resourceItemName,
                                          java.lang.String dflt)
Gets a resource value as string.

Parameters:
resourceItemName - Name of the resource item to get
dflt - Default value
Returns:
The string value of the item or the default value if no such item exists

getOptionalObject

public java.lang.Object getOptionalObject(java.lang.String resourceItemName)
Gets a resource value.

Parameters:
resourceItemName - Name of the resource item to get
Returns:
The string value of the item or null if no such item exists

getOptionalObject

public java.lang.Object getOptionalObject(java.lang.String resourceItemName,
                                          java.lang.Object dflt)
Gets a resource value.

Parameters:
resourceItemName - Name of the resource item to get
dflt - Default value
Returns:
The string value of the item or the default value if no such item exists

addResourceItem

public void addResourceItem(ResourceItem item)
Adds the resource item to the resource.

Parameters:
item - Resource item

addImport

public void addImport(ResourceCollection importedResourceCollection)
Add a imported resource to this resource.

Parameters:
importedResourceCollection - The imported resource

getKeys

public java.util.Iterator getKeys()
Get all resource keys.

Returns:
Key iterator

getResourceItem

public ResourceItem getResourceItem(java.lang.String resourceItemName)
Gets the resource item specified by its name.

Parameters:
resourceItemName - Resource item name
Returns:
The resource item or null if no such item exists

getErrorName

public java.lang.String getErrorName()
Returns a string that identifies the resource in error messages.


getResourceObject

protected java.lang.Object getResourceObject(java.lang.String resourceItemName)
Get an object from a resource.

Parameters:
resourceItemName - Resource item name
Returns:
Resource item value

readFromInput

protected void readFromInput(java.io.InputStream stream)
                      throws java.io.IOException,
                             org.xml.sax.SAXException
Reads the DOM tree of a resource and adds all resource items it finds.

Parameters:
stream - XML input stream
Throws:
java.io.IOException - On I/O error
org.xml.sax.SAXException - On XML error

parseResource

protected void parseResource(org.w3c.dom.Element parentNode,
                             java.lang.String groupPath,
                             boolean preload)
Parses the DOM tree of a resource and adds all resource items it finds.

Parameters:
parentNode - Parent node to parse
groupPath - Resource group name to prepend to all resource items or null
preload - true Preload any resource objects (images etc.)
false Load the resource objects only when accessing the resource item.

createResourceItem

protected ResourceItem createResourceItem(org.w3c.dom.Element resourceItemNode,
                                          java.lang.String group,
                                          boolean preload)
Create a resource object.

Parameters:
resourceItemNode - Resource item xml element
group - Group of the item or null
preload - true The preload attribute of the resource file was set to true
false The preload attribute of the resource file was set to false
Returns:
Resource item or null on error

readResourceItem

public byte[] readResourceItem(java.lang.String relativePath)
Reads the (byte data) content of a resource collection item.

Parameters:
relativePath - Relative path of the item resource
Returns:
Byte Array or null if not found

getResourceItemPath

public java.lang.String getResourceItemPath(java.lang.String relativePath)
Determines the file path of a file within a container for error message output.

Parameters:
relativePath - Relative path of the file
Returns:
The path


Copyright © 2011. All Rights Reserved.