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.MessageSourceExtension of theResourceBundleMessageSourcewhich automatically sets the proper locale from theInvocationContextand 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.StringPROFILE_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.StringgetDefaultLocaleCode()java.util.Map<java.lang.String,java.util.Locale>getEnabledLocales()java.util.LocalegetLocale()static java.util.LocalegetLocale(java.util.Locale fallback)java.lang.StringgetLocaleCode()java.lang.StringgetMessage(java.lang.String code, java.lang.Object... args)java.lang.StringgetMessageNullArg(java.lang.String code, java.lang.Object... args)If any of the arguments is null, then empty string is returnedjava.lang.StringgetMessageUnsafe(java.lang.String code, java.lang.Object... args)java.util.Map<java.lang.String,java.util.Locale>getSupportedLocales()java.lang.StringgetYesNo(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:
getMessageUnsafein interfacepl.edu.icm.unity.MessageSource
-
getMessage
public java.lang.String getMessage(java.lang.String code, java.lang.Object... args)- Specified by:
getMessagein 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:
getMessageNullArgin interfacepl.edu.icm.unity.MessageSource- Parameters:
code-args-- Returns:
-
getYesNo
public java.lang.String getYesNo(boolean value)
- Specified by:
getYesNoin interfacepl.edu.icm.unity.MessageSource
-
getLocale
public java.util.Locale getLocale()
- Specified by:
getLocalein interfacepl.edu.icm.unity.MessageSource
-
getEnabledLocales
public java.util.Map<java.lang.String,java.util.Locale> getEnabledLocales()
- Specified by:
getEnabledLocalesin interfacepl.edu.icm.unity.MessageSource
-
getDefaultLocaleCode
public java.lang.String getDefaultLocaleCode()
- Specified by:
getDefaultLocaleCodein interfacepl.edu.icm.unity.MessageSource
-
getLocaleCode
public java.lang.String getLocaleCode()
- Specified by:
getLocaleCodein 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:
getSupportedLocalesin interfacepl.edu.icm.unity.MessageSource
-
-