Package org.alfresco.repo.i18n
Class MessageServiceImpl
- java.lang.Object
-
- org.alfresco.repo.i18n.MessageServiceImpl
-
- All Implemented Interfaces:
MessageService,org.alfresco.repo.tenant.TenantDeployer,org.alfresco.service.cmr.i18n.MessageLookup
public class MessageServiceImpl extends java.lang.Object implements MessageService
Message Service to get localised messages/strings which have been loaded from resource bundles either dynamically deployed in the Repository and/or statically loaded from the Classpath. Also provides methods (delegated to core utility class) to access the Locale of the current thread.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROPERTIES_FILE_SUFFIX
-
Constructor Summary
Constructors Constructor Description MessageServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()java.lang.StringgetBaseBundleName(java.lang.String resourceName)java.util.LocalegetContentLocale()Get the content local for the current thread.
This will revert toMessageService.getLocale()if no value has been defined.java.util.LocalegetLocale()Get the general local for the current thread, will revert to the default locale if none specified for this thread.java.lang.StringgetMessage(java.lang.String messageKey)java.lang.StringgetMessage(java.lang.String messageKey, java.lang.Object... params)java.lang.StringgetMessage(java.lang.String messageKey, java.util.Locale locale)java.lang.StringgetMessage(java.lang.String messageKey, java.util.Locale locale, java.lang.Object... params)java.util.LocalegetNearestLocale(java.util.Locale templateLocale, java.util.Set<java.util.Locale> options)Searches for the nearest locale from the available options.protected org.alfresco.service.cmr.repository.NodeRefgetNode(org.alfresco.service.cmr.repository.NodeRef rootNodeRef, java.lang.String path)java.util.Set<java.lang.String>getRegisteredBundles()Get set of registered message resource bundlesjava.util.ResourceBundlegetRepoResourceBundle(org.alfresco.service.cmr.repository.StoreRef storeRef, java.lang.String path, java.util.Locale locale)Get message resource bundle from the repository note: also used by Web Client (ResourceBundleWrapper)voidinit()voidonDisableTenant()voidonEnableTenant()java.util.LocaleparseLocale(java.lang.String localeStr)Factory method to create a Locale from a lang_country_variant string.voidregister(MessageDeployer messageDeployer)Register message deployer with message servicevoidregisterResourceBundle(java.lang.String resBundlePath)Register a resource bundle.voidreset()Resets the message serviceprotected org.alfresco.service.cmr.repository.NodeRefresolveQNamePath(org.alfresco.service.cmr.repository.NodeRef rootNodeRef, java.lang.String[] pathPrefixQNameStrings)voidsetContentLocale(java.util.Locale locale)Set the content locale for the current thread.voidsetContentService(ContentService contentService)voidsetLoadedResourceBundlesCache(org.alfresco.repo.cache.SimpleCache<java.lang.String,java.util.Map<java.util.Locale,java.util.Set<java.lang.String>>> loadedResourceBundlesCache)voidsetLocale(java.util.Locale locale)Set the locale for the current thread.voidsetMessagesCache(org.alfresco.repo.cache.SimpleCache<java.lang.String,java.util.Map<java.util.Locale,java.util.Map<java.lang.String,java.lang.String>>> messagesCache)voidsetNamespaceService(org.alfresco.service.namespace.NamespaceService namespaceService)voidsetNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)voidsetResourceBundleBaseNamesCache(org.alfresco.repo.cache.SimpleCache<java.lang.String,java.util.Set<java.lang.String>> resourceBundleBaseNamesCache)voidsetTenantService(org.alfresco.repo.tenant.TenantService tenantService)voidsetTryLockTimeout(long tryLockTimeout)voidunregisterResourceBundle(java.lang.String resBundlePath)Unregister a resource bundle
-
-
-
Field Detail
-
PROPERTIES_FILE_SUFFIX
public static final java.lang.String PROPERTIES_FILE_SUFFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
setNamespaceService
public void setNamespaceService(org.alfresco.service.namespace.NamespaceService namespaceService)
-
setNodeService
public void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)
-
setTenantService
public void setTenantService(org.alfresco.repo.tenant.TenantService tenantService)
-
setContentService
public void setContentService(ContentService contentService)
-
setResourceBundleBaseNamesCache
public void setResourceBundleBaseNamesCache(org.alfresco.repo.cache.SimpleCache<java.lang.String,java.util.Set<java.lang.String>> resourceBundleBaseNamesCache)
-
setLoadedResourceBundlesCache
public void setLoadedResourceBundlesCache(org.alfresco.repo.cache.SimpleCache<java.lang.String,java.util.Map<java.util.Locale,java.util.Set<java.lang.String>>> loadedResourceBundlesCache)
-
setMessagesCache
public void setMessagesCache(org.alfresco.repo.cache.SimpleCache<java.lang.String,java.util.Map<java.util.Locale,java.util.Map<java.lang.String,java.lang.String>>> messagesCache)
-
setTryLockTimeout
public void setTryLockTimeout(long tryLockTimeout)
-
setLocale
public void setLocale(java.util.Locale locale)
Description copied from interface:MessageServiceSet the locale for the current thread.- Specified by:
setLocalein interfaceMessageService- Parameters:
locale- the locale
-
getLocale
public java.util.Locale getLocale()
Description copied from interface:MessageServiceGet the general local for the current thread, will revert to the default locale if none specified for this thread.- Specified by:
getLocalein interfaceMessageService- Returns:
- the general locale
-
setContentLocale
public void setContentLocale(java.util.Locale locale)
Description copied from interface:MessageServiceSet the content locale for the current thread.- Specified by:
setContentLocalein interfaceMessageService- Parameters:
locale- the content locale
-
getContentLocale
public java.util.Locale getContentLocale()
Description copied from interface:MessageServiceGet the content local for the current thread.
This will revert toMessageService.getLocale()if no value has been defined.- Specified by:
getContentLocalein interfaceMessageService- Returns:
- Returns the content locale
-
getNearestLocale
public java.util.Locale getNearestLocale(java.util.Locale templateLocale, java.util.Set<java.util.Locale> options)Description copied from interface:MessageServiceSearches for the nearest locale from the available options. To match any locale, pass in null.- Specified by:
getNearestLocalein interfaceMessageService- Parameters:
templateLocale- the template to search for or null to match any localeoptions- the available locales to search from- Returns:
- Returns the best match from the available options, or the null if all matches fail
-
parseLocale
public java.util.Locale parseLocale(java.lang.String localeStr)
Description copied from interface:MessageServiceFactory method to create a Locale from a lang_country_variant string.- Specified by:
parseLocalein interfaceMessageService- Parameters:
localeStr- e.g. fr_FR- Returns:
- Returns the locale instance, or the
defaultif the string is invalid
-
registerResourceBundle
public void registerResourceBundle(java.lang.String resBundlePath)
Description copied from interface:MessageServiceRegister a resource bundle.This should be the bundle base path eg, alfresco/messages/errors or, workspace://SpaceStore/app:company_home/app:dictionary/app:labels/cm:errors
Once registered the messages will be available via getMessage, assuming the bundle resource exists at the given path location.
- Specified by:
registerResourceBundlein interfaceMessageService- Parameters:
resBundlePath- the bundle base path
-
getMessage
public java.lang.String getMessage(java.lang.String messageKey)
- Specified by:
getMessagein interfaceorg.alfresco.service.cmr.i18n.MessageLookup
-
getMessage
public java.lang.String getMessage(java.lang.String messageKey, java.util.Locale locale)- Specified by:
getMessagein interfaceorg.alfresco.service.cmr.i18n.MessageLookup
-
getMessage
public java.lang.String getMessage(java.lang.String messageKey, java.lang.Object... params)- Specified by:
getMessagein interfaceorg.alfresco.service.cmr.i18n.MessageLookup
-
getMessage
public java.lang.String getMessage(java.lang.String messageKey, java.util.Locale locale, java.lang.Object... params)- Specified by:
getMessagein interfaceorg.alfresco.service.cmr.i18n.MessageLookup
-
unregisterResourceBundle
public void unregisterResourceBundle(java.lang.String resBundlePath)
Description copied from interface:MessageServiceUnregister a resource bundleThis should be the bundle base path eg alfresco/messages/errors or workspace://SpaceStore/app:company_home/app:dictionary/app:labels/cm:errors
Once unregistered the messages will no longer be available via getMessage
- Specified by:
unregisterResourceBundlein interfaceMessageService- Parameters:
resBundlePath- the bundle base path
-
getRepoResourceBundle
public java.util.ResourceBundle getRepoResourceBundle(org.alfresco.service.cmr.repository.StoreRef storeRef, java.lang.String path, java.util.Locale locale) throws java.io.IOExceptionDescription copied from interface:MessageServiceGet message resource bundle from the repository note: also used by Web Client (ResourceBundleWrapper)- Specified by:
getRepoResourceBundlein interfaceMessageService- Parameters:
storeRef- store refpath- repository path (XPath)locale- locale- Returns:
- input stream
- Throws:
java.io.IOException
-
onEnableTenant
public void onEnableTenant()
- Specified by:
onEnableTenantin interfaceorg.alfresco.repo.tenant.TenantDeployer
-
onDisableTenant
public void onDisableTenant()
- Specified by:
onDisableTenantin interfaceorg.alfresco.repo.tenant.TenantDeployer
-
init
public void init()
- Specified by:
initin interfaceorg.alfresco.repo.tenant.TenantDeployer
-
destroy
public void destroy()
- Specified by:
destroyin interfaceorg.alfresco.repo.tenant.TenantDeployer
-
getRegisteredBundles
public java.util.Set<java.lang.String> getRegisteredBundles()
Description copied from interface:MessageServiceGet set of registered message resource bundles- Specified by:
getRegisteredBundlesin interfaceMessageService- Returns:
- set of registered bundles
-
register
public void register(MessageDeployer messageDeployer)
Description copied from interface:MessageServiceRegister message deployer with message service- Specified by:
registerin interfaceMessageService- Parameters:
messageDeployer- MessageDeployer
-
reset
public void reset()
Resets the message service
-
getBaseBundleName
public java.lang.String getBaseBundleName(java.lang.String resourceName)
- Specified by:
getBaseBundleNamein interfaceMessageService
-
getNode
protected org.alfresco.service.cmr.repository.NodeRef getNode(org.alfresco.service.cmr.repository.NodeRef rootNodeRef, java.lang.String path)
-
resolveQNamePath
protected org.alfresco.service.cmr.repository.NodeRef resolveQNamePath(org.alfresco.service.cmr.repository.NodeRef rootNodeRef, java.lang.String[] pathPrefixQNameStrings)
-
-