Messages
.@Deprecated public class MessageBundle extends ResourceBundle
ResourceBundle
to provide some useful additional functionality.
MissingResourceException
, the ResourceBundle.getString(String)
method
will return ThreadLocal
object using the static setClientLocale(Locale)
so that client localized messages can be retrieved using the getClientString(String, Object...)
method on all instances of this class.
addSearchPath(Class, String)
method.
This allows messages to be retrieved from the resource bundles of parent classes.
getBundle(Locale)
method.
getString(Locale, String, Object...)
method can be used to retrieve locale-specific messages.
getString("myMessage" )
.
ResourceBundle.Control
parent
Constructor and Description |
---|
MessageBundle(Class<?> forClass,
String bundlePath)
Deprecated.
Constructor.
|
Modifier and Type | Method and Description |
---|---|
MessageBundle |
addSearchPath(Class<?> forClass,
String bundlePath)
Deprecated.
Add another bundle path to this resource bundle.
|
boolean |
containsKey(String key)
Deprecated.
|
static MessageBundle |
create(Class<?> forClass)
Deprecated.
Constructor.
|
static MessageBundle |
create(Class<?> forClass,
String bundlePath)
Deprecated.
Constructor.
|
String |
findFirstString(Locale locale,
String... keys)
Deprecated.
Same as
findFirstString(String...) , but uses the specified locale. |
String |
findFirstString(String... keys)
Deprecated.
Looks for all the specified keys in the resource bundle and returns the first value that exists.
|
MessageBundle |
getBundle(Locale locale)
Deprecated.
Returns the resource bundle for the specified locale.
|
String |
getClientString(String key,
Object... args)
Deprecated.
Same as
getString(String, Object...) but uses the locale specified on the call to setClientLocale(Locale) . |
Enumeration<String> |
getKeys()
Deprecated.
|
String |
getString(Locale locale,
String key,
Object... args)
Deprecated.
Same as
getString(String, Object...) but allows you to specify the locale. |
String |
getString(String key,
Object... args)
Deprecated.
Similar to
ResourceBundle.getString(String) except allows you to pass in MessageFormat objects. |
protected Object |
handleGetObject(String key)
Deprecated.
|
Set<String> |
keySet()
Deprecated.
|
Set<String> |
keySet(String prefix)
Deprecated.
Returns all keys in this resource bundle with the specified prefix.
|
static void |
setClientLocale(Locale locale)
Deprecated.
Sets the locale for this thread so that calls to
getClientString(String, Object...) return messages in
that locale. |
OMap |
swap()
Deprecated.
Returns this resource bundle as an
OMap . |
clearCache, clearCache, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, handleKeySet, setParent
public MessageBundle(Class<?> forClass, String bundlePath)
forClass
- The class using this resource bundle.bundlePath
- The path of the resource bundle to wrap.
This can be an absolute path (e.g. public static void setClientLocale(Locale locale)
getClientString(String, Object...)
return messages in
that locale.locale
- The new client locale.public static final MessageBundle create(Class<?> forClass)
When this method is used, the bundle path is determined by searching for the resource bundle in the following locations:
forClass
- The classpublic static final MessageBundle create(Class<?> forClass, String bundlePath)
A shortcut for calling
forClass
- The classbundlePath
- The location of the resource bundle.public MessageBundle addSearchPath(Class<?> forClass, String bundlePath)
Order of property lookup is first-to-last.
This method must be called from the same thread as the call to the constructor. This eliminates the need for synchronization.
forClass
- The class using this resource bundle.bundlePath
- The bundle path.public boolean containsKey(String key)
containsKey
in class ResourceBundle
public String getString(String key, Object... args)
ResourceBundle.getString(String)
except allows you to pass in MessageFormat
objects.key
- The resource bundle key.args
- Optional MessageFormat
-style arguments.public String getString(Locale locale, String key, Object... args)
getString(String, Object...)
but allows you to specify the locale.locale
- The locale of the resource bundle to retrieve message from.key
- The resource bundle key.args
- Optional MessageFormat
-style arguments.public String getClientString(String key, Object... args)
getString(String, Object...)
but uses the locale specified on the call to setClientLocale(Locale)
.key
- The resource bundle key.args
- Optional MessageFormat
-style arguments.public String findFirstString(String... keys)
keys
- The list of possible keys.public String findFirstString(Locale locale, String... keys)
findFirstString(String...)
, but uses the specified locale.locale
- The locale of the resource bundle to retrieve message from.keys
- The list of possible keys.public Set<String> keySet()
keySet
in class ResourceBundle
public Set<String> keySet(String prefix)
prefix
- The prefix.public Enumeration<String> getKeys()
getKeys
in class ResourceBundle
protected Object handleGetObject(String key)
handleGetObject
in class ResourceBundle
public OMap swap()
OMap
.
Useful for debugging purposes.
Note that any class that implements a
This method always constructs a new OMap
on each call.
public MessageBundle getBundle(Locale locale)
locale
- The client locale.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.