public abstract class AbstractMessageSource extends java.lang.Object implements MessageSource
Modifier and Type | Field and Description |
---|---|
protected static java.lang.Object[] |
EMPTY_OBJECT_ARGS |
protected static java.lang.String |
ERROR_ARGS_NULL |
protected static java.lang.String |
ERROR_KEY_BLANK |
protected static java.lang.String |
ERROR_LOCALE_NULL |
protected static java.lang.String |
ERROR_MESSAGE_NULL |
REF_KEY_END, REF_KEY_START
Constructor and Description |
---|
AbstractMessageSource() |
Modifier and Type | Method and Description |
---|---|
protected abstract java.lang.Object |
doResolveMessageValue(java.lang.String key,
java.util.Locale locale) |
protected java.lang.Object |
evalMessageWithArguments(java.lang.Object message,
java.util.Map<java.lang.String,java.lang.Object> args) |
protected java.lang.Object |
evalMessageWithArguments(java.lang.Object message,
java.lang.Object[] args) |
java.lang.String |
formatMessage(java.lang.String message,
java.util.List<?> args)
Formats the given message using supplied args to substitute placeholders.
|
java.lang.String |
formatMessage(java.lang.String message,
java.util.Map<java.lang.String,java.lang.Object> args)
Formats the given message using supplied args to substitute placeholders.
|
java.lang.String |
formatMessage(java.lang.String message,
java.lang.Object[] args)
Formats the given message using supplied args to substitute placeholders.
|
java.lang.String |
getMessage(java.lang.String key)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.List<?> args)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.List<?> args,
java.util.Locale locale)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.List<?> args,
java.util.Locale locale,
java.lang.String defaultMessage)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.List<?> args,
java.lang.String defaultMessage)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.Locale locale)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.Locale locale,
java.lang.String defaultMessage)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.Map<java.lang.String,java.lang.Object> args)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.Map<java.lang.String,java.lang.Object> args,
java.util.Locale locale)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.Map<java.lang.String,java.lang.Object> args,
java.util.Locale locale,
java.lang.String defaultMessage)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.util.Map<java.lang.String,java.lang.Object> args,
java.lang.String defaultMessage)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.lang.Object[] args)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.lang.Object[] args,
java.util.Locale locale)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.lang.Object[] args,
java.util.Locale locale,
java.lang.String defaultMessage)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.lang.Object[] args,
java.lang.String defaultMessage)
Try to resolve the message.
|
java.lang.String |
getMessage(java.lang.String key,
java.lang.String defaultMessage)
Try to resolve the message.
|
java.lang.Object |
resolveMessageValue(java.lang.String key,
java.util.Locale locale)
Resolve a message given a key and a Locale.
|
protected java.lang.Object[] |
toObjectArray(java.util.List<?> args) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
asResourceBundle
protected static final java.lang.String ERROR_KEY_BLANK
protected static final java.lang.String ERROR_LOCALE_NULL
protected static final java.lang.String ERROR_ARGS_NULL
protected static final java.lang.String ERROR_MESSAGE_NULL
protected static final java.lang.Object[] EMPTY_OBJECT_ARGS
@Nonnull public java.lang.String getMessage(@Nonnull java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.lang.Object[] args, @Nonnull java.util.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.List<?> args, @Nonnull java.util.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nullable java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.Locale locale, @Nullable java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.lang.Object[] args, @Nullable java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.lang.Object[] args, @Nonnull java.util.Locale locale, @Nullable java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.List<?> args, @Nullable java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.List<?> args, @Nonnull java.util.Locale locale, @Nullable java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.Map<java.lang.String,java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.Map<java.lang.String,java.lang.Object> args, @Nonnull java.util.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.Map<java.lang.String,java.lang.Object> args, @Nullable java.lang.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 java.lang.String getMessage(@Nonnull java.lang.String key, @Nonnull java.util.Map<java.lang.String,java.lang.Object> args, @Nonnull java.util.Locale locale, @Nullable java.lang.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 java.lang.Object resolveMessageValue(@Nonnull java.lang.String key, @Nonnull java.util.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 java.lang.String formatMessage(@Nonnull java.lang.String message, @Nonnull java.util.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 java.lang.String formatMessage(@Nonnull java.lang.String message, @Nonnull java.lang.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 java.lang.String formatMessage(@Nonnull java.lang.String message, @Nonnull java.util.Map<java.lang.String,java.lang.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 java.lang.Object doResolveMessageValue(@Nonnull java.lang.String key, @Nonnull java.util.Locale locale) throws NoSuchMessageException
NoSuchMessageException
@Nullable protected java.lang.Object evalMessageWithArguments(@Nonnull java.lang.Object message, @Nonnull java.lang.Object[] args)
@Nullable protected java.lang.Object evalMessageWithArguments(@Nonnull java.lang.Object message, @Nonnull java.util.Map<java.lang.String,java.lang.Object> args)
@Nonnull protected java.lang.Object[] toObjectArray(@Nonnull java.util.List<?> args)