org.alfresco.repo.i18n
Class MessageServiceImpl

java.lang.Object
  extended by org.alfresco.repo.i18n.MessageServiceImpl
All Implemented Interfaces:
MessageService, org.alfresco.repo.tenant.TenantDeployer

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
static java.lang.String PROPERTIES_FILE_SUFFIX
           
 
Constructor Summary
MessageServiceImpl()
           
 
Method Summary
 void destroy()
           
 java.lang.String getBaseBundleName(java.lang.String resourceName)
           
 java.util.Locale getContentLocale()
          Get the content local for the current thread.
This will revert to MessageService.getLocale() if no value has been defined.
 java.util.Locale getLocale()
          Get the general local for the current thread, will revert to the default locale if none specified for this thread.
 java.lang.String getMessage(java.lang.String messageKey)
          Get message from registered resource bundle.
 java.lang.String getMessage(java.lang.String messageKey, java.util.Locale locale)
          Get a localised message string
 java.lang.String getMessage(java.lang.String messageKey, java.util.Locale locale, java.lang.Object[] params)
          Get a localised message string, parameterized using standard MessageFormatter.
 java.lang.String getMessage(java.lang.String messageKey, java.lang.Object[] params)
          Get a localised message string, parameterized using standard MessageFormatter.
 java.util.Locale getNearestLocale(java.util.Locale templateLocale, java.util.Set options)
          Searches for the nearest locale from the available options.
protected  org.alfresco.service.cmr.repository.NodeRef getNode(org.alfresco.service.cmr.repository.NodeRef rootNodeRef, java.lang.String path)
           
 java.util.Set getRegisteredBundles()
          Get set of registered message resource bundles
 java.util.ResourceBundle getRepoResourceBundle(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)
 void init()
           
 void onDisableTenant()
           
 void onEnableTenant()
           
 java.util.Locale parseLocale(java.lang.String localeStr)
          Factory method to create a Locale from a lang_country_variant string.
 void register(MessageDeployer messageDeployer)
          Register message deployer with message service
 void registerResourceBundle(java.lang.String resBundlePath)
          Register a resource bundle.
 void reset()
          Resets the message service
protected  org.alfresco.service.cmr.repository.NodeRef resolveQNamePath(org.alfresco.service.cmr.repository.NodeRef rootNodeRef, java.lang.String[] pathPrefixQNameStrings)
           
 void setContentLocale(java.util.Locale locale)
          Set the content locale for the current thread.
 void setContentService(ContentService contentService)
           
 void setLoadedResourceBundlesCache(org.alfresco.repo.cache.SimpleCache loadedResourceBundlesCache)
           
 void setLocale(java.util.Locale locale)
          Set the locale for the current thread.
 void setMessagesCache(org.alfresco.repo.cache.SimpleCache messagesCache)
           
 void setNamespaceService(org.alfresco.service.namespace.NamespaceService namespaceService)
           
 void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)
           
 void setResourceBundleBaseNamesCache(org.alfresco.repo.cache.SimpleCache resourceBundleBaseNamesCache)
           
 void setTenantService(org.alfresco.repo.tenant.TenantService tenantService)
           
 void unregisterResourceBundle(java.lang.String resBundlePath)
          Unregister a resource bundle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTIES_FILE_SUFFIX

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

MessageServiceImpl

public MessageServiceImpl()
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 resourceBundleBaseNamesCache)

setLoadedResourceBundlesCache

public void setLoadedResourceBundlesCache(org.alfresco.repo.cache.SimpleCache loadedResourceBundlesCache)

setMessagesCache

public void setMessagesCache(org.alfresco.repo.cache.SimpleCache messagesCache)

setLocale

public void setLocale(java.util.Locale locale)
Description copied from interface: MessageService
Set the locale for the current thread.

Specified by:
setLocale in interface MessageService
Parameters:
locale - the locale

getLocale

public java.util.Locale getLocale()
Description copied from interface: MessageService
Get the general local for the current thread, will revert to the default locale if none specified for this thread.

Specified by:
getLocale in interface MessageService
Returns:
the general locale

setContentLocale

public void setContentLocale(java.util.Locale locale)
Description copied from interface: MessageService
Set the content locale for the current thread.

Specified by:
setContentLocale in interface MessageService
Parameters:
locale - the content locale

getContentLocale

public java.util.Locale getContentLocale()
Description copied from interface: MessageService
Get the content local for the current thread.
This will revert to MessageService.getLocale() if no value has been defined.

Specified by:
getContentLocale in interface MessageService
Returns:
Returns the content locale

getNearestLocale

public java.util.Locale getNearestLocale(java.util.Locale templateLocale,
                                         java.util.Set options)
Description copied from interface: MessageService
Searches for the nearest locale from the available options. To match any locale, pass in null.

Specified by:
getNearestLocale in interface MessageService
Parameters:
templateLocale - the template to search for or null to match any locale
options - 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: MessageService
Factory method to create a Locale from a lang_country_variant string.

Specified by:
parseLocale in interface MessageService
Parameters:
localeStr - e.g. fr_FR
Returns:
Returns the locale instance, or the default if the string is invalid

registerResourceBundle

public void registerResourceBundle(java.lang.String resBundlePath)
Description copied from interface: MessageService
Register 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:
registerResourceBundle in interface MessageService

getMessage

public java.lang.String getMessage(java.lang.String messageKey)
Description copied from interface: MessageService
Get message from registered resource bundle.

Specified by:
getMessage in interface MessageService
Parameters:
messageKey - message key
Returns:
localised message string, null if not found

getMessage

public java.lang.String getMessage(java.lang.String messageKey,
                                   java.util.Locale locale)
Description copied from interface: MessageService
Get a localised message string

Specified by:
getMessage in interface MessageService
Parameters:
messageKey - the message key
locale - override the current locale
Returns:
the localised message string, null if not found

getMessage

public java.lang.String getMessage(java.lang.String messageKey,
                                   java.lang.Object[] params)
Description copied from interface: MessageService
Get a localised message string, parameterized using standard MessageFormatter.

Specified by:
getMessage in interface MessageService
Parameters:
messageKey - message key
params - format parameters
Returns:
the localised string, null if not found

getMessage

public java.lang.String getMessage(java.lang.String messageKey,
                                   java.util.Locale locale,
                                   java.lang.Object[] params)
Description copied from interface: MessageService
Get a localised message string, parameterized using standard MessageFormatter.

Specified by:
getMessage in interface MessageService
Parameters:
messageKey - the message key
locale - override current locale
params - the localised message string
Returns:
the localised string, null if not found

unregisterResourceBundle

public void unregisterResourceBundle(java.lang.String resBundlePath)
Description copied from interface: MessageService
Unregister 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 unregistered the messages will no longer be available via getMessage

Specified by:
unregisterResourceBundle in interface MessageService

getRepoResourceBundle

public java.util.ResourceBundle getRepoResourceBundle(org.alfresco.service.cmr.repository.StoreRef storeRef,
                                                      java.lang.String path,
                                                      java.util.Locale locale)
                                               throws java.io.IOException
Description copied from interface: MessageService
Get message resource bundle from the repository note: also used by Web Client (ResourceBundleWrapper)

Specified by:
getRepoResourceBundle in interface MessageService
Parameters:
storeRef - store ref
path - repository path (XPath)
locale - locale
Returns:
input stream
Throws:
java.io.IOException

onEnableTenant

public void onEnableTenant()
Specified by:
onEnableTenant in interface org.alfresco.repo.tenant.TenantDeployer

onDisableTenant

public void onDisableTenant()
Specified by:
onDisableTenant in interface org.alfresco.repo.tenant.TenantDeployer

init

public void init()
Specified by:
init in interface org.alfresco.repo.tenant.TenantDeployer

destroy

public void destroy()
Specified by:
destroy in interface org.alfresco.repo.tenant.TenantDeployer

getRegisteredBundles

public java.util.Set getRegisteredBundles()
Description copied from interface: MessageService
Get set of registered message resource bundles

Specified by:
getRegisteredBundles in interface MessageService
Returns:
set of registered bundles

register

public void register(MessageDeployer messageDeployer)
Description copied from interface: MessageService
Register message deployer with message service

Specified by:
register in interface MessageService

reset

public void reset()
Resets the message service


getBaseBundleName

public java.lang.String getBaseBundleName(java.lang.String resourceName)
Specified by:
getBaseBundleName in interface MessageService

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)


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.