public class MessageSourceAccessor
extends java.lang.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,
java.util.Locale defaultLocale)
Create a new MessageSourceAccessor, using the given default locale.
|
Modifier and Type | Method and Description |
---|---|
protected java.util.Locale |
getDefaultLocale()
Return the default locale to use if no explicit locale has been given.
|
java.lang.String |
getMessage(MessageSourceResolvable resolvable)
Retrieve the given MessageSourceResolvable (e.g.
|
java.lang.String |
getMessage(MessageSourceResolvable resolvable,
java.util.Locale locale)
Retrieve the given MessageSourceResolvable (e.g.
|
java.lang.String |
getMessage(java.lang.String code)
Retrieve the message for the given code and the default Locale.
|
java.lang.String |
getMessage(java.lang.String code,
java.util.Locale locale)
Retrieve the message for the given code and the given Locale.
|
java.lang.String |
getMessage(java.lang.String code,
java.lang.Object[] args)
Retrieve the message for the given code and the default Locale.
|
java.lang.String |
getMessage(java.lang.String code,
java.lang.Object[] args,
java.util.Locale locale)
Retrieve the message for the given code and the given Locale.
|
java.lang.String |
getMessage(java.lang.String code,
java.lang.Object[] args,
java.lang.String defaultMessage)
Retrieve the message for the given code and the default Locale.
|
java.lang.String |
getMessage(java.lang.String code,
java.lang.Object[] args,
java.lang.String defaultMessage,
java.util.Locale locale)
Retrieve the message for the given code and the given Locale.
|
java.lang.String |
getMessage(java.lang.String code,
java.lang.String defaultMessage)
Retrieve the message for the given code and the default Locale.
|
java.lang.String |
getMessage(java.lang.String code,
java.lang.String defaultMessage,
java.util.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, java.util.Locale defaultLocale)
messageSource
- the MessageSource to wrapdefaultLocale
- the default locale to use for message accessprotected java.util.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 java.lang.String getMessage(java.lang.String code, java.lang.String defaultMessage)
code
- code of the messagedefaultMessage
- String to return if the lookup failspublic java.lang.String getMessage(java.lang.String code, java.lang.String defaultMessage, java.util.Locale locale)
code
- code of the messagedefaultMessage
- String to return if the lookup failslocale
- Locale in which to do lookuppublic java.lang.String getMessage(java.lang.String code, @Nullable java.lang.Object[] args, java.lang.String defaultMessage)
code
- code of the messageargs
- arguments for the message, or null
if nonedefaultMessage
- String to return if the lookup failspublic java.lang.String getMessage(java.lang.String code, @Nullable java.lang.Object[] args, java.lang.String defaultMessage, java.util.Locale locale)
code
- code of the messageargs
- arguments for the message, or null
if nonedefaultMessage
- String to return if the lookup failslocale
- Locale in which to do lookuppublic java.lang.String getMessage(java.lang.String code) throws NoSuchMessageException
code
- code of the messageNoSuchMessageException
- if not foundpublic java.lang.String getMessage(java.lang.String code, java.util.Locale locale) throws NoSuchMessageException
code
- code of the messagelocale
- Locale in which to do lookupNoSuchMessageException
- if not foundpublic java.lang.String getMessage(java.lang.String code, @Nullable java.lang.Object[] args) throws NoSuchMessageException
code
- code of the messageargs
- arguments for the message, or null
if noneNoSuchMessageException
- if not foundpublic java.lang.String getMessage(java.lang.String code, @Nullable java.lang.Object[] args, java.util.Locale locale) throws NoSuchMessageException
code
- code of the messageargs
- arguments for the message, or null
if nonelocale
- Locale in which to do lookupNoSuchMessageException
- if not foundpublic java.lang.String getMessage(MessageSourceResolvable resolvable) throws NoSuchMessageException
resolvable
- the MessageSourceResolvableNoSuchMessageException
- if not foundpublic java.lang.String getMessage(MessageSourceResolvable resolvable, java.util.Locale locale) throws NoSuchMessageException
resolvable
- the MessageSourceResolvablelocale
- Locale in which to do lookupNoSuchMessageException
- if not found