Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.struts.util.MessageResources
public abstract class MessageResources
extends java.lang.Object
implements Serializable
MessageFormat
class to produce internationalized messages with parametric replacement.
Calls to getMessage()
variants without a Locale
argument are presumed to be requesting a message string in the default
Locale
for this JVM.
Calls to getMessage()
with an unknown key, or an unknown
Locale
will return null
if the
returnNull
property is set to true
. Otherwise,
a suitable error message will be returned instead.
IMPLEMENTATION NOTE - Classes that extend this class
must be Serializable so that instances may be used in distributable
application server environments.
Field Summary | |
protected String |
|
protected static MessageResourcesFactory |
|
protected Locale |
|
private boolean |
|
protected MessageResourcesFactory |
|
protected HashMap |
|
protected static Log |
|
protected boolean |
|
Constructor Summary | |
| |
|
Method Summary | |
protected String |
|
String |
|
MessageResourcesFactory |
|
abstract String |
|
String |
|
String |
|
String |
|
String |
|
String |
|
String |
|
String |
|
String |
|
String |
|
String |
|
String |
|
static MessageResources |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
protected String |
|
void |
|
void |
|
protected String |
|
protected String |
|
void |
|
void |
|
protected String config
The configuration parameter used to initialize this MessageResources.
protected static MessageResourcesFactory defaultFactory
The default MessageResourcesFactory used to create MessageResources instances.
protected Locale defaultLocale
The default Locale for our environment.
private boolean escape
Indicates whether 'escape processing' should be performed on the error message string.
protected MessageResourcesFactory factory
TheMessageResourcesFactory
that created this instance.
protected HashMap formats
The set of previously created MessageFormat objects, keyed by the key computed inmessageKey()
.
protected static Log log
Commons Logging instance.
protected boolean returnNull
Indicate is anull
is returned instead of an error message string when an unknown Locale or key is requested.
public MessageResources(MessageResourcesFactory factory, String config)
Construct a new MessageResources according to the specified parameters.
- Parameters:
factory
- The MessageResourcesFactory that created usconfig
- The configuration parameter for this MessageResources
public MessageResources(MessageResourcesFactory factory, String config, boolean returnNull)
Construct a new MessageResources according to the specified parameters.
- Parameters:
factory
- The MessageResourcesFactory that created usconfig
- The configuration parameter for this MessageResourcesreturnNull
- The returnNull property we should initialize with
protected String escape(String string)
Escape any single quote characters that are included in the specified message string.
- Parameters:
string
- The string to be escaped
public String getConfig()
The configuration parameter used to initialize this MessageResources.
- Returns:
- parameter used to initialize this MessageResources
public MessageResourcesFactory getFactory()
TheMessageResourcesFactory
that created this instance.
- Returns:
MessageResourcesFactory
that created instance
public abstract String getMessage(Locale locale, String key)
Returns a text message for the specified key, for the default Locale. A null string result will be returned by this method if no relevant message resource is found for this key or Locale, if thereturnNull
property is set. Otherwise, an appropriate error message will be returned. This method must be implemented by a concrete subclass.
- Parameters:
locale
- The requested message Locale, ornull
for the system default Localekey
- The message key to look up
public String getMessage(Locale locale, String key, Object arg0)
Returns a text message after parametric replacement of the specified parameter placeholders. A null string result will never be returned by this method.
- Parameters:
locale
- The requested message Locale, ornull
for the system default Localekey
- The message key to look uparg0
- The replacement for placeholder {0} in the message
public String getMessage(Locale locale, String key, Object arg0, Object arg1)
Returns a text message after parametric replacement of the specified parameter placeholders. A null string result will never be returned by this method.
- Parameters:
locale
- The requested message Locale, ornull
for the system default Localekey
- The message key to look uparg0
- The replacement for placeholder {0} in the messagearg1
- The replacement for placeholder {1} in the message
public String getMessage(Locale locale, String key, Object arg0, Object arg1, Object arg2)
Returns a text message after parametric replacement of the specified parameter placeholders. A null string result will never be returned by this method.
- Parameters:
locale
- The requested message Locale, ornull
for the system default Localekey
- The message key to look uparg0
- The replacement for placeholder {0} in the messagearg1
- The replacement for placeholder {1} in the messagearg2
- The replacement for placeholder {2} in the message
public String getMessage(Locale locale, String key, Object arg0, Object arg1, Object arg2, Object arg3)
Returns a text message after parametric replacement of the specified parameter placeholders. A null string result will never be returned by this method.
- Parameters:
locale
- The requested message Locale, ornull
for the system default Localekey
- The message key to look uparg0
- The replacement for placeholder {0} in the messagearg1
- The replacement for placeholder {1} in the messagearg2
- The replacement for placeholder {2} in the messagearg3
- The replacement for placeholder {3} in the message
public String getMessage(Locale locale, String key, args[] )
Returns a text message after parametric replacement of the specified parameter placeholders. A null string result will be returned by this method if no resource bundle has been configured.
- Parameters:
locale
- The requested message Locale, ornull
for the system default Localekey
- The message key to look up
public String getMessage(String key)
Returns a text message for the specified key, for the default Locale.
- Parameters:
key
- The message key to look up
public String getMessage(String key, Object arg0)
Returns a text message after parametric replacement of the specified parameter placeholders.
- Parameters:
key
- The message key to look uparg0
- The replacement for placeholder {0} in the message
public String getMessage(String key, Object arg0, Object arg1)
Returns a text message after parametric replacement of the specified parameter placeholders.
- Parameters:
key
- The message key to look uparg0
- The replacement for placeholder {0} in the messagearg1
- The replacement for placeholder {1} in the message
public String getMessage(String key, Object arg0, Object arg1, Object arg2)
Returns a text message after parametric replacement of the specified parameter placeholders.
- Parameters:
key
- The message key to look uparg0
- The replacement for placeholder {0} in the messagearg1
- The replacement for placeholder {1} in the messagearg2
- The replacement for placeholder {2} in the message
public String getMessage(String key, Object arg0, Object arg1, Object arg2, Object arg3)
Returns a text message after parametric replacement of the specified parameter placeholders.
- Parameters:
key
- The message key to look uparg0
- The replacement for placeholder {0} in the messagearg1
- The replacement for placeholder {1} in the messagearg2
- The replacement for placeholder {2} in the messagearg3
- The replacement for placeholder {3} in the message
public String getMessage(String key, args[] )
Returns a text message after parametric replacement of the specified parameter placeholders.
- Parameters:
key
- The message key to look up
public static MessageResources getMessageResources(String config)
Create and return an instance ofMessageResources
for the created by the defaultMessageResourcesFactory
.
- Parameters:
config
- Configuration parameter for this message bundle.
public boolean getReturnNull()
Indicates that anull
is returned instead of an error message string if an unknown Locale or key is requested.
- Returns:
- true if null is returned if unknown key or locale is requested
public boolean isEscape()
Indicates whether 'escape processing' should be performed on the error message string.
- Since:
- Struts 1.2.8
public boolean isPresent(Locale locale, String key)
Returntrue
if there is a defined message for the specified key in the specified Locale.
- Parameters:
locale
- The requested message Locale, ornull
for the system default Localekey
- The message key to look up
public boolean isPresent(String key)
Returntrue
if there is a defined message for the specified key in the system default locale.
- Parameters:
key
- The message key to look up
protected String localeKey(Locale locale)
Compute and return a key to be used in caching information by a Locale. NOTE - The locale key for the default Locale in our environment is a zero length String.
- Parameters:
locale
- The locale for which a key is desired
public void log(String message)
Log a message to the Writer that has been configured for our use.
- Parameters:
message
- The message to be logged
public void log(String message, Throwable throwable)
Log a message and exception to the Writer that has been configured for our use.
- Parameters:
message
- The message to be loggedthrowable
- The exception to be logged
protected String messageKey(Locale locale, String key)
Compute and return a key to be used in caching information by Locale and message key.
- Parameters:
locale
- The Locale for which this format key is calculatedkey
- The message key for which this format key is calculated
protected String messageKey(String localeKey, String key)
Compute and return a key to be used in caching information by locale key and message key.
- Parameters:
localeKey
- The locale key for which this cache key is calculatedkey
- The message key for which this cache key is calculated
public void setEscape(boolean escape)
Set whether 'escape processing' should be performed on the error message string.
- Since:
- Struts 1.2.8
public void setReturnNull(boolean returnNull)
Indicates that anull
is returned instead of an error message string if an unknown Locale or key is requested.
- Parameters:
returnNull
- true Indicates that anull
is returned if an unknown Locale or key is requested.