public class MessageSourceAccessor extends Object
Available from ApplicationObjectSupport, but also reusable as a standalone helper to delegate to in application objects.
ApplicationObjectSupport.getMessageSourceAccessor()
Constructor and Description |
---|
MessageSourceAccessor(MessageSource messageSource)
Create a new MessageSourceAccessor, using LocaleContextHolder's locale
as default locale.
|
MessageSourceAccessor(MessageSource messageSource,
Locale defaultLocale)
Create a new MessageSourceAccessor, using the given default locale.
|
Modifier and Type | Method and Description |
---|---|
protected Locale |
getDefaultLocale()
Return the default locale to use if no explicit locale has been given.
|
String |
getMessage(MessageSourceResolvable resolvable)
Retrieve the given MessageSourceResolvable (e.g.
|
String |
getMessage(MessageSourceResolvable resolvable,
Locale locale)
Retrieve the given MessageSourceResolvable (e.g.
|
String |
getMessage(String code)
Retrieve the message for the given code and the default Locale.
|
String |
getMessage(String code,
Locale locale)
Retrieve the message for the given code and the given Locale.
|
String |
getMessage(String code,
Object[] args)
Retrieve the message for the given code and the default Locale.
|
String |
getMessage(String code,
Object[] args,
Locale locale)
Retrieve the message for the given code and the given Locale.
|
String |
getMessage(String code,
Object[] args,
String defaultMessage)
Retrieve the message for the given code and the default Locale.
|
String |
getMessage(String code,
Object[] args,
String defaultMessage,
Locale locale)
Retrieve the message for the given code and the given Locale.
|
String |
getMessage(String code,
String defaultMessage)
Retrieve the message for the given code and the default Locale.
|
String |
getMessage(String code,
String defaultMessage,
Locale locale)
Retrieve the message for the given code and the given Locale.
|
public MessageSourceAccessor(MessageSource messageSource)
messageSource
- the MessageSource to wrapLocaleContextHolder.getLocale()
public MessageSourceAccessor(MessageSource messageSource, Locale defaultLocale)
messageSource
- the MessageSource to wrapdefaultLocale
- the default locale to use for message accessprotected Locale getDefaultLocale()
The default implementation returns the default locale passed into the corresponding constructor, or LocaleContextHolder's locale as fallback. Can be overridden in subclasses.
public String getMessage(String code, String defaultMessage)
code
- the code of the messagedefaultMessage
- the String to return if the lookup failspublic String getMessage(String code, String defaultMessage, Locale locale)
code
- the code of the messagedefaultMessage
- the String to return if the lookup failslocale
- the Locale in which to do lookuppublic String getMessage(String code, @Nullable Object[] args, String defaultMessage)
code
- the code of the messageargs
- arguments for the message, or null
if nonedefaultMessage
- the String to return if the lookup failspublic String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale)
code
- the code of the messageargs
- arguments for the message, or null
if nonedefaultMessage
- the String to return if the lookup failslocale
- the Locale in which to do lookuppublic String getMessage(String code) throws NoSuchMessageException
code
- the code of the messageNoSuchMessageException
- if not foundpublic String getMessage(String code, Locale locale) throws NoSuchMessageException
code
- the code of the messagelocale
- the Locale in which to do lookupNoSuchMessageException
- if not foundpublic String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException
code
- the code of the messageargs
- arguments for the message, or null
if noneNoSuchMessageException
- if not foundpublic String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException
code
- the code of the messageargs
- arguments for the message, or null
if nonelocale
- the Locale in which to do lookupNoSuchMessageException
- if not foundpublic String getMessage(MessageSourceResolvable resolvable) throws NoSuchMessageException
resolvable
- the MessageSourceResolvableNoSuchMessageException
- if not foundpublic String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException
resolvable
- the MessageSourceResolvablelocale
- the Locale in which to do lookupNoSuchMessageException
- if not found