Class BroadleafMergeResourceBundleMessageSource

java.lang.Object
org.springframework.context.support.MessageSourceSupport
org.springframework.context.support.AbstractMessageSource
org.springframework.context.support.AbstractResourceBasedMessageSource
org.springframework.context.support.ReloadableResourceBundleMessageSource
org.broadleafcommerce.common.util.BroadleafMergeResourceBundleMessageSource
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.HierarchicalMessageSource, org.springframework.context.MessageSource, org.springframework.context.ResourceLoaderAware

public class BroadleafMergeResourceBundleMessageSource extends org.springframework.context.support.ReloadableResourceBundleMessageSource

Replaces the older BLResourceBundleMessageSource by using a ReloadableResourceBundleMessageSource instead. The main advantage of using this is the out-of-the-box ability to merge multiple property files together. There is one important difference: When there is a conflict for a property (declared in multiple files) this implementation assumes that the later one in the list takes precedence. This follows with normal Broadleaf assumptions that bean definitions declared later in the merge process win.

While this theoretically supports caching via the features provided in ReloadableResourceBundleMessageSource, this should not be used and instead should have cacheMillis always set to -1 (which is the default implementation). This ensures that codes are always obtained from a merged property list.

The basenames in this implementation are Spring path resources so if you need to refer to a resource on the classpath, these should be prefixed with classpath:. This is slightly different from the ResourceBundleMessageSource; see AbstractResourceBasedMessageSource.setBasenames(String...) for more information.

The BroadleafMergeResourceExtensionManager will get invoked first and return any resolved message from an implementing module.

Author:
Phillip Verheyden
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.context.support.ReloadableResourceBundleMessageSource

    org.springframework.context.support.ReloadableResourceBundleMessageSource.PropertiesHolder
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     

    Fields inherited from class org.springframework.context.support.MessageSourceSupport

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected MessageFormat
    resolveCode(String code, Locale locale)
     
    protected String
     
    void
    setBasenames(String... basenames)
    The super implementation ensures the basenames defined at the beginning take precedence.

    Methods inherited from class org.springframework.context.support.ReloadableResourceBundleMessageSource

    calculateAllFilenames, calculateFilenamesForLocale, clearCache, clearCacheIncludingAncestors, collectPropertiesToMerge, getMergedProperties, getProperties, loadProperties, mergeProperties, newProperties, refreshProperties, resolveResource, setConcurrentRefresh, setFileEncodings, setFileExtensions, setPropertiesPersister, setResourceLoader, toString

    Methods inherited from class org.springframework.context.support.AbstractResourceBasedMessageSource

    addBasenames, getBasenameSet, getCacheMillis, getDefaultEncoding, getDefaultLocale, isFallbackToSystemLocale, setBasename, setCacheMillis, setCacheSeconds, setDefaultEncoding, setDefaultLocale, setFallbackToSystemLocale

    Methods inherited from class org.springframework.context.support.AbstractMessageSource

    getCommonMessages, getDefaultMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessage

    Methods inherited from class org.springframework.context.support.MessageSourceSupport

    createMessageFormat, formatMessage, isAlwaysUseMessageFormat, renderDefaultMessage, setAlwaysUseMessageFormat

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • BroadleafMergeResourceBundleMessageSource

      public BroadleafMergeResourceBundleMessageSource()
  • Method Details

    • setBasenames

      public void setBasenames(String... basenames)
      The super implementation ensures the basenames defined at the beginning take precedence. We require the opposite in order to be in line with previous assumptions about the applicationContext merge process (meaning, beans defined in later applicationContexts take precedence). Thus, this reverses basenames before passing it up to the super implementation.
      Overrides:
      setBasenames in class org.springframework.context.support.AbstractResourceBasedMessageSource
      Parameters:
      basenames -
    • resolveCode

      protected MessageFormat resolveCode(String code, Locale locale)
      Overrides:
      resolveCode in class org.springframework.context.support.ReloadableResourceBundleMessageSource
    • resolveCodeWithoutArguments

      protected String resolveCodeWithoutArguments(String code, Locale locale)
      Overrides:
      resolveCodeWithoutArguments in class org.springframework.context.support.ReloadableResourceBundleMessageSource