uPortal 2.4.1
API Documentation

org.jasig.portal.i18n
Class LocaleManager

java.lang.Object
  extended byorg.jasig.portal.i18n.LocaleManager

public class LocaleManager
extends java.lang.Object

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: 1.24.2.1 $
Author:
Shoji Kajita kajita@itc.nagoya-u.ac.jp, Ken Weiner, kweiner@unicon.net

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

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,
                     java.lang.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 java.util.Locale getJvmLocale()

getPortalLocales

public static java.util.Locale[] getPortalLocales()

getBrowserLocales

public java.util.Locale[] getBrowserLocales()

getUserLocales

public java.util.Locale[] getUserLocales()

getSessionLocales

public java.util.Locale[] getSessionLocales()

setJvmLocale

public static void setJvmLocale(java.util.Locale jvmLocale)

setPortalLocales

public static void setPortalLocales(java.util.Locale[] portalLocales)

setBrowserLocales

public void setBrowserLocales(java.util.Locale[] browserLocales)

setUserLocales

public void setUserLocales(java.util.Locale[] userLocales)

setSessionLocales

public void setSessionLocales(java.util.Locale[] sessionLocales)

getLocales

public java.util.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 java.util.Locale[] parseLocales(java.lang.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 java.util.Locale parseLocale(java.lang.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 java.lang.String stringValueOf(java.util.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(java.util.Locale[] userLocales)
                        throws java.lang.Exception
Stores the user locales persistantly.

Parameters:
userLocales - the user locales preference
Throws:
java.lang.Exception

xmlValueOf

public static org.w3c.dom.Document xmlValueOf(java.util.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 org.w3c.dom.Document xmlValueOf(java.util.Locale[] locales,
                                              java.util.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 java.lang.String toString()

uPortal 2.4.1
API Documentation