|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.struts.util.MessageResources
public abstract class MessageResources
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.
Field Summary | |
---|---|
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. |
protected MessageResourcesFactory |
factory
The MessageResourcesFactory that created this instance. |
protected HashMap |
formats
The set of previously created MessageFormat objects, keyed by the key computed in messageKey() . |
protected static Log |
log
Commons Logging instance. |
protected boolean |
returnNull
Indicate is a null is returned instead of an error message
string when an unknown Locale or key is requested. |
Constructor Summary | |
---|---|
MessageResources(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 | |
---|---|
protected String |
escape(String string)
Escape any single quote characters that are included in the specified message string. |
String |
getConfig()
The configuration parameter used to initialize this MessageResources. |
MessageResourcesFactory |
getFactory()
The MessageResourcesFactory that created this instance. |
abstract String |
getMessage(Locale locale,
String key)
Returns a text message for the specified key, for the default Locale. |
String |
getMessage(Locale locale,
String key,
Object arg0)
Returns a text message after parametric replacement of the specified parameter placeholders. |
String |
getMessage(Locale locale,
String key,
Object[] args)
Returns a text message after parametric replacement of the specified parameter placeholders. |
String |
getMessage(Locale locale,
String key,
Object arg0,
Object arg1)
Returns a text message after parametric replacement of the specified parameter placeholders. |
String |
getMessage(Locale locale,
String key,
Object arg0,
Object arg1,
Object arg2)
Returns a text message after parametric replacement of the specified parameter placeholders. |
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. |
String |
getMessage(String key)
Returns a text message for the specified key, for the default Locale. |
String |
getMessage(String key,
Object arg0)
Returns a text message after parametric replacement of the specified parameter placeholders. |
String |
getMessage(String key,
Object[] args)
Returns a text message after parametric replacement of the specified parameter placeholders. |
String |
getMessage(String key,
Object arg0,
Object arg1)
Returns a text message after parametric replacement of the specified parameter placeholders. |
String |
getMessage(String key,
Object arg0,
Object arg1,
Object arg2)
Returns a text message after parametric replacement of the specified parameter placeholders. |
String |
getMessage(String key,
Object arg0,
Object arg1,
Object arg2,
Object arg3)
Returns a text message after parametric replacement of the specified parameter placeholders. |
static MessageResources |
getMessageResources(String config)
Create and return an instance of MessageResources for the
created by the default MessageResourcesFactory . |
boolean |
getReturnNull()
Indicates that a null is returned instead of an error
message string if an unknown Locale or key is requested. |
boolean |
isEscape()
Indicates whether 'escape processing' should be performed on the error message string. |
boolean |
isPresent(Locale locale,
String key)
Return true if there is a defined message for the
specified key in the specified Locale. |
boolean |
isPresent(String key)
Return true if there is a defined message for the
specified key in the system default locale. |
protected String |
localeKey(Locale locale)
Compute and return a key to be used in caching information by a Locale. |
void |
log(String message)
Log a message to the Writer that has been configured for our use. |
void |
log(String message,
Throwable throwable)
Log a message and exception to the Writer that has been configured for our use. |
protected String |
messageKey(Locale locale,
String key)
Compute and return a key to be used in caching information by Locale and message key. |
protected String |
messageKey(String localeKey,
String key)
Compute and return a key to be used in caching information by locale key and message key. |
void |
setEscape(boolean escape)
Set whether 'escape processing' should be performed on the error message string. |
void |
setReturnNull(boolean returnNull)
Indicates that a null is returned instead of an error
message string if an unknown Locale or key is requested. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static Log log
protected static MessageResourcesFactory defaultFactory
protected String config
protected Locale defaultLocale
protected MessageResourcesFactory factory
MessageResourcesFactory
that created this instance.
protected HashMap formats
messageKey()
.
protected boolean returnNull
null
is returned instead of an error message
string when an unknown Locale or key is requested.
Constructor Detail |
---|
public MessageResources(MessageResourcesFactory factory, String config)
factory
- The MessageResourcesFactory that created usconfig
- The configuration parameter for this MessageResourcespublic MessageResources(MessageResourcesFactory factory, String config, boolean returnNull)
factory
- The MessageResourcesFactory that created usconfig
- The configuration parameter for this
MessageResourcesreturnNull
- The returnNull property we should initialize withMethod Detail |
---|
public String getConfig()
public MessageResourcesFactory getFactory()
MessageResourcesFactory
that created this instance.
MessageResourcesFactory
that created instancepublic boolean getReturnNull()
null
is returned instead of an error
message string if an unknown Locale or key is requested.
public void setReturnNull(boolean returnNull)
null
is returned instead of an error
message string if an unknown Locale or key is requested.
returnNull
- true Indicates that a null
is returned
if an unknown Locale or key is requested.public boolean isEscape()
public void setEscape(boolean escape)
public String getMessage(String key)
key
- The message key to look uppublic String getMessage(String key, Object[] args)
key
- The message key to look upargs
- An array of replacement parameters for placeholderspublic String getMessage(String key, Object arg0)
key
- The message key to look uparg0
- The replacement for placeholder {0} in the messagepublic String getMessage(String key, Object arg0, Object arg1)
key
- The message key to look uparg0
- The replacement for placeholder {0} in the messagearg1
- The replacement for placeholder {1} in the messagepublic String getMessage(String key, Object arg0, Object arg1, Object arg2)
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 messagepublic String getMessage(String key, Object arg0, Object arg1, Object arg2, Object arg3)
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 messagepublic abstract String getMessage(Locale locale, String key)
returnNull
property is set. Otherwise, an appropriate
error message will be returned. This method must be implemented by a concrete subclass.
locale
- The requested message Locale, or null
for
the system default Localekey
- The message key to look uppublic String getMessage(Locale locale, String key, Object[] args)
locale
- The requested message Locale, or null
for
the system default Localekey
- The message key to look upargs
- An array of replacement parameters for placeholderspublic String getMessage(Locale locale, String key, Object arg0)
locale
- The requested message Locale, or null
for
the system default Localekey
- The message key to look uparg0
- The replacement for placeholder {0} in the messagepublic String getMessage(Locale locale, String key, Object arg0, Object arg1)
locale
- The requested message Locale, or null
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 messagepublic String getMessage(Locale locale, String key, Object arg0, Object arg1, Object arg2)
locale
- The requested message Locale, or null
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 messagepublic String getMessage(Locale locale, String key, Object arg0, Object arg1, Object arg2, Object arg3)
locale
- The requested message Locale, or null
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 messagepublic boolean isPresent(String key)
true
if there is a defined message for the
specified key in the system default locale.
key
- The message key to look uppublic boolean isPresent(Locale locale, String key)
true
if there is a defined message for the
specified key in the specified Locale.
locale
- The requested message Locale, or null
for
the system default Localekey
- The message key to look upprotected String escape(String string)
string
- The string to be escapedprotected String localeKey(Locale locale)
locale
- The locale for which a key is desiredprotected String messageKey(Locale locale, String key)
locale
- The Locale for which this format key is calculatedkey
- The message key for which this format key is calculatedprotected String messageKey(String localeKey, String key)
localeKey
- The locale key for which this cache key is calculatedkey
- The message key for which this cache key is
calculatedpublic static MessageResources getMessageResources(String config)
MessageResources
for the
created by the default MessageResourcesFactory
.
config
- Configuration parameter for this message bundle.public void log(String message)
message
- The message to be loggedpublic void log(String message, Throwable throwable)
message
- The message to be loggedthrowable
- The exception to be logged
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |