public abstract class AbstractMessageSource extends Object implements MessageSource
Modifier and Type | Field and Description |
---|---|
protected static Object[] |
EMPTY_OBJECT_ARGS |
protected static String |
ERROR_ARGS_NULL |
protected static String |
ERROR_KEY_BLANK |
protected static String |
ERROR_LOCALE_NULL |
protected static String |
ERROR_MESSAGE_NULL |
REF_KEY_END, REF_KEY_START
Constructor and Description |
---|
AbstractMessageSource() |
Modifier and Type | Method and Description |
---|---|
protected abstract Object |
doResolveMessageValue(String key,
Locale locale) |
protected Object |
evalMessageWithArguments(Object message,
Map<String,Object> args) |
protected Object |
evalMessageWithArguments(Object message,
Object[] args) |
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.
|
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.
|
protected Object[] |
toObjectArray(List<?> args) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
asResourceBundle
protected static final String ERROR_KEY_BLANK
protected static final String ERROR_LOCALE_NULL
protected static final String ERROR_ARGS_NULL
protected static final String ERROR_MESSAGE_NULL
protected static final Object[] EMPTY_OBJECT_ARGS
@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 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 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@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@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@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 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@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@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 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 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@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@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@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 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@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 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.@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 protected abstract Object doResolveMessageValue(@Nonnull String key, @Nonnull Locale locale) throws NoSuchMessageException
NoSuchMessageException
@Nullable protected Object evalMessageWithArguments(@Nonnull Object message, @Nonnull Object[] args)
@Nullable protected Object evalMessageWithArguments(@Nonnull Object message, @Nonnull Map<String,Object> args)