Package net.solarnetwork.support
Class TemplatedMessageSource
java.lang.Object
net.solarnetwork.support.TemplatedMessageSource
- All Implemented Interfaces:
org.springframework.context.HierarchicalMessageSource,org.springframework.context.MessageSource
public class TemplatedMessageSource
extends Object
implements org.springframework.context.MessageSource, org.springframework.context.HierarchicalMessageSource
Delegating
MessageSource that dynamically extracts a pre-configured
regular expression match 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
mapProperty['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 delegate message source.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.MessageSourcegetRegex()Get the configured regular expression.voidsetDelegate(org.springframework.context.MessageSource delegate) Set theMessageSourceto delegate to.voidsetParentMessageSource(org.springframework.context.MessageSource parent) voidSet the regular expression to match against message codes.
-
Constructor Details
-
TemplatedMessageSource
public TemplatedMessageSource()
-
-
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
-
getRegex
Get the configured regular expression.- Returns:
- the regular expression
-
setRegex
Set the regular expression to match against message codes.The regular expression must provide at least one capture group; all capture groups are combined into the final message code.
- Parameters:
regex- the regular expression to use
-
getDelegate
public org.springframework.context.MessageSource getDelegate()Get the delegate message source.- Returns:
- the delegate
-
setDelegate
public void setDelegate(org.springframework.context.MessageSource delegate) Set theMessageSourceto delegate to.If that object implements
HierarchicalMessageSourcethen those methods will be supported by instances of this class as well.- Parameters:
delegate- the delegate message source to use
-