Class SelectedLocale
- java.lang.Object
-
- edu.cornell.mannlib.vitro.webapp.i18n.selection.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classSelectedLocale.ContextSelectedLocaleHolds Locale information in the ServletContext.protected static classSelectedLocale.SessionSelectedLocaleHolds Locale information in the Session.
-
Field Summary
Fields Modifier and Type Field Description protected static StringATTRIBUTE_NAMEUse 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 LocalegetCurrentLocale(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 JVMstatic LocalegetFallbackLocale()static LocalegetOverridingLocale(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 nullstatic LocalegetOverridingLocale(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 nullstatic LocalegetPreferredLocale(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 JVMstatic 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 voidsetForcedLocale(javax.servlet.ServletContext ctx, Locale forcedLocale)Store the forced locale in the servlet context.static voidsetSelectableLocales(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 voidsetSelectedLocale(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
-
-
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.
-
-