Package net.solarnetwork.support
Class PrefixedMessageSource
java.lang.Object
net.solarnetwork.support.PrefixedMessageSource
- All Implemented Interfaces:
org.springframework.context.HierarchicalMessageSource,org.springframework.context.MessageSource
public class PrefixedMessageSource
extends Object
implements org.springframework.context.MessageSource, org.springframework.context.HierarchicalMessageSource
Delegating
MessageSource that dynamically removes a pre-configured
prefix from all message codes.
The inspiration for this class was to support messages for objects that might
be nested in other objects used in
SettingSpecifierProvider implementations.
When one provider proxies another, or uses nested bean paths, this class can
be used to dynamically re-map message codes. For example a code
delegate.url could be re-mapped to url.
- Since:
- 1.43
- Version:
- 1.0
- Author:
- matt
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.context.MessageSourceGet the singularMessageSourceto use with the singular prefix.Get the multi-prefix delegate mapping.getMessage(String code, Object[] args, String defaultMessage, Locale locale) getMessage(String code, Object[] args, Locale locale) getMessage(org.springframework.context.MessageSourceResolvable resolvable, Locale locale) org.springframework.context.MessageSourceGet the singular message code prefix to dynamically remove from all message codes.voidsetDelegate(org.springframework.context.MessageSource delegate) Set the singularMessageSourceto use with the singular prefix.voidsetDelegates(Map<String, org.springframework.context.MessageSource> delegates) Set the multi-prefix delegate mapping.voidsetParentMessageSource(org.springframework.context.MessageSource parent) voidSet the singular message code prefix to dynamically remove from all message codes.
-
Constructor Details
-
PrefixedMessageSource
public PrefixedMessageSource()
-
-
Method Details
-
setParentMessageSource
public void setParentMessageSource(org.springframework.context.MessageSource parent) - Specified by:
setParentMessageSourcein interfaceorg.springframework.context.HierarchicalMessageSource
-
getParentMessageSource
public org.springframework.context.MessageSource getParentMessageSource()- Specified by:
getParentMessageSourcein interfaceorg.springframework.context.HierarchicalMessageSource
-
getMessage
- Specified by:
getMessagein interfaceorg.springframework.context.MessageSource
-
getMessage
public String getMessage(String code, Object[] args, Locale locale) throws org.springframework.context.NoSuchMessageException - Specified by:
getMessagein interfaceorg.springframework.context.MessageSource- Throws:
org.springframework.context.NoSuchMessageException
-
getMessage
public String getMessage(org.springframework.context.MessageSourceResolvable resolvable, Locale locale) throws org.springframework.context.NoSuchMessageException - Specified by:
getMessagein interfaceorg.springframework.context.MessageSource- Throws:
org.springframework.context.NoSuchMessageException
-
getPrefix
Get the singular message code prefix to dynamically remove from all message codes.- Returns:
- the singular message code prefix
- See Also:
-
setPrefix
Set the singular message code prefix to dynamically remove from all message codes.This prefix will only be used with the singular delegate configured via
setDelegate(MessageSource).- Parameters:
prefix- the singular message code prefix- See Also:
-
getDelegate
public org.springframework.context.MessageSource getDelegate()Get the singularMessageSourceto use with the singular prefix.- Returns:
- the singular message source delegate
-
setDelegate
public void setDelegate(org.springframework.context.MessageSource delegate) Set the singularMessageSourceto use with the singular prefix.Note when this method is used, then messages found in this delegate under un-prefixed keys will be returned without consulting any parent source first.
- Parameters:
delegate- the singular delegate to use
-
getDelegates
Get the multi-prefix delegate mapping.- Returns:
- a mapping of message code prefixes to associated
MessageSourcedelegates
-
setDelegates
Set the multi-prefix delegate mapping.This configures any number of
MessageSourcedelegates to handle specific message codes with associated prefix values.- Parameters:
delegates- the message code prefix mapping
-