Package pl.edu.icm.unity.engine.api.msg
Class UnityMessageSource
- java.lang.Object
-
- org.springframework.context.support.MessageSourceSupport
-
- org.springframework.context.support.AbstractMessageSource
-
- org.springframework.context.support.AbstractResourceBasedMessageSource
-
- org.springframework.context.support.ReloadableResourceBundleMessageSource
-
- pl.edu.icm.unity.engine.api.msg.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 theResourceBundleMessageSource
which automatically sets the proper locale from theInvocationContext
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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PROFILE_FAIL_ON_MISSING
-
Constructor Summary
Constructors Constructor Description UnityMessageSource(UnityServerConfiguration config, boolean failOnMissing)
UnityMessageSource(UnityServerConfiguration config, org.springframework.core.env.Environment springEnv)
-
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 returnedjava.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
-
-
-
-
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 interfacepl.edu.icm.unity.MessageSource
-
getMessage
public java.lang.String getMessage(java.lang.String code, java.lang.Object... args)
- Specified by:
getMessage
in interfacepl.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 interfacepl.edu.icm.unity.MessageSource
- Parameters:
code
-args
-- Returns:
-
getYesNo
public java.lang.String getYesNo(boolean value)
- Specified by:
getYesNo
in interfacepl.edu.icm.unity.MessageSource
-
getLocale
public java.util.Locale getLocale()
- Specified by:
getLocale
in interfacepl.edu.icm.unity.MessageSource
-
getEnabledLocales
public java.util.Map<java.lang.String,java.util.Locale> getEnabledLocales()
- Specified by:
getEnabledLocales
in interfacepl.edu.icm.unity.MessageSource
-
getDefaultLocaleCode
public java.lang.String getDefaultLocaleCode()
- Specified by:
getDefaultLocaleCode
in interfacepl.edu.icm.unity.MessageSource
-
getLocaleCode
public java.lang.String getLocaleCode()
- Specified by:
getLocaleCode
in interfacepl.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 interfacepl.edu.icm.unity.MessageSource
-
-