public class MessageSourceDecorator extends Object implements MessageSource
REF_KEY_END, REF_KEY_START
Constructor and Description |
---|
MessageSourceDecorator(MessageSource delegate) |
Modifier and Type | Method and Description |
---|---|
ResourceBundle |
asResourceBundle()
Offers a view of this
MessageSource as a ResourceBundle . |
String |
formatMessage(String message,
List<?> args)
Formats the given message using supplied args to substitute placeholders.
|
String |
formatMessage(String message,
Map<String,Object> args)
Formats the given message using supplied args to substitute placeholders.
|
String |
formatMessage(String message,
Object[] args)
Formats the given message using supplied args to substitute placeholders.
|
protected MessageSource |
getDelegate() |
String |
getMessage(String key)
Try to resolve the message.
|
String |
getMessage(String key,
List<?> args)
Try to resolve the message.
|
String |
getMessage(String key,
List<?> args,
Locale locale)
Try to resolve the message.
|
String |
getMessage(String key,
List<?> args,
Locale locale,
String defaultMessage)
Try to resolve the message.
|
String |
getMessage(String key,
List<?> args,
String defaultMessage)
Try to resolve the message.
|
String |
getMessage(String key,
Locale locale)
Try to resolve the message.
|
String |
getMessage(String key,
Locale locale,
String defaultMessage)
Try to resolve the message.
|
String |
getMessage(String key,
Map<String,Object> args)
Try to resolve the message.
|
String |
getMessage(String key,
Map<String,Object> args,
Locale locale)
Try to resolve the message.
|
String |
getMessage(String key,
Map<String,Object> args,
Locale locale,
String defaultMessage)
Try to resolve the message.
|
String |
getMessage(String key,
Map<String,Object> args,
String defaultMessage)
Try to resolve the message.
|
String |
getMessage(String key,
Object[] args)
Try to resolve the message.
|
String |
getMessage(String key,
Object[] args,
Locale locale)
Try to resolve the message.
|
String |
getMessage(String key,
Object[] args,
Locale locale,
String defaultMessage)
Try to resolve the message.
|
String |
getMessage(String key,
Object[] args,
String defaultMessage)
Try to resolve the message.
|
String |
getMessage(String key,
String defaultMessage)
Try to resolve the message.
|
Object |
resolveMessageValue(String key,
Locale locale)
Resolve a message given a key and a Locale.
|
public MessageSourceDecorator(@Nonnull MessageSource delegate)
@Nonnull protected MessageSource getDelegate()
@Nonnull public String getMessage(@Nonnull String key) throws NoSuchMessageException
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'NoSuchMessageException
- if no message is found@Nonnull public String formatMessage(@Nonnull String message, @Nonnull Object[] args)
MessageSource
formatMessage
in interface MessageSource
message
- The message following a predefined format.args
- Arguments that will be filled in for params within the message (params look like "{0}"
within a message, but this might differ between implementations), or null if none.@Nullable public String getMessage(@Nonnull String key, @Nonnull List<?> args, @Nonnull Locale locale, @Nullable String defaultMessage)
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{0}"
within a message, but this might differ between implementations), or null if none.locale
- Locale in which to lookupdefaultMessage
- Message to return if the lookup fails@Nonnull public String getMessage(@Nonnull String key, @Nonnull Object[] args, @Nonnull Locale locale) throws NoSuchMessageException
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{0}" within a
message, but this might differ between implementations), or null if none.locale
- Locale in which to lookupNoSuchMessageException
- if no message is found@Nonnull public String getMessage(@Nonnull String key, @Nonnull List<?> args) throws NoSuchMessageException
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{0}" within a
message, but this might differ between implementations), or null if none.NoSuchMessageException
- if no message is found@Nullable public String getMessage(@Nonnull String key, @Nonnull List<?> args, @Nullable String defaultMessage)
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{0}"
within a message, but this might differ between implementations), or null if none.defaultMessage
- Message to return if the lookup fails@Nullable public String getMessage(@Nonnull String key, @Nonnull Object[] args, @Nonnull Locale locale, @Nullable String defaultMessage)
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{0}"
within a message, but this might differ between implementations), or null if none.locale
- Locale in which to lookupdefaultMessage
- Message to return if the lookup fails@Nonnull public String formatMessage(@Nonnull String message, @Nonnull List<?> args)
MessageSource
formatMessage
in interface MessageSource
message
- The message following a predefined format.args
- Arguments that will be filled in for params within the message (params look like "{0}"
within a message, but this might differ between implementations), or null if none.@Nonnull public String formatMessage(@Nonnull String message, @Nonnull Map<String,Object> args)
MessageSource
formatMessage
in interface MessageSource
message
- The message following a predefined format.args
- Arguments that will be filled in for params within the message (params look like "{:key}"
within a message, but this might differ between implementations), or null if none.@Nonnull public String getMessage(@Nonnull String key, @Nonnull Object[] args) throws NoSuchMessageException
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{0}" within a
message, but this might differ between implementations), or null if none.NoSuchMessageException
- if no message is found@Nullable public String getMessage(@Nonnull String key, @Nullable String defaultMessage)
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'defaultMessage
- Message to return if the lookup fails@Nullable public String getMessage(@Nonnull String key, @Nonnull Map<String,Object> args, @Nullable String defaultMessage)
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{:key}"
within a message, but this might differ between implementations), or null if none.defaultMessage
- Message to return if the lookup fails@Nonnull public String getMessage(@Nonnull String key, @Nonnull Locale locale) throws NoSuchMessageException
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'locale
- Locale in which to lookupNoSuchMessageException
- if no message is found@Nonnull public String getMessage(@Nonnull String key, @Nonnull Map<String,Object> args) throws NoSuchMessageException
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{:key}"
within a message, but this might differ between implementations), or null if none.NoSuchMessageException
- if no message is found@Nullable public String getMessage(@Nonnull String key, @Nonnull Locale locale, @Nullable String defaultMessage)
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'locale
- Locale in which to lookupdefaultMessage
- Message to return if the lookup fails@Nullable public String getMessage(@Nonnull String key, @Nonnull Object[] args, @Nullable String defaultMessage)
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{0}"
within a message, but this might differ between implementations), or null if none.defaultMessage
- Message to return if the lookup fails@Nonnull public String getMessage(@Nonnull String key, @Nonnull Map<String,Object> args, @Nonnull Locale locale) throws NoSuchMessageException
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{:key}"
within a message, but this might differ between implementations), or null if none.locale
- Locale in which to lookupNoSuchMessageException
- if no message is found@Nonnull public ResourceBundle asResourceBundle()
MessageSource
MessageSource
as a ResourceBundle
.asResourceBundle
in interface MessageSource
ResourceBundle
containing the keys this MessageSource
can resolve.@Nullable public String getMessage(@Nonnull String key, @Nonnull Map<String,Object> args, @Nonnull Locale locale, @Nullable String defaultMessage)
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{:key}"
within a message, but this might differ between implementations), or null if none.locale
- Locale in which to lookupdefaultMessage
- Message to return if the lookup fails@Nonnull public String getMessage(@Nonnull String key, @Nonnull List<?> args, @Nonnull Locale locale) throws NoSuchMessageException
MessageSource
getMessage
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'args
- Arguments that will be filled in for params within the message (params look like "{0}" within a
message, but this might differ between implementations), or null if none.locale
- Locale in which to lookupNoSuchMessageException
- if no message is found@Nonnull public Object resolveMessageValue(@Nonnull String key, @Nonnull Locale locale) throws NoSuchMessageException
MessageSource
Resolve a message given a key and a Locale.
This method should use the default Locale if the locale argument is null. The key
argument may refer to
another key if the resolved value results in a CharSequence
that begins with "@[" and ends with "]". In this
case the method will use the enclosed value as the next key to be resolved. For example, given the following key/value
definitions
some.key = Hello {0} other.key = @[some.key]Evaluating the keys results in
assert resolveMessageValue('some.key', Locale.default) == 'Hello {0}' assert resolveMessageValue('other.key', Locale.default) == 'Hello {0}'
resolveMessageValue
in interface MessageSource
key
- Key to lookup, such as 'log4j.appenders.console'locale
- Locale in which to lookupNoSuchMessageException
- if no message is found