org.springframework.context.support
Class MessageSourceAccessor


public class 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.

Author:
Juergen Hoeller
Since: 23.10.2003
See Also: ApplicationObjectSupport.getMessageSourceAccessor()

Constructor Summary
MessageSourceAccessor(MessageSource messageSource)
          Create a new MessageSourceAccessor, using the system Locale as default Locale.
MessageSourceAccessor(MessageSource messageSource, Locale defaultLocale)
          Create a new MessageSourceAccessor, using the given default locale.

Method Summary
 StringgetMessage(String code, String defaultMessage)
          Retrieve the message for the given code and the default Locale.
 StringgetMessage(String code, String defaultMessage, Locale locale)
          Retrieve the message for the given code and the given Locale.
 StringgetMessage(String code, Object[] args, String defaultMessage)
          Retrieve the message for the given code and the default Locale.
 StringgetMessage(String code, Object[] args, String defaultMessage, Locale locale)
          Retrieve the message for the given code and the given Locale.
 StringgetMessage(String code)
          Retrieve the message for the given code and the default Locale.
 StringgetMessage(String code, Locale locale)
          Retrieve the message for the given code and the given Locale.
 StringgetMessage(String code, Object[] args)
          Retrieve the message for the given code and the default Locale.
 StringgetMessage(String code, Object[] args, Locale locale)
          Retrieve the message for the given code and the given Locale.
 StringgetMessage(MessageSourceResolvable resolvable)
          Retrieve the given MessageSourceResolvable (e.g.
 StringgetMessage(MessageSourceResolvable resolvable, Locale locale)
          Retrieve the given MessageSourceResolvable (e.g.

Constructor Detail

MessageSourceAccessor

public MessageSourceAccessor(MessageSource messageSource)
Create a new MessageSourceAccessor, using the system Locale as default Locale.
Parameters:
messageSource - the MessageSource to wrap

MessageSourceAccessor

public MessageSourceAccessor(MessageSource messageSource, Locale defaultLocale)
Create a new MessageSourceAccessor, using the given default locale.
Parameters:
messageSource - the MessageSource to wrap
defaultLocale - the default locale to use for message access
Method Detail

getMessage

public String getMessage(String code, String defaultMessage)
Retrieve the message for the given code and the default Locale.
Parameters:
code - code of the message
defaultMessage - String to return if the lookup fails
Returns: the message

getMessage

public String getMessage(String code, String defaultMessage, Locale locale)
Retrieve the message for the given code and the given Locale.
Parameters:
code - code of the message
defaultMessage - String to return if the lookup fails
locale - Locale in which to do lookup
Returns: the message

getMessage

public String getMessage(String code, Object[] args, String defaultMessage)
Retrieve the message for the given code and the default Locale.
Parameters:
code - code of the message
args - arguments for the message, or null if none
defaultMessage - String to return if the lookup fails
Returns: the message

getMessage

public String getMessage(String code, Object[] args, String defaultMessage, Locale locale)
Retrieve the message for the given code and the given Locale.
Parameters:
code - code of the message
args - arguments for the message, or null if none
defaultMessage - String to return if the lookup fails
locale - Locale in which to do lookup
Returns: the message

getMessage

public String getMessage(String code)
throws org.springframework.context.NoSuchMessageException
Retrieve the message for the given code and the default Locale.
Parameters:
code - code of the message
Returns: the message
Throws:
org.springframework.context.NoSuchMessageException - if not found

getMessage

public String getMessage(String code, Locale locale)
throws org.springframework.context.NoSuchMessageException
Retrieve the message for the given code and the given Locale.
Parameters:
code - code of the message
locale - Locale in which to do lookup
Returns: the message
Throws:
org.springframework.context.NoSuchMessageException - if not found

getMessage

public String getMessage(String code, Object[] args)
throws org.springframework.context.NoSuchMessageException
Retrieve the message for the given code and the default Locale.
Parameters:
code - code of the message
args - arguments for the message, or null if none
Returns: the message
Throws:
org.springframework.context.NoSuchMessageException - if not found

getMessage

public String getMessage(String code, Object[] args, Locale locale)
throws org.springframework.context.NoSuchMessageException
Retrieve the message for the given code and the given Locale.
Parameters:
code - code of the message
args - arguments for the message, or null if none
locale - Locale in which to do lookup
Returns: the message
Throws:
org.springframework.context.NoSuchMessageException - if not found

getMessage

public String getMessage(MessageSourceResolvable resolvable)
throws org.springframework.context.NoSuchMessageException
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance) in the default Locale.
Parameters:
resolvable - the MessageSourceResolvable
Returns: the message
Throws:
org.springframework.context.NoSuchMessageException - if not found

getMessage

public String getMessage(MessageSourceResolvable resolvable, Locale locale)
throws org.springframework.context.NoSuchMessageException
Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance) in the given Locale.
Parameters:
resolvable - the MessageSourceResolvable
locale - Locale in which to do lookup
Returns: the message
Throws:
org.springframework.context.NoSuchMessageException - if not found

Association Links

to Class org.springframework.context.MessageSource

to Class java.util.Locale