Package org.apache.struts.util
Class MessageResources
java.lang.Object
org.apache.struts.util.MessageResources
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
PropertyMessageResources
General purpose abstract class that describes an API for retrieving
Locale-sensitive messages from underlying resource locations of an
unspecified design, and optionally utilizing the
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.
- Version:
- $Rev$ $Date: 2005-08-29 23:57:50 -0400 (Mon, 29 Aug 2005) $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe configuration parameter used to initialize this MessageResources.protected static MessageResourcesFactoryThe default MessageResourcesFactory used to create MessageResources instances.protected LocaleThe default Locale for our environment.protected MessageResourcesFactoryTheMessageResourcesFactorythat created this instance.protected HashMap<String, MessageFormat> The set of previously created MessageFormat objects, keyed by the key computed inmessageKey().protected booleanIndicate is anullis returned instead of an error message string when an unknown Locale or key is requested. -
Constructor Summary
ConstructorsConstructorDescriptionMessageResources(MessageResourcesFactory factory, String config) Construct a new MessageResources according to the specified parameters.MessageResources(MessageResourcesFactory factory, String config, boolean returnNull) Construct a new MessageResources according to the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringEscape any single quote characters that are included in the specified message string.The configuration parameter used to initialize this MessageResources.TheMessageResourcesFactorythat created this instance.getMessage(String key) Returns a text message for the specified key, for the default Locale.getMessage(String key, Object arg0) Returns a text message after parametric replacement of the specified parameter placeholders.getMessage(String key, Object[] args) Returns a text message after parametric replacement of the specified parameter placeholders.getMessage(String key, Object arg0, Object arg1) Returns a text message after parametric replacement of the specified parameter placeholders.getMessage(String key, Object arg0, Object arg1, Object arg2) Returns a text message after parametric replacement of the specified parameter placeholders.Returns a text message after parametric replacement of the specified parameter placeholders.abstract StringgetMessage(Locale locale, String key) Returns a text message for the specified key, for the default Locale.getMessage(Locale locale, String key, Object arg0) Returns a text message after parametric replacement of the specified parameter placeholders.getMessage(Locale locale, String key, Object[] args) Returns a text message after parametric replacement of the specified parameter placeholders.getMessage(Locale locale, String key, Object arg0, Object arg1) Returns a text message after parametric replacement of the specified parameter placeholders.Returns a text message after parametric replacement of the specified parameter placeholders.Returns a text message after parametric replacement of the specified parameter placeholders.static MessageResourcesgetMessageResources(String config) Create and return an instance ofMessageResourcesfor the created by the defaultMessageResourcesFactory.booleanIndicates that anullis returned instead of an error message string if an unknown Locale or key is requested.booleanisEscape()Indicates whether 'escape processing' should be performed on the error message string.booleanReturntrueif there is a defined message for the specified key in the system default locale.booleanReturntrueif there is a defined message for the specified key in the specified Locale.protected StringCompute and return a key to be used in caching information by a Locale.voidLog a message to the Writer that has been configured for our use.voidLog a message and exception to the Writer that has been configured for our use.protected StringmessageKey(String localeKey, String key) Compute and return a key to be used in caching information by locale key and message key.protected StringmessageKey(Locale locale, String key) Compute and return a key to be used in caching information by Locale and message key.voidsetEscape(boolean escape) Set whether 'escape processing' should be performed on the error message string.voidsetReturnNull(boolean returnNull) Indicates that anullis returned instead of an error message string if an unknown Locale or key is requested.
-
Field Details
-
defaultFactory
The default MessageResourcesFactory used to create MessageResources instances. -
config
The configuration parameter used to initialize this MessageResources. -
defaultLocale
The default Locale for our environment. -
factory
TheMessageResourcesFactorythat created this instance. -
formats
The set of previously created MessageFormat objects, keyed by the key computed inmessageKey(). -
returnNull
protected boolean returnNullIndicate is anullis returned instead of an error message string when an unknown Locale or key is requested.
-
-
Constructor Details
-
MessageResources
Construct a new MessageResources according to the specified parameters.- Parameters:
factory- The MessageResourcesFactory that created usconfig- The configuration parameter for this MessageResources
-
MessageResources
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
-
-
Method Details
-
getConfig
The configuration parameter used to initialize this MessageResources.- Returns:
- parameter used to initialize this MessageResources
-
getFactory
TheMessageResourcesFactorythat created this instance.- Returns:
MessageResourcesFactorythat created instance
-
getReturnNull
public boolean getReturnNull()Indicates that anullis 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
-
setReturnNull
public void setReturnNull(boolean returnNull) Indicates that anullis returned instead of an error message string if an unknown Locale or key is requested.- Parameters:
returnNull- true Indicates that anullis returned if an unknown Locale or key is requested.
-
isEscape
public boolean isEscape()Indicates whether 'escape processing' should be performed on the error message string.- Since:
- Struts 1.2.8
-
setEscape
public void setEscape(boolean escape) Set whether 'escape processing' should be performed on the error message string.- Since:
- Struts 1.2.8
-
getMessage
Returns a text message for the specified key, for the default Locale.- Parameters:
key- The message key to look up
-
getMessage
Returns a text message after parametric replacement of the specified parameter placeholders.- Parameters:
key- The message key to look upargs- An array of replacement parameters for placeholders
-
getMessage
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
-
getMessage
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
-
getMessage
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
-
getMessage
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
-
getMessage
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 thereturnNullproperty 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, ornullfor the system default Localekey- The message key to look up
-
getMessage
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, ornullfor the system default Localekey- The message key to look upargs- An array of replacement parameters for placeholders
-
getMessage
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, ornullfor the system default Localekey- The message key to look uparg0- The replacement for placeholder {0} in the message
-
getMessage
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, ornullfor 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
-
getMessage
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, ornullfor 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
-
getMessage
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, ornullfor 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
-
isPresent
Returntrueif there is a defined message for the specified key in the system default locale.- Parameters:
key- The message key to look up
-
isPresent
Returntrueif there is a defined message for the specified key in the specified Locale.- Parameters:
locale- The requested message Locale, ornullfor the system default Localekey- The message key to look up
-
escape
Escape any single quote characters that are included in the specified message string.- Parameters:
string- The string to be escaped
-
localeKey
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
-
messageKey
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
-
messageKey
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
-
getMessageResources
Create and return an instance ofMessageResourcesfor the created by the defaultMessageResourcesFactory.- Parameters:
config- Configuration parameter for this message bundle.
-
log
Log a message to the Writer that has been configured for our use.- Parameters:
message- The message to be logged
-
log
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
-