public class ResourceBundleWrapper
extends java.lang.Object
ResourceBundle
objects. We use the wrapper because we don't
want to throw exceptions if a key is missing. Instead, we return the key as the value
and log a message to system log. There are also some other useful variants for retreiving
values.Modifier and Type | Field and Description |
---|---|
private static org.slf4j.Logger |
log |
private java.lang.String |
name |
private java.util.ResourceBundle |
parent |
private boolean |
returnKeys |
Constructor and Description |
---|
ResourceBundleWrapper(java.lang.String name,
java.util.ResourceBundle parent)
The wrapper is created by
ResourceBundleFactory . |
Modifier and Type | Method and Description |
---|---|
java.util.Locale |
getLocale()
Get the actual locale used by the bundle, which may be a different
locale from the one that was used to load it.
|
java.lang.String |
getName()
Get the base name of the resource bundle.
|
java.util.ResourceBundle |
getResourceBundle()
Get access to the underlying resource bundle.
|
java.lang.String |
getString(java.lang.String key,
boolean variant,
java.lang.String... replacements)
Utility method for returning the value for the key given
by
key.0 (variant=false) or key.1
(variant=true) depending on the value of the variant parameter. |
java.lang.String |
getString(java.lang.String key,
int index,
java.lang.String... replacements)
Utility method for returning the value for the key given by:
key.index . |
java.lang.String |
getString(java.lang.String key,
java.lang.String... replacements)
Get a string value from the bundle.
|
void |
setReturnKeys(boolean returnKeys)
Set a flag indicating that the various
getString() methods
should always return the key instead of trying to find a value for it. |
java.lang.String |
toString() |
private static final org.slf4j.Logger log
private final java.lang.String name
private final java.util.ResourceBundle parent
private boolean returnKeys
public ResourceBundleWrapper(java.lang.String name, java.util.ResourceBundle parent)
ResourceBundleFactory
.name
- The base name of the bundleparent
- The underlying ResourceBundle
public java.lang.String getName()
public java.util.Locale getLocale()
public void setReturnKeys(boolean returnKeys)
getString()
methods
should always return the key instead of trying to find a value for it.returnKeys
- TRUE to always return the key, FALSE to try to find valuespublic java.util.ResourceBundle getResourceBundle()
public java.lang.String getString(java.lang.String key, boolean variant, java.lang.String... replacements)
key.0
(variant=false) or key.1
(variant=true) depending on the value of the variant parameter.getString(String, String...)
public java.lang.String getString(java.lang.String key, int index, java.lang.String... replacements)
key.index
.getString(String, String...)
public java.lang.String getString(java.lang.String key, java.lang.String... replacements)
{index}
which will be replaced by the
corresponding value from the replacements array. Index values
that are outside the range of the array are not replaced.
If no value is found for the key or if the setReturnKeys(boolean)
has been enabled the key is returned.
key
- The key for the valuereplacements
- An optional array with string replacmentspublic java.lang.String toString()
toString
in class java.lang.Object