public class ResourceUtils
extends java.lang.Object
The getBundle() calls cache the requested bundles hashed off of the Locale and the bundle basename. This will provide a speed-up over ResourceBundle.getBundle() for components that are doing many getBundle() calls, turning a series of String concatenations into two Hashtable look-ups.
The getMsgResource() calls prepend the resource string with an identifying string consisting of the bundle name and the resource look-up key. When messages are localized, it is useful to be able to identify where they came from.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string
|
static boolean |
useBundlePrefix |
Constructor and Description |
---|
ResourceUtils()
Empty constructor.
|
Modifier and Type | Method and Description |
---|---|
static java.util.ResourceBundle |
getBundle(java.lang.String pBaseName)
Returns the requested ResourceBundle.
|
static java.util.ResourceBundle |
getBundle(java.lang.String pBaseName,
java.util.Locale pLocale)
Returns the requested ResourceBundle for the specified Locale.
|
static java.lang.String |
getMsgResource(java.lang.String pLookupKey,
java.lang.String pBundleName,
java.util.ResourceBundle pBundle)
Fetches the message resource from the given bundle and pre-pends
the resource ID string to the message.
|
static java.lang.String |
getMsgResource(java.lang.String pLookupKey,
java.lang.String pBundleName,
java.util.ResourceBundle pBundle,
java.lang.Object pMsgArg)
Fetches the message resource from the given bundle and pre-pends
the resource ID string to the message.
|
static java.lang.String |
getMsgResource(java.lang.String pLookupKey,
java.lang.String pBundleName,
java.util.ResourceBundle pBundle,
java.lang.Object[] pMsgArgs)
Fetches the message resource from the given bundle and pre-pends
the resource ID string to the message.
|
static java.lang.String |
getMsgResource(java.lang.String pLookupKey,
java.lang.String pBundleName,
java.util.ResourceBundle pBundle,
java.lang.Object pMsgArg1,
java.lang.Object pMsgArg2)
Fetches the message resource from the given bundle and pre-pends
the resource ID string to the message.
|
static java.util.List<java.lang.String> |
getPublicStringConstantsNotInBundle(java.lang.Class<?> pClass,
java.util.Set<java.lang.String> pIgnoredFields,
java.util.ResourceBundle pBundle)
Return the values of the string constants in the given class that are not
in the specified collection.
|
static java.lang.String |
getUserMsgResource(java.lang.String pLookupKey,
java.lang.String pBundleName,
java.util.ResourceBundle pBundle)
Fetches the message resource from the given bundle without prepending
the resource ID string to the message.
|
static java.lang.String |
getUserMsgResource(java.lang.String pLookupKey,
java.lang.String pBundleName,
java.util.ResourceBundle pBundle,
java.lang.Object[] pMsgArgs)
Fetches the message resource from the given bundle without prepending
the resource ID string to the message.
|
static boolean |
isKeyDefinedInLocalizedResource(java.lang.String pLookupKey,
java.lang.String pBundleName,
java.util.ResourceBundle pBundle)
This method determines if a locale specific resource originates from the
localized resource instead of just fetching it from the base property
resource.
|
static void |
setUseBundlePrefix(boolean pUseBundlePrefix)
Should we display messages using the bundle name and resource key
as a prefix or just display the messages?
|
public static java.lang.String CLASS_VERSION
public static boolean useBundlePrefix
public static java.util.ResourceBundle getBundle(java.lang.String pBaseName) throws java.util.MissingResourceException
java.util.MissingResourceException
public static java.util.ResourceBundle getBundle(java.lang.String pBaseName, java.util.Locale pLocale) throws java.util.MissingResourceException
java.util.MissingResourceException
public static java.lang.String getMsgResource(java.lang.String pLookupKey, java.lang.String pBundleName, java.util.ResourceBundle pBundle)
public static java.lang.String getMsgResource(java.lang.String pLookupKey, java.lang.String pBundleName, java.util.ResourceBundle pBundle, java.lang.Object[] pMsgArgs)
public static java.lang.String getMsgResource(java.lang.String pLookupKey, java.lang.String pBundleName, java.util.ResourceBundle pBundle, java.lang.Object pMsgArg)
public static java.lang.String getMsgResource(java.lang.String pLookupKey, java.lang.String pBundleName, java.util.ResourceBundle pBundle, java.lang.Object pMsgArg1, java.lang.Object pMsgArg2)
public static void setUseBundlePrefix(boolean pUseBundlePrefix)
public static java.lang.String getUserMsgResource(java.lang.String pLookupKey, java.lang.String pBundleName, java.util.ResourceBundle pBundle)
public static java.lang.String getUserMsgResource(java.lang.String pLookupKey, java.lang.String pBundleName, java.util.ResourceBundle pBundle, java.lang.Object[] pMsgArgs)
public static boolean isKeyDefinedInLocalizedResource(java.lang.String pLookupKey, java.lang.String pBundleName, java.util.ResourceBundle pBundle)
pLookupKey
- The resource lookup key.pBundleName
- The name of the resource bundle if the bundle is not
already available.pBundle
- The resource bundle to query.ResourceBundle
,
PropertyResourceBundle
public static java.util.List<java.lang.String> getPublicStringConstantsNotInBundle(java.lang.Class<?> pClass, java.util.Set<java.lang.String> pIgnoredFields, java.util.ResourceBundle pBundle) throws java.lang.IllegalAccessException
pClass
- the class containing the string constants that
should appear in the resource bundle.pIgnoredFields
- the names of fields/constants that should be
ignored, typically because they contain other string constants.pBundle
- the resource bundle which should contain keys
that match the string constants value.java.lang.IllegalAccessException