org.openbp.common.rc
Class ResourceCollectionMgr

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

public class ResourceCollectionMgr
extends java.lang.Object

Manages resources (ResourceCollection). The class can be instantiated for usage within a particular context, but also provides a global default instance that should be used for access to regular application resources.

Author:
Andreas Putz

Field Summary
static java.lang.String DEFAULT_LOCALE
          Default locale directory
static java.lang.String MEDIA_SUFFIX
          Media file suffix
static java.lang.String RC_FOLDER
          Default locale directory
 
Constructor Summary
ResourceCollectionMgr()
          Constructor.
 
Method Summary
 void addResourceVariable(java.lang.String pattern, java.lang.String replacement)
          Adds a global resource text variable.
static java.lang.String constructResourceCollectionLocalPath(java.lang.String containerName, java.util.Locale locale, java.lang.String resourceName)
          Constructs the local path to a resource collection.
 java.util.Locale determineParentLocale(java.util.Locale locale)
          Determines the parent locale of the given locale.
static ResourceCollectionMgr getDefaultInstance()
          Gets the singleton instance of this class.
 ResourceCollection getResource(java.lang.String containerName, java.lang.Class cls)
          Gets the resource for the given class using the default locale.
 ResourceCollection getResource(java.lang.String containerName, java.lang.Class cls, java.util.Locale locale)
          Gets the resource for the given class using the given locale.
 ResourceCollection getResource(java.lang.String containerName, java.lang.String resourceName)
          Gets the resource using the default locale.
 ResourceCollection getResource(java.lang.String containerName, java.lang.String resourceName, java.util.Locale locale)
          Gets the resource using the given locale.
 ResourceMgr getResourceMgr()
          Gets the resource manager used to read the resource files.
 java.lang.String performVariableReplacement(java.lang.String text)
          Performs any text replacements defined by addResourceVariable(java.lang.String, java.lang.String).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RC_FOLDER

public static final java.lang.String RC_FOLDER
Default locale directory

See Also:
Constant Field Values

DEFAULT_LOCALE

public static final java.lang.String DEFAULT_LOCALE
Default locale directory

See Also:
Constant Field Values

MEDIA_SUFFIX

public static final java.lang.String MEDIA_SUFFIX
Media file suffix

See Also:
Constant Field Values
Constructor Detail

ResourceCollectionMgr

public ResourceCollectionMgr()
Constructor.

Method Detail

getDefaultInstance

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


getResource

public ResourceCollection getResource(java.lang.String containerName,
                                      java.lang.String resourceName)
Gets the resource using the default locale.

Parameters:
containerName - Name of the resource container or null
resourceName - Name of the resource
Returns:
Resource object

getResource

public ResourceCollection getResource(java.lang.String containerName,
                                      java.lang.Class cls)
Gets the resource for the given class using the default locale. The class name of the resource is used as resource name. Note that the prefix "org.openbp.", will be removed from the class name in order to shorten the resource file name.

Parameters:
containerName - Name of the resource container or null
cls - Class of the object requesting the resource
Returns:
Resource object

getResource

public ResourceCollection getResource(java.lang.String containerName,
                                      java.lang.Class cls,
                                      java.util.Locale locale)
Gets the resource for the given class using the given locale. The class name of the resource is used as resource name. Note that the prefix "org.openbp.", will be removed from the class name in order to shorten the resource file name.

Parameters:
containerName - Name of the resource container or null
cls - Class of the object requesting the resource
locale - Locale to use; If the locale is null, the default locale will be used
Returns:
Resource object

getResource

public ResourceCollection getResource(java.lang.String containerName,
                                      java.lang.String resourceName,
                                      java.util.Locale locale)
Gets the resource using the given locale.

Parameters:
containerName - Name of the resource container or null
resourceName - Name of the resource
locale - Locale to use; If the locale is null, the default locale will be used
Returns:
Resource object or null if no such resource was found
Throws:
ResourceCollectionException - if no such resource collection in any matching locale could be found

constructResourceCollectionLocalPath

public static java.lang.String constructResourceCollectionLocalPath(java.lang.String containerName,
                                                                    java.util.Locale locale,
                                                                    java.lang.String resourceName)
Constructs the local path to a resource collection.

Parameters:
containerName - Container name or null
locale - Locale
resourceName - Resource name
Returns:
The path name

determineParentLocale

public java.util.Locale determineParentLocale(java.util.Locale locale)
Determines the parent locale of the given locale. Example: If the locale is 'de_DE' then is the parent locale 'de'.

Parameters:
locale - Locale to check
Returns:
The parent locale or null if the locale is a top-level locale

addResourceVariable

public void addResourceVariable(java.lang.String pattern,
                                java.lang.String replacement)
Adds a global resource text variable. The variable will be replaced for its value in every resource string (including image path names).

Parameters:
pattern - The pattern to search for
replacement - The substitute that will replace the pattern in the string or null to remove the pattern from the string

performVariableReplacement

public java.lang.String performVariableReplacement(java.lang.String text)
Performs any text replacements defined by addResourceVariable(java.lang.String, java.lang.String).

Parameters:
text - Text to replace or null
Returns:
The result text or null

getResourceMgr

public ResourceMgr getResourceMgr()
Gets the resource manager used to read the resource files.



Copyright © 2011. All Rights Reserved.