Package net.sf.basedb.util.resources
Class ResourceBundleWrapper
java.lang.Object
net.sf.basedb.util.resources.ResourceBundleWrapper
A wrapper around
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.- Since:
- 2.16
- Author:
- Nicklas
- Last modified
- $Date: 2014-04-09 14:21:20 +0200 (on, 09 apr 2014) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final Logger
private final String
private final ResourceBundle
private boolean
-
Constructor Summary
ConstructorDescriptionResourceBundleWrapper
(String name, ResourceBundle parent) The wrapper is created byResourceBundleFactory
. -
Method Summary
Modifier and TypeMethodDescriptionGet the actual locale used by the bundle, which may be a different locale from the one that was used to load it.getName()
Get the base name of the resource bundle.Get access to the underlying resource bundle.Utility method for returning the value for the key given bykey.0
(variant=false) orkey.1
(variant=true) depending on the value of the variant parameter.Utility method for returning the value for the key given by:key.index
.Get a string value from the bundle.void
setReturnKeys
(boolean returnKeys) Set a flag indicating that the variousgetString()
methods should always return the key instead of trying to find a value for it.toString()
-
Field Details
-
log
-
name
-
parent
-
returnKeys
private boolean returnKeys
-
-
Constructor Details
-
ResourceBundleWrapper
The wrapper is created byResourceBundleFactory
.- Parameters:
name
- The base name of the bundleparent
- The underlyingResourceBundle
-
-
Method Details
-
getName
Get the base name of the resource bundle. -
getLocale
Get the actual locale used by the bundle, which may be a different locale from the one that was used to load it. -
setReturnKeys
public void setReturnKeys(boolean returnKeys) Set a flag indicating that the variousgetString()
methods should always return the key instead of trying to find a value for it.- Parameters:
returnKeys
- TRUE to always return the key, FALSE to try to find values
-
getResourceBundle
Get access to the underlying resource bundle. -
getString
Utility method for returning the value for the key given bykey.0
(variant=false) orkey.1
(variant=true) depending on the value of the variant parameter.- See Also:
-
getString
Utility method for returning the value for the key given by:key.index
.- See Also:
-
getString
Get a string value from the bundle. The value may contain placeholders of the form{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.- Parameters:
key
- The key for the valuereplacements
- An optional array with string replacments- Returns:
- The value found for the key
-
toString
-