@Status(stage=PRODUCTION, unitTests=PARTIAL) @Review(by="Kees Schotanus", at="2009-09-28") @ThreadSafety(level=NOT_THREAD_SAFE, doc="Since JSP Beans are not thread safe either.") public final class CResourceBundle extends Object implements Serializable
resource bundles
that represents itself as a single ResourceBundle
.
Constructor and Description |
---|
CResourceBundle(Locale locale)
Constructs this CResourceBundle with an empty list of resource bundles.
|
CResourceBundle(Locale locale,
String resourceBundleName)
Constructs this CResourceBundle from the supplied locale and resourceBundleName.
|
CResourceBundle(String resourceBundleName)
Constructs this CResourceBundle from the supplied resourceBundleName, using the default locale.
|
Modifier and Type | Method and Description |
---|---|
void |
addResourceBundles(ResourceBundle... resourceBundles)
Adds resource bundles to the list of resource bundles.
|
void |
addResourceBundles(String... resourceBundleNames)
Adds resource bundles by name, to the list of resource bundles.
|
String |
format(String messagePattern,
Object... messageArguments)
Formats the supplied messagePattern with the optionally supplied messageArguments.
|
boolean |
getBoolean(String key)
Gets a boolean resource from the list of resource bundles.
|
boolean |
getBoolean(String key,
boolean defaultValue)
Gets a boolean resource from the list of resource bundles and when this resource does not exist, use the supplied
defaultValue.
|
Date |
getDate(String key)
Gets a Date resource from the list of resource bundles.
|
Date |
getDate(String key,
Date defaultValue)
Gets a Date resource from the list of resource bundles and when this resource does not exist, use the supplied
defaultValue.
|
Double |
getDouble(String key)
Gets a Double resource from the list of resource bundles.
|
Double |
getDouble(String key,
Double defaultValue)
Gets a Double resource from the list of resource bundles and when this resource does not exist, use the supplied
defaultValue.
|
Integer |
getInteger(String key)
Gets an Integer resource from the list of resource bundles.
|
Integer |
getInteger(String key,
Integer defaultValue)
Gets an Integer resource from the list of resource bundles and when this resource does not exist, use the supplied
defaultValue.
|
Locale |
getLocale()
Gets the locale used by the list of resource bundles.
|
static String |
getLocalizedMessage(Locale locale,
String resourceBundleName,
String messageKey,
Object... messageArguments)
Gets the localized message from the resource bundle with the supplied resourceBundleName, using the supplied messageKey.
|
static String |
getLocalizedMessage(ResourceBundle resourceBundle,
String messageKey,
Object... messageArguments)
Gets the localized message from the supplied resourceBundle, using the supplied messageKey.
|
Long |
getLong(String key)
Gets a Long resource from the list of resource bundles.
|
Long |
getLong(String key,
Long defaultValue)
Gets a Long resource from the list of resource bundles and when this resource does not exist, use the supplied
defaultValue.
|
String |
getMessage(String key,
Object... arguments)
Gets a formatted message from the list of resource bundles.
|
boolean |
getRequiredBoolean(String key)
Gets a required boolean resource from the list of resource bundles.
|
Date |
getRequiredDate(String key)
Gets a required Date resource from the list of resource bundles.
|
Double |
getRequiredDouble(String key)
Gets a required Double resource from the list of resource bundles.
|
Integer |
getRequiredInteger(String key)
Gets a required Integer resource from the list of resource bundles.
|
Long |
getRequiredLong(String key)
Gets a required Long resource from the list of resource bundles.
|
String |
getRequiredString(String key)
Gets a required String resource from the list of resource bundles.
|
String |
getString(String key)
Gets a String resource from the list of resource bundles.
|
String |
getString(String key,
String defaultValue)
Gets a String resource from the list of resource bundles and when this resource does not exist, use the supplied
defaultValue.
|
String |
toString()
Creates a String representation of this bundle of resource bundles.
|
public CResourceBundle(String resourceBundleName)
addResourceBundles(String...)
will use the same locale.resourceBundleName
- Name of the resource bundle file.
IllegalArgumentException
- When the supplied resourceBundleName is empty.MissingResourceException
- When the resource bundle could not be located.NullPointerException
- When the supplied resourceBundleName is null.public CResourceBundle(Locale locale)
locale
- The locale to localize the resources or null to use the default locale.public CResourceBundle(Locale locale, String resourceBundleName)
addResourceBundles(String...)
will use the same locale.locale
- The locale to localize the resources or null to use the default locale.resourceBundleName
- Name of the resource bundle file.
IllegalArgumentException
- When the supplied resourceBundleName is empty.MissingResourceException
- When the resource bundle could not be located.NullPointerException
- When the supplied resourceBundleName is null.public void addResourceBundles(String... resourceBundleNames)
resourceBundleNames
- The names of the resource bundles to add.
IllegalArgumentException
- When the supplied resourceBundleNames is empty.NullPointerException
- When the supplied resourceBundleNames is null.public void addResourceBundles(ResourceBundle... resourceBundles)
resourceBundles
- The resource bundles to add.
IllegalArgumentException
- When the supplied resourceBundles is empty.NullPointerException
- When the supplied resourceBundles is null.public Locale getLocale()
public boolean getBoolean(String key)
key
- Key to the boolean resource.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Boolean.parseBoolean(String)
public boolean getBoolean(String key, boolean defaultValue)
key
- Key to the boolean resource.defaultValue
- Default value in case the key is missing or when the located resource is not a boolean.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Boolean.parseBoolean(String)
public boolean getRequiredBoolean(String key)
key
- Key to the boolean resource.IllegalArgumentException
- When the supplied key is empty or when the retrieved resource could not be converted to
a boolean value.MissingResourceException
- When the key does not exist.NullPointerException
- When the supplied key is null.Boolean.parseBoolean(String)
public Date getDate(String key)
key
- Key to the Date resource.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Date.valueOf(String)
public Date getDate(String key, Date defaultValue)
key
- Key to the Date resource.defaultValue
- Default value in case the key is missing or when the located resource is not a Date.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Date.valueOf(String)
public Date getRequiredDate(String key)
key
- Key to the Date resource.IllegalArgumentException
- When the supplied key is empty or when the retrieved resource could not be converted to
a Date value.MissingResourceException
- When the key does not exist.NullPointerException
- When the supplied key is null.Date.valueOf(String)
public Integer getInteger(String key)
key
- Key to the Integer resource.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Integer.valueOf(String)
public Integer getInteger(String key, Integer defaultValue)
key
- Key to the Integer resource.defaultValue
- Default value in case the key is missing or when the located resource is not an Integer.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Integer.valueOf(String)
public Integer getRequiredInteger(String key)
key
- Key to the Integer resource.IllegalArgumentException
- When the supplied key is empty or when the retrieved resource could not be converted to
an Integer value.MissingResourceException
- When the key does not exist.NullPointerException
- When the supplied key is null.Integer.valueOf(String)
public Long getLong(String key)
key
- Key to the Long resource.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Long.valueOf(String)
public Long getLong(String key, Long defaultValue)
key
- Key to the Long resource.defaultValue
- Default value in case the key is missing or when the
located resource is not a Long.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Long.valueOf(String)
public Long getRequiredLong(String key)
key
- Key to the Long resource.IllegalArgumentException
- When the supplied key is empty or when the retrieved resource could not be converted to
a Long value.MissingResourceException
- When the key does not exist.NullPointerException
- When the supplied key is null.Long.valueOf(String)
public Double getDouble(String key)
key
- Key to the Double resource.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Double.valueOf(String)
public Double getDouble(String key, Double defaultValue)
key
- Key to the Double resource.defaultValue
- Default value in case the key is missing or when the located resource is not a Double.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.Double.valueOf(String)
public Double getRequiredDouble(String key)
key
- Key to the double resource.IllegalArgumentException
- When the supplied key is empty or when the retrieved resource could not be converted to
a Double value.MissingResourceException
- When the key does not exist.NullPointerException
- When the supplied key is null.Double.valueOf(String)
public String getString(String key)
key
- Key to the String resource.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.public String getString(String key, String defaultValue)
key
- Key to the String resource.defaultValue
- Default value in case the key does not exist.IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.public String getRequiredString(String key)
key
- Key to the String resource.IllegalArgumentException
- When the supplied key is empty.MissingResourceException
- When the key does not exist.NullPointerException
- When the supplied key is null.public String getMessage(String key, Object... arguments)
key
- Key to the String resource.arguments
- Message arguments that will be substituted in the retrieved string resource.
IllegalArgumentException
- When the supplied key is empty.NullPointerException
- When the supplied key is null.public String format(String messagePattern, Object... messageArguments)
messagePattern
- The message pattern.
messageArguments
- The arguments that must be inserted into the supplied messagePattern.
Localizable
that will be localized before being
inserted into the supplied messagePattern.NullPointerException
- When the supplied messagePattern is null.public static String getLocalizedMessage(Locale locale, String resourceBundleName, String messageKey, Object... messageArguments)
locale
- The locale used to translate the message.
resourceBundleName
- The name of the ResourceBundle
that contains the message to be localized.messageKey
- Key of the message to find and localize.messageArguments
- The message arguments that will be inserted into the localized message.MissingResourceException
.IllegalArgumentException
- When either the supplied resourceBundleName or messageKey is empty.NullPointerException
- When either the supplied resourceBundleName or messageKey is null.public static String getLocalizedMessage(ResourceBundle resourceBundle, String messageKey, Object... messageArguments)
resourceBundle
- The ResourceBundle that contains the message to be localized.messageKey
- Key of the message to find and localize.messageArguments
- The message arguments that will be inserted into the localized message.MissingResourceException
.IllegalArgumentException
- When the supplied messageKey is empty.NullPointerException
- When either the supplied resourceBundle or messageKey is null.Copyright © 2008–2018. All rights reserved.