org.apache.struts.util
public class PropertyMessageResources extends MessageResources
MessageResources
that reads message keys
and corresponding strings from named property resources in the same manner
that java.util.PropertyResourceBundle
does. The
base
property defines the base property resource name, and
must be specified.
IMPLEMENTATION NOTE - This class trades memory for speed by caching all messages located via generalizing the Locale under the original locale as well. This results in specific messages being stored in the message cache more than once, but improves response time on subsequent requests for the same locale + key combination.
Modifier and Type | Field and Description |
---|---|
protected java.util.HashMap |
locales
The set of locale keys for which we have already loaded messages, keyed
by the value calculated in
localeKey() . |
protected static org.apache.commons.logging.Log |
log
The
Log instance for this class. |
protected java.util.HashMap |
messages
The cache of messages we have accumulated over time, keyed by the
value calculated in
messageKey() . |
config, defaultFactory, defaultLocale, factory, formats, returnNull
Constructor and Description |
---|
PropertyMessageResources(MessageResourcesFactory factory,
java.lang.String config)
Construct a new PropertyMessageResources according to the
specified parameters.
|
PropertyMessageResources(MessageResourcesFactory factory,
java.lang.String config,
boolean returnNull)
Construct a new PropertyMessageResources according to the
specified parameters.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getMessage(java.util.Locale locale,
java.lang.String key)
Returns a text message for the specified key, for the default Locale.
|
protected void |
loadLocale(java.lang.String localeKey)
Load the messages associated with the specified Locale key.
|
escape, getConfig, getFactory, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessageResources, getReturnNull, isEscape, isPresent, isPresent, localeKey, log, log, messageKey, messageKey, setEscape, setReturnNull
protected java.util.HashMap locales
localeKey()
.protected static final org.apache.commons.logging.Log log
Log
instance for this class.protected java.util.HashMap messages
messageKey()
.public PropertyMessageResources(MessageResourcesFactory factory, java.lang.String config)
factory
- The MessageResourcesFactory that created usconfig
- The configuration parameter for this MessageResourcespublic PropertyMessageResources(MessageResourcesFactory factory, java.lang.String config, boolean returnNull)
factory
- The MessageResourcesFactory that created usconfig
- The configuration parameter for this MessageResourcesreturnNull
- The returnNull property we should initialize withpublic java.lang.String getMessage(java.util.Locale locale, java.lang.String key)
returnNull
property is set. Otherwise, an appropriate
error message will be returned.
This method must be implemented by a concrete subclass.
getMessage
in class MessageResources
locale
- The requested message Locale, or null
for the system default Localekey
- The message key to look upprotected void loadLocale(java.lang.String localeKey)
config
property should contain a fully
qualified package and resource name, separated by periods, of a series
of property resources to be loaded from the class loader that created
this PropertyMessageResources instance. This is exactly the same name
format you would use when utilizing the
java.util.PropertyResourceBundle
class.localeKey
- Locale key for the messages to be retrievedCopyright ? 2000-2014 - The Apache Software Foundation