Class DefaultLocalePolicyService

java.lang.Object
org.exoplatform.portal.application.localization.DefaultLocalePolicyService
All Implemented Interfaces:
org.exoplatform.services.resources.LocalePolicy
Direct Known Subclasses:
NoBrowserLocalePolicyService

public class DefaultLocalePolicyService extends Object implements org.exoplatform.services.resources.LocalePolicy
This service represents a default policy for determining LocaleConfig to be used for user's session. This service is registered through portal services configuration file: conf/portal/configuration.xml Custom locale determination policy can be implemented by overriding or completely replacing this class, and registering an alternative implementation. To gracefully fallback from more specific locales (lang_COUNTRY) to more generic (lang) without loss of information about user's language selection use LocaleContextInfo.getLocaleIfLangSupported(java.util.Locale) and return a more specific Locale. The Locale will be appropriately narrowed by LocalePolicy caller. Special care needs to be taken to assure Locale consistency between portal requests and non-portal requests - like login redirect upon failed authentication attempt. To keep consistency at least one of LocaleContextInfo.cookieLocales and LocaleContextInfo.sessionLocale needs to be enabled.
Author:
Marko Strukelj
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultLocalePolicyService(org.exoplatform.services.resources.LocaleConfigService localeConfigService, org.exoplatform.container.xml.InitParams params)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    determineLocale(org.exoplatform.services.resources.LocaleContextInfo context)
     
    protected Locale
    getLocaleConfigForAnonymous(org.exoplatform.services.resources.LocaleContextInfo context)
    Override this method to change Locale determination for users that aren't logged in.
    protected Locale
    getLocaleConfigForRegistered(org.exoplatform.services.resources.LocaleContextInfo context)
    Override this method to change the LocaleConfig determination for registered users.
    protected Locale
    getLocaleConfigFromBrowser(org.exoplatform.services.resources.LocaleContextInfo context)
    Override this method to change the Locale determination based on browser language preferences.
    protected Locale
    getLocaleConfigFromCookie(org.exoplatform.services.resources.LocaleContextInfo context)
    Override this method to change the Locale determination based on browser cookie.
    protected Locale
    getLocaleConfigFromSession(org.exoplatform.services.resources.LocaleContextInfo context)
    Override this method to change the Locale determination based on session attribute.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultLocalePolicyService

      public DefaultLocalePolicyService(org.exoplatform.services.resources.LocaleConfigService localeConfigService, org.exoplatform.container.xml.InitParams params)
  • Method Details

    • determineLocale

      public Locale determineLocale(org.exoplatform.services.resources.LocaleContextInfo context)
      Specified by:
      determineLocale in interface org.exoplatform.services.resources.LocalePolicy
      See Also:
      • LocalePolicy.determineLocale(LocaleContextInfo)
    • getLocaleConfigForRegistered

      protected Locale getLocaleConfigForRegistered(org.exoplatform.services.resources.LocaleContextInfo context)
      Override this method to change the LocaleConfig determination for registered users. Default is: use user's profile language, if not available fall back to LOCALE cookie, and finally if that is not available either fall back to browser language preference.
      Parameters:
      context - locale context info available to implementations in order to determine appropriate Locale
      Returns:
      Locale representing a language to use, or null
    • getLocaleConfigFromBrowser

      protected Locale getLocaleConfigFromBrowser(org.exoplatform.services.resources.LocaleContextInfo context)
      Override this method to change the Locale determination based on browser language preferences. If you want to disable the use of browser language preferences simply return null.
      Parameters:
      context - locale context info available to implementations in order to determine appropriate Locale
      Returns:
      Locale representing a language to use, or null
    • getLocaleConfigForAnonymous

      protected Locale getLocaleConfigForAnonymous(org.exoplatform.services.resources.LocaleContextInfo context)
      Override this method to change Locale determination for users that aren't logged in. By default the request's LOCALE cookie is used, if that is not available the browser language preferences are used.
      Parameters:
      context - locale context info available to implementations in order to determine appropriate Locale
      Returns:
      Locale representing a language to use, or null
    • getLocaleConfigFromSession

      protected Locale getLocaleConfigFromSession(org.exoplatform.services.resources.LocaleContextInfo context)
      Override this method to change the Locale determination based on session attribute. Note: this is mostly a backup for cookie, as either one usually has to be enabled for locale to remain synchronized between portal and non-portal pages.
      Parameters:
      context - locale context info available to implementations in order to determine appropriate Locale
      Returns:
      Locale representing a language to use, or null
    • getLocaleConfigFromCookie

      protected Locale getLocaleConfigFromCookie(org.exoplatform.services.resources.LocaleContextInfo context)
      Override this method to change the Locale determination based on browser cookie. If you want to disable the use of browser cookies simply return null.
      Parameters:
      context - locale context info available to implementations in order to determine appropriate Locale
      Returns:
      Locale representing a language to use, or null