Class MessageServiceImpl

  • All Implemented Interfaces:
    MessageService, org.alfresco.repo.tenant.TenantDeployer, org.alfresco.service.cmr.i18n.MessageLookup

    public class MessageServiceImpl
    extends 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.
    • 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<String,​Set<String>> resourceBundleBaseNamesCache)
      • setLoadedResourceBundlesCache

        public void setLoadedResourceBundlesCache​(org.alfresco.repo.cache.SimpleCache<String,​Map<Locale,​Set<String>>> loadedResourceBundlesCache)
      • setMessagesCache

        public void setMessagesCache​(org.alfresco.repo.cache.SimpleCache<String,​Map<Locale,​Map<String,​String>>> messagesCache)
      • setTryLockTimeout

        public void setTryLockTimeout​(long tryLockTimeout)
      • setLocale

        public void setLocale​(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 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​(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
      • getNearestLocale

        public Locale getNearestLocale​(Locale templateLocale,
                                       Set<Locale> 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 Locale parseLocale​(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​(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
        Parameters:
        resBundlePath - the bundle base path
      • getMessage

        public String getMessage​(String messageKey)
        Specified by:
        getMessage in interface org.alfresco.service.cmr.i18n.MessageLookup
      • getMessage

        public String getMessage​(String messageKey,
                                 Locale locale)
        Specified by:
        getMessage in interface org.alfresco.service.cmr.i18n.MessageLookup
      • getMessage

        public String getMessage​(String messageKey,
                                 Object... params)
        Specified by:
        getMessage in interface org.alfresco.service.cmr.i18n.MessageLookup
      • getMessage

        public String getMessage​(String messageKey,
                                 Locale locale,
                                 Object... params)
        Specified by:
        getMessage in interface org.alfresco.service.cmr.i18n.MessageLookup
      • unregisterResourceBundle

        public void unregisterResourceBundle​(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
        Parameters:
        resBundlePath - the bundle base path
      • getRepoResourceBundle

        public ResourceBundle getRepoResourceBundle​(org.alfresco.service.cmr.repository.StoreRef storeRef,
                                                    String path,
                                                    Locale locale)
                                             throws 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:
        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
      • register

        public void register​(MessageDeployer messageDeployer)
        Description copied from interface: MessageService
        Register message deployer with message service
        Specified by:
        register in interface MessageService
        Parameters:
        messageDeployer - MessageDeployer
      • reset

        public void reset()
        Resets the message service
      • getNode

        protected org.alfresco.service.cmr.repository.NodeRef getNode​(org.alfresco.service.cmr.repository.NodeRef rootNodeRef,
                                                                      String path)
      • resolveQNamePath

        protected org.alfresco.service.cmr.repository.NodeRef resolveQNamePath​(org.alfresco.service.cmr.repository.NodeRef rootNodeRef,
                                                                               String[] pathPrefixQNameStrings)