Class PluginAwareResourceBundleMessageSource

  • All Implemented Interfaces:
    GrailsApplicationAware, PluginManagerAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.HierarchicalMessageSource, org.springframework.context.MessageSource, org.springframework.context.ResourceLoaderAware

    public class PluginAwareResourceBundleMessageSource
    extends ReloadableResourceBundleMessageSource
    implements GrailsApplicationAware, PluginManagerAware, org.springframework.beans.factory.InitializingBean
    A ReloadableResourceBundleMessageSource that is capable of loading message sources from plugins.
    Since:
    1.1
    • Field Detail

      • pluginBaseNames

        protected java.util.List<java.lang.String> pluginBaseNames
    • Constructor Detail

      • PluginAwareResourceBundleMessageSource

        public PluginAwareResourceBundleMessageSource()
    • Method Detail

      • setResourceResolver

        public void setResourceResolver​(org.springframework.core.io.support.PathMatchingResourcePatternResolver resourceResolver)
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        java.lang.Exception
      • getMergedPluginProperties

        protected ReloadableResourceBundleMessageSource.PropertiesHolder getMergedPluginProperties​(java.util.Locale locale)
        Get a PropertiesHolder that contains the actually visible properties for a Locale, after merging all specified resource bundles. Either fetches the holder from the cache or freshly loads it.

        Only used when caching resource bundle contents forever, i.e. with cacheSeconds < 0. Therefore, merged properties are always cached forever.

      • resolveCodeWithoutArgumentsFromPlugins

        protected java.lang.String resolveCodeWithoutArgumentsFromPlugins​(java.lang.String code,
                                                                          java.util.Locale locale)
        Attempts to resolve a String for the code from the list of plugin base names
        Parameters:
        code - The code
        locale - The locale
        Returns:
        a MessageFormat
      • mergeBinaryPluginProperties

        protected void mergeBinaryPluginProperties​(java.util.Locale locale,
                                                   java.util.Properties mergedProps)
      • resolveCodeFromPlugins

        protected java.text.MessageFormat resolveCodeFromPlugins​(java.lang.String code,
                                                                 java.util.Locale locale)
        Attempts to resolve a MessageFormat for the code from the list of plugin base names
        Parameters:
        code - The code
        locale - The locale
        Returns:
        a MessageFormat
      • setResourceLoader

        public void setResourceLoader​(org.springframework.core.io.ResourceLoader resourceLoader)
        Description copied from class: ReloadableResourceBundleMessageSource
        Set the ResourceLoader to use for loading bundle properties files.

        The default is a DefaultResourceLoader. Will get overridden by the ApplicationContext if running in a context, as it implements the ResourceLoaderAware interface. Can be manually overridden when running outside of an ApplicationContext.

        Specified by:
        setResourceLoader in interface org.springframework.context.ResourceLoaderAware
        Overrides:
        setResourceLoader in class ReloadableResourceBundleMessageSource
        See Also:
        DefaultResourceLoader, ResourceLoaderAware
      • setPluginCacheSeconds

        public void setPluginCacheSeconds​(int pluginCacheSeconds)
        Set the number of seconds to cache the list of matching properties files loaded from plugin.
        • Default value is the same value as cacheSeconds
      • setSearchClasspath

        public void setSearchClasspath​(boolean searchClasspath)
        Whether to search the full classpath for message bundles. Enabling this will degrade startup performance. The default is to only search for message bundles relative to the application classes directory.
        Parameters:
        searchClasspath - True if the entire classpath should be searched
      • setMessageBundleLocationPattern

        public void setMessageBundleLocationPattern​(java.lang.String messageBundleLocationPattern)
        The location pattern for message bundles
        Parameters:
        messageBundleLocationPattern - The message bundle location pattern