public interface MessageSource
Modifier and Type | Field and Description |
---|---|
static String |
REF_KEY_END
"]"
|
static String |
REF_KEY_START
"@["
|
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.
|
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.
|
static final String REF_KEY_START
static final String REF_KEY_END
@Nonnull String getMessage(@Nonnull String key) throws NoSuchMessageException
key
- Key to lookup, such as 'log4j.appenders.console'NoSuchMessageException
- if no message is found@Nonnull String getMessage(@Nonnull String key, @Nonnull Locale locale) throws NoSuchMessageException
key
- Key to lookup, such as 'log4j.appenders.console'locale
- Locale in which to lookupNoSuchMessageException
- if no message is found@Nonnull String getMessage(@Nonnull String key, @Nonnull Object[] args) throws NoSuchMessageException
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 String getMessage(@Nonnull String key, @Nonnull Object[] args, @Nonnull Locale locale) throws NoSuchMessageException
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 String getMessage(@Nonnull String key, @Nonnull List<?> args) throws NoSuchMessageException
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 String getMessage(@Nonnull String key, @Nonnull List<?> args, @Nonnull Locale locale) throws NoSuchMessageException
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 String getMessage(@Nonnull String key, @Nullable String defaultMessage)
key
- Key to lookup, such as 'log4j.appenders.console'defaultMessage
- Message to return if the lookup fails@Nullable String getMessage(@Nonnull String key, @Nonnull Locale locale, @Nullable String defaultMessage)
key
- Key to lookup, such as 'log4j.appenders.console'locale
- Locale in which to lookupdefaultMessage
- Message to return if the lookup fails@Nullable String getMessage(@Nonnull String key, @Nonnull Object[] args, @Nullable String defaultMessage)
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 String getMessage(@Nonnull String key, @Nonnull Object[] args, @Nonnull Locale locale, @Nullable String defaultMessage)
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 String getMessage(@Nonnull String key, @Nonnull List<?> args, @Nullable String defaultMessage)
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 String getMessage(@Nonnull String key, @Nonnull List<?> args, @Nonnull Locale locale, @Nullable String defaultMessage)
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 String getMessage(@Nonnull String key, @Nonnull Map<String,Object> args) throws NoSuchMessageException
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 String getMessage(@Nonnull String key, @Nonnull Map<String,Object> args, @Nonnull Locale locale) throws NoSuchMessageException
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 String getMessage(@Nonnull String key, @Nonnull Map<String,Object> args, @Nullable String defaultMessage)
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 String getMessage(@Nonnull String key, @Nonnull Map<String,Object> args, @Nonnull Locale locale, @Nullable String defaultMessage)
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 Object resolveMessageValue(@Nonnull String key, @Nonnull Locale locale) throws NoSuchMessageException
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}'
key
- Key to lookup, such as 'log4j.appenders.console'locale
- Locale in which to lookupNoSuchMessageException
- if no message is found@Nonnull String formatMessage(@Nonnull String message, @Nonnull List<?> args)
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 String formatMessage(@Nonnull String message, @Nonnull Object[] args)
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 String formatMessage(@Nonnull String message, @Nonnull Map<String,Object> args)
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 ResourceBundle asResourceBundle()
MessageSource
as a ResourceBundle
.ResourceBundle
containing the keys this MessageSource
can resolve.