Class MessageSourceAccessor
java.lang.Object
org.springframework.context.support.MessageSourceAccessor
Helper class for easy access to messages from a MessageSource,
 providing various overloaded getMessage methods.
 
Available from ApplicationObjectSupport, but also reusable as a standalone helper to delegate to in application objects.
- Since:
- 23.10.2003
- Author:
- Juergen Hoeller
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionMessageSourceAccessor(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.
- 
Method SummaryModifier and TypeMethodDescriptionprotected LocaleReturn the default locale to use if no explicit locale has been given.getMessage(String code) Retrieve the message for the given code and the default Locale.getMessage(String code, Object[] args) Retrieve the message for the given code and the default Locale.getMessage(String code, Object[] args, String defaultMessage) Retrieve the message for the given code and the default Locale.getMessage(String code, Object[] args, String defaultMessage, Locale locale) Retrieve the message for the given code and the given Locale.getMessage(String code, Object[] args, Locale locale) Retrieve the message for the given code and the given Locale.getMessage(String code, String defaultMessage) Retrieve the message for the given code and the default Locale.getMessage(String code, String defaultMessage, Locale locale) Retrieve the message for the given code and the given Locale.getMessage(String code, Locale locale) Retrieve the message for the given code and the given Locale.getMessage(MessageSourceResolvable resolvable) Retrieve the given MessageSourceResolvable (for example, an ObjectError instance) in the default Locale.getMessage(MessageSourceResolvable resolvable, Locale locale) Retrieve the given MessageSourceResolvable (for example, an ObjectError instance) in the given Locale.
- 
Constructor Details- 
MessageSourceAccessorCreate a new MessageSourceAccessor, using LocaleContextHolder's locale as default locale.- Parameters:
- messageSource- the MessageSource to wrap
- See Also:
 
- 
MessageSourceAccessorCreate a new MessageSourceAccessor, using the given default locale.- Parameters:
- messageSource- the MessageSource to wrap
- defaultLocale- the default locale to use for message access
 
 
- 
- 
Method Details- 
getDefaultLocaleReturn the default locale to use if no explicit locale has been given.The default implementation returns the default locale passed into the corresponding constructor, or LocaleContextHolder's locale as fallback. Can be overridden in subclasses. 
- 
getMessageRetrieve the message for the given code and the default Locale.- Parameters:
- code- the code of the message
- defaultMessage- the String to return if the lookup fails
- Returns:
- the message
 
- 
getMessageRetrieve the message for the given code and the given Locale.- Parameters:
- code- the code of the message
- defaultMessage- the String to return if the lookup fails
- locale- the Locale in which to do lookup
- Returns:
- the message
 
- 
getMessageRetrieve the message for the given code and the default Locale.- Parameters:
- code- the code of the message
- args- arguments for the message, or- nullif none
- defaultMessage- the String to return if the lookup fails
- Returns:
- the message
 
- 
getMessagepublic String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale) Retrieve the message for the given code and the given Locale.- Parameters:
- code- the code of the message
- args- arguments for the message, or- nullif none
- defaultMessage- the String to return if the lookup fails
- locale- the Locale in which to do lookup
- Returns:
- the message
 
- 
getMessageRetrieve the message for the given code and the default Locale.- Parameters:
- code- the code of the message
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessageRetrieve the message for the given code and the given Locale.- Parameters:
- code- the code of the message
- locale- the Locale in which to do lookup
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessageRetrieve the message for the given code and the default Locale.- Parameters:
- code- the code of the message
- args- arguments for the message, or- nullif none
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessagepublic String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException Retrieve the message for the given code and the given Locale.- Parameters:
- code- the code of the message
- args- arguments for the message, or- nullif none
- locale- the Locale in which to do lookup
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessageRetrieve the given MessageSourceResolvable (for example, an ObjectError instance) in the default Locale.- Parameters:
- resolvable- the MessageSourceResolvable
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
- 
getMessagepublic String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException Retrieve the given MessageSourceResolvable (for example, an ObjectError instance) in the given Locale.- Parameters:
- resolvable- the MessageSourceResolvable
- locale- the Locale in which to do lookup
- Returns:
- the message
- Throws:
- NoSuchMessageException- if not found
 
 
-