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 Details

    • TemplatedMessageSource

      public TemplatedMessageSource()
  • Method Details

    • setParentMessageSource

      public void setParentMessageSource(org.springframework.context.MessageSource parent)
      Specified by:
      setParentMessageSource in interface org.springframework.context.HierarchicalMessageSource
    • getParentMessageSource

      public org.springframework.context.MessageSource getParentMessageSource()
      Specified by:
      getParentMessageSource in interface org.springframework.context.HierarchicalMessageSource
    • getMessage

      public String getMessage(String code, Object[] args, String defaultMessage, Locale locale)
      Specified by:
      getMessage in interface org.springframework.context.MessageSource
    • getMessage

      public String getMessage(String code, Object[] args, Locale locale) throws org.springframework.context.NoSuchMessageException
      Specified by:
      getMessage in interface org.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:
      getMessage in interface org.springframework.context.MessageSource
      Throws:
      org.springframework.context.NoSuchMessageException
    • getRegex

      public String getRegex()
      Get the configured regular expression.
      Returns:
      the regular expression
    • setRegex

      public void setRegex(String regex)
      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 the MessageSource to delegate to.

      If that object implements HierarchicalMessageSource then those methods will be supported by instances of this class as well.

      Parameters:
      delegate - the delegate message source to use