org.jasig.portal.i18n
Class LocaleManager

java.lang.Object
  extended by org.jasig.portal.i18n.LocaleManager
All Implemented Interfaces:
Serializable

public class LocaleManager
extends Object
implements Serializable

Manages locales on behalf of a user. This class currently keeps track of locales at the following levels:

  1. User's locale preferences (associated with a user ID)
  2. Browser's locale preferences (from the Accept-Language request header)
  3. Session's locale preferences (set via the portal request parameter uP_locales)
  4. Portal's locale preferences (set in portal.properties)
Eventually, this class will also keep track of locale preferences at the following levels:
  1. Layout node's locale preferences
  2. User profile's locale preferences

Version:
$Revision: 21139 $
Author:
Shoji Kajita kajita@itc.nagoya-u.ac.jp, Ken Weiner, kweiner@unicon.net
See Also:
Serialized Form

Field Summary
static boolean DEFAULT_LOCALE_AWARE
          Default value for localeAware.
 
Constructor Summary
LocaleManager(IPerson person)
          Constructor that associates a locale manager with a user.
LocaleManager(IPerson person, String acceptLanguage)
          Constructor that sets up locales according to the Accept-Language request header from a user's browser.
 
Method Summary
 Locale[] getBrowserLocales()
           
static Locale getJvmLocale()
           
 Locale[] getLocales()
          Produces a sorted list of locales according to locale preferences obtained from several places.
static Locale[] getPortalLocales()
           
 Locale[] getSessionLocales()
           
 Locale[] getUserLocales()
           
static boolean isLocaleAware()
           
static Locale parseLocale(String localeString)
          Helper method to produce a java.util.Locale object from a locale string such as en_US or ja_JP.
static Locale[] parseLocales(String localeStringList)
          Helper method to produce a java.util.Locale array from a comma-delimited locale string list, e.g.
 void persistUserLocales(Locale[] userLocales)
          Stores the user locales persistantly.
 void setBrowserLocales(Locale[] browserLocales)
           
static void setJvmLocale(Locale jvmLocale)
           
static void setPortalLocales(Locale[] portalLocales)
           
 void setSessionLocales(Locale[] sessionLocales)
           
 void setUserLocales(Locale[] userLocales)
           
static String stringValueOf(Locale[] locales)
          Constructs a comma-delimited list of locales that could be parsed back into a Locale array with parseLocales(String localeStringList).
 String toString()
           
static Document xmlValueOf(Locale[] locales)
          Creates an XML representation of a list of locales.
static Document xmlValueOf(Locale[] locales, Locale selectedLocale)
          Creates an XML representation of a list of locales.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_LOCALE_AWARE

public static final boolean DEFAULT_LOCALE_AWARE
Default value for localeAware. This value will be used when the corresponding property cannot be loaded.

See Also:
Constant Field Values
Constructor Detail

LocaleManager

public LocaleManager(IPerson person)
Constructor that associates a locale manager with a user.

Parameters:
person - the user

LocaleManager

public LocaleManager(IPerson person,
                     String acceptLanguage)
Constructor that sets up locales according to the Accept-Language request header from a user's browser.

Parameters:
person - the user
acceptLanguage - the Accept-Language request header from a user's browser
Method Detail

isLocaleAware

public static boolean isLocaleAware()

getJvmLocale

public static Locale getJvmLocale()

getPortalLocales

public static Locale[] getPortalLocales()

getBrowserLocales

public Locale[] getBrowserLocales()

getUserLocales

public Locale[] getUserLocales()

getSessionLocales

public Locale[] getSessionLocales()

setJvmLocale

public static void setJvmLocale(Locale jvmLocale)

setPortalLocales

public static void setPortalLocales(Locale[] portalLocales)

setBrowserLocales

public void setBrowserLocales(Locale[] browserLocales)

setUserLocales

public void setUserLocales(Locale[] userLocales)

setSessionLocales

public void setSessionLocales(Locale[] sessionLocales)

getLocales

public Locale[] getLocales()
Produces a sorted list of locales according to locale preferences obtained from several places. The following priority is given: session, user, browser, portal, and jvm.

Returns:
the sorted list of locales

parseLocales

public static Locale[] parseLocales(String localeStringList)
Helper method to produce a java.util.Locale array from a comma-delimited locale string list, e.g. "en_US,ja_JP"

Parameters:
localeStringList - the locales to parse
Returns:
an array of locales representing the locale string list

parseLocale

public static Locale parseLocale(String localeString)
Helper method to produce a java.util.Locale object from a locale string such as en_US or ja_JP.

Parameters:
localeString - a locale string such as en_US
Returns:
a java.util.Locale object representing the locale string

stringValueOf

public static String stringValueOf(Locale[] locales)
Constructs a comma-delimited list of locales that could be parsed back into a Locale array with parseLocales(String localeStringList).

Parameters:
locales - the list of locales
Returns:
a string representing the list of locales

persistUserLocales

public void persistUserLocales(Locale[] userLocales)
                        throws Exception
Stores the user locales persistantly.

Parameters:
userLocales - the user locales preference
Throws:
Exception

xmlValueOf

public static Document xmlValueOf(Locale[] locales)
Creates an XML representation of a list of locales.

Parameters:
locales - the locale list
Returns:
the locale list as XML

xmlValueOf

public static Document xmlValueOf(Locale[] locales,
                                  Locale selectedLocale)
Creates an XML representation of a list of locales. If a selected locale is supplied, the XML element representing the selected locale will have an attribute of selected with value of true. This is helpful when constructing user interfaces that indicate which locale is selected.

Parameters:
locales - the locale list
selectedLocale - a locale that should be selected if it is in the list
Returns:
the locale list as XML

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010 Jasig. All Rights Reserved.