Class UnityMessageSource

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.context.HierarchicalMessageSource, org.springframework.context.MessageSource, org.springframework.context.ResourceLoaderAware, pl.edu.icm.unity.MessageSource

    @Component
    public class UnityMessageSource
    extends org.springframework.context.support.ReloadableResourceBundleMessageSource
    implements pl.edu.icm.unity.MessageSource
    Extension of the ResourceBundleMessageSource which automatically sets the proper locale from the InvocationContext and allows for an easier invocation using varargs. It also sets UTF-8 encoding and disables platform's locale fallback.

    Another improvement is loading of messages from all classpath resources which are under messages/per-module-id/messages.properties path and from a respective file which is under configured i18n location in the same subdirectory as the per-module-id from classpath.

    Author:
    K. Benedyczak
    • 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
      static java.lang.String PROFILE_FAIL_ON_MISSING  
      • Fields inherited from class org.springframework.context.support.MessageSourceSupport

        logger
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getDefaultLocaleCode()  
      java.util.Map<java.lang.String,​java.util.Locale> getEnabledLocales()  
      java.util.Locale getLocale()  
      static java.util.Locale getLocale​(java.util.Locale fallback)  
      java.lang.String getLocaleCode()  
      java.lang.String getMessage​(java.lang.String code, java.lang.Object... args)  
      java.lang.String getMessageNullArg​(java.lang.String code, java.lang.Object... args)
      If any of the arguments is null, then empty string is returned
      java.lang.String getMessageUnsafe​(java.lang.String code, java.lang.Object... args)  
      java.util.Map<java.lang.String,​java.util.Locale> getSupportedLocales()  
      java.lang.String getYesNo​(boolean value)  
      • Methods inherited from class org.springframework.context.support.ReloadableResourceBundleMessageSource

        calculateAllFilenames, calculateFilenamesForLocale, clearCache, clearCacheIncludingAncestors, getMergedProperties, getProperties, loadProperties, newProperties, refreshProperties, resolveCode, resolveCodeWithoutArguments, setConcurrentRefresh, setFileEncodings, setPropertiesPersister, setResourceLoader, toString
      • Methods inherited from class org.springframework.context.support.AbstractResourceBasedMessageSource

        addBasenames, getBasenameSet, getCacheMillis, getDefaultEncoding, isFallbackToSystemLocale, setBasename, setBasenames, setCacheMillis, setCacheSeconds, setDefaultEncoding, 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
      • Methods inherited from interface org.springframework.context.MessageSource

        getMessage, getMessage, getMessage
    • Field Detail

      • PROFILE_FAIL_ON_MISSING

        public static final java.lang.String PROFILE_FAIL_ON_MISSING
        See Also:
        Constant Field Values
    • Constructor Detail

      • UnityMessageSource

        @Autowired
        public UnityMessageSource​(UnityServerConfiguration config,
                                  org.springframework.core.env.Environment springEnv)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • UnityMessageSource

        public UnityMessageSource​(UnityServerConfiguration config,
                                  boolean failOnMissing)
                           throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getMessageUnsafe

        public java.lang.String getMessageUnsafe​(java.lang.String code,
                                                 java.lang.Object... args)
        Specified by:
        getMessageUnsafe in interface pl.edu.icm.unity.MessageSource
      • getMessage

        public java.lang.String getMessage​(java.lang.String code,
                                           java.lang.Object... args)
        Specified by:
        getMessage in interface pl.edu.icm.unity.MessageSource
      • getMessageNullArg

        public java.lang.String getMessageNullArg​(java.lang.String code,
                                                  java.lang.Object... args)
        If any of the arguments is null, then empty string is returned
        Specified by:
        getMessageNullArg in interface pl.edu.icm.unity.MessageSource
        Parameters:
        code -
        args -
        Returns:
      • getYesNo

        public java.lang.String getYesNo​(boolean value)
        Specified by:
        getYesNo in interface pl.edu.icm.unity.MessageSource
      • getLocale

        public java.util.Locale getLocale()
        Specified by:
        getLocale in interface pl.edu.icm.unity.MessageSource
      • getEnabledLocales

        public java.util.Map<java.lang.String,​java.util.Locale> getEnabledLocales()
        Specified by:
        getEnabledLocales in interface pl.edu.icm.unity.MessageSource
      • getDefaultLocaleCode

        public java.lang.String getDefaultLocaleCode()
        Specified by:
        getDefaultLocaleCode in interface pl.edu.icm.unity.MessageSource
      • getLocaleCode

        public java.lang.String getLocaleCode()
        Specified by:
        getLocaleCode in interface pl.edu.icm.unity.MessageSource
      • getLocale

        public static java.util.Locale getLocale​(java.util.Locale fallback)
      • getSupportedLocales

        public java.util.Map<java.lang.String,​java.util.Locale> getSupportedLocales()
        Specified by:
        getSupportedLocales in interface pl.edu.icm.unity.MessageSource