Class SelectedLocale


  • public abstract class SelectedLocale
    extends Object
    A utility class for storing and retrieving Locale information. The static methods create beans and store them in the ServletContext or the session, where the information can be found later.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static String ATTRIBUTE_NAME
      Use this attribute on both the ServletContext and the Session.
    • Constructor Summary

      Constructors 
      Constructor Description
      SelectedLocale()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Locale getCurrentLocale​(javax.servlet.http.HttpServletRequest req)
      Get the current Locale to use, which is the first of these to be found: The forced Locale in the servlet context The selected Locale in the session The Locale from the request The default Locale for the JVM
      static Locale getFallbackLocale()  
      static Locale getOverridingLocale​(javax.servlet.http.HttpServletRequest req)
      Do we need to override the Locale in the current request? return the first of these to be found: The forced Locale in the servlet context The selected Locale in the session The first of the selectable Locales null
      static Locale getOverridingLocale​(javax.servlet.ServletContext ctx, List<Locale> preferredLocales)
      Get the overriding Locale to use, which is the first of these to be found: The forced Locale in the servlet context The first selectable locale matching a preferred locale The first of the preferred locale null
      static Locale getPreferredLocale​(javax.servlet.ServletContext ctx, List<Locale> preferredLocales)
      Get the preferred Locale to use, which is the first of these to be found: The forced Locale in the servlet context The first selectable locale matching a preferred locale The first of the preferred locale The default Locale for the JVM
      static List<Locale> getSelectableLocales​(javax.servlet.http.HttpServletRequest req)
      Get the list of selectable Locales from the servlet context.
      static List<Locale> getSelectableLocales​(javax.servlet.ServletContext ctx)
      Get the list of selectable Locales from the servlet context.
      static void setForcedLocale​(javax.servlet.ServletContext ctx, Locale forcedLocale)
      Store the forced locale in the servlet context.
      static void setSelectableLocales​(javax.servlet.ServletContext ctx, List<Locale> selectableLocales)
      Store a list of selectable Locales in the servlet context, so we can easily build the selection panel in the GUI.
      static void setSelectedLocale​(javax.servlet.http.HttpServletRequest req, Locale selectedLocale)
      Store the selected locale in the current session.
    • Field Detail

      • ATTRIBUTE_NAME

        protected static final String ATTRIBUTE_NAME
        Use this attribute on both the ServletContext and the Session.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SelectedLocale

        public SelectedLocale()
    • Method Detail

      • setForcedLocale

        public static void setForcedLocale​(javax.servlet.ServletContext ctx,
                                           Locale forcedLocale)
        Store the forced locale in the servlet context. Clear any selectable Locales.
      • setSelectedLocale

        public static void setSelectedLocale​(javax.servlet.http.HttpServletRequest req,
                                             Locale selectedLocale)
        Store the selected locale in the current session.
      • getOverridingLocale

        public static Locale getOverridingLocale​(javax.servlet.http.HttpServletRequest req)
        Do we need to override the Locale in the current request? return the first of these to be found:
        • The forced Locale in the servlet context
        • The selected Locale in the session
        • The first of the selectable Locales
        • null
      • getOverridingLocale

        public static Locale getOverridingLocale​(javax.servlet.ServletContext ctx,
                                                 List<Locale> preferredLocales)
        Get the overriding Locale to use, which is the first of these to be found:
        • The forced Locale in the servlet context
        • The first selectable locale matching a preferred locale
        • The first of the preferred locale
        • null
      • getFallbackLocale

        public static Locale getFallbackLocale()
        Returns:
        a default locale to use if no other criteria for selecting a different one exist.
      • getCurrentLocale

        public static Locale getCurrentLocale​(javax.servlet.http.HttpServletRequest req)
        Get the current Locale to use, which is the first of these to be found:
        • The forced Locale in the servlet context
        • The selected Locale in the session
        • The Locale from the request
        • The default Locale for the JVM
      • getPreferredLocale

        public static Locale getPreferredLocale​(javax.servlet.ServletContext ctx,
                                                List<Locale> preferredLocales)
        Get the preferred Locale to use, which is the first of these to be found:
        • The forced Locale in the servlet context
        • The first selectable locale matching a preferred locale
        • The first of the preferred locale
        • The default Locale for the JVM
      • setSelectableLocales

        public static void setSelectableLocales​(javax.servlet.ServletContext ctx,
                                                List<Locale> selectableLocales)
        Store a list of selectable Locales in the servlet context, so we can easily build the selection panel in the GUI. Clears any forced locale.
      • getSelectableLocales

        public static List<Locale> getSelectableLocales​(javax.servlet.http.HttpServletRequest req)
        Get the list of selectable Locales from the servlet context. May return an empty list, but never returns null.
      • getSelectableLocales

        public static List<Locale> getSelectableLocales​(javax.servlet.ServletContext ctx)
        Get the list of selectable Locales from the servlet context. May return an empty list, but never returns null.