public class StaticMessageSource extends AbstractMessageSource
MessageSource
which allows messages to be registered programmatically.
This MessageSource supports basic internationalization.
Intended for testing rather than for use in production systems.
logger| Constructor and Description |
|---|
StaticMessageSource() |
| Modifier and Type | Method and Description |
|---|---|
void |
addMessage(java.lang.String code,
java.util.Locale locale,
java.lang.String msg)
Associate the given message with the given code.
|
void |
addMessages(java.util.Map<java.lang.String,java.lang.String> messages,
java.util.Locale locale)
Associate the given message values with the given keys as codes.
|
protected java.text.MessageFormat |
resolveCode(java.lang.String code,
java.util.Locale locale)
Subclasses must implement this method to resolve a message.
|
protected java.lang.String |
resolveCodeWithoutArguments(java.lang.String code,
java.util.Locale locale)
Subclasses can override this method to resolve a message without arguments
in an optimized fashion, i.e.
|
java.lang.String |
toString() |
getCommonMessages, getDefaultMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessagecreateMessageFormat, formatMessage, isAlwaysUseMessageFormat, renderDefaultMessage, setAlwaysUseMessageFormatprotected java.lang.String resolveCodeWithoutArguments(java.lang.String code,
java.util.Locale locale)
AbstractMessageSourceThe default implementation does use MessageFormat, through
delegating to the AbstractMessageSource.resolveCode(java.lang.String, java.util.Locale) method. Subclasses are encouraged
to replace this with optimized resolution.
Unfortunately, java.text.MessageFormat is not implemented
in an efficient fashion. In particular, it does not detect that a message
pattern doesn't contain argument placeholders in the first place. Therefore,
it is advisable to circumvent MessageFormat for messages without arguments.
resolveCodeWithoutArguments in class AbstractMessageSourcecode - the code of the message to resolvelocale - the locale to resolve the code for
(subclasses are encouraged to support internationalization)null if not foundAbstractMessageSource.resolveCode(java.lang.String, java.util.Locale),
MessageFormatprotected java.text.MessageFormat resolveCode(java.lang.String code,
java.util.Locale locale)
AbstractMessageSourceReturns a MessageFormat instance rather than a message String, to allow for appropriate caching of MessageFormats in subclasses.
Subclasses are encouraged to provide optimized resolution
for messages without arguments, not involving MessageFormat.
See the AbstractMessageSource.resolveCodeWithoutArguments(java.lang.String, java.util.Locale) javadoc for details.
resolveCode in class AbstractMessageSourcecode - the code of the message to resolvelocale - the locale to resolve the code for
(subclasses are encouraged to support internationalization)null if not foundAbstractMessageSource.resolveCodeWithoutArguments(String, java.util.Locale)public void addMessage(java.lang.String code,
java.util.Locale locale,
java.lang.String msg)
code - the lookup codelocale - the locale that the message should be found withinmsg - the message associated with this lookup codepublic void addMessages(java.util.Map<java.lang.String,java.lang.String> messages,
java.util.Locale locale)
messages - the messages to register, with messages codes
as keys and message texts as valueslocale - the locale that the messages should be found withinpublic java.lang.String toString()
toString in class java.lang.Object