Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jasig.portal.i18n
Class LocaleManager

    java.lang.Object
      org.jasig.portal.i18n.LocaleManager

All Implemented Interfaces:
  java.io.Serializable

    public class LocaleManager

extends java.lang.Object
implements java.io.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: 1.27.4.1 $
Author:
  Shoji Kajita kajita@itc.nagoya-u.ac.jp, Ken Weiner, kweiner@unicon.net
See Also:
  Serialized Form

Field Summary
`private java.util.Locale[]` | `browserLocales`
`static boolean` | `DEFAULT_LOCALE_AWARE` Default value for localeAware.
`private static java.util.Locale` | `jvmLocale`
`private static boolean` | `localeAware`
`private static org.apache.commons.logging.Log` | `log`
`private IPerson` | `person`
`private static java.util.Locale[]` | `portalLocales`
`private java.util.Locale[]` | `sessionLocales`
`private java.util.Locale[]` | `userLocales`

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
`private void` | `addToLocaleList(java.util.List localeList, java.util.Locale[] locales)` Add locales to the locale list if they aren't in there already
`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()`
`private java.util.Locale[]` | `loadPortalLocales()` Read and parse portal_locales from portal.properties.
`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
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### log

    private static final org.apache.commons.logging.Log log

### 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

### person

    private IPerson person

### localeAware

    private static boolean localeAware

### jvmLocale

    private static java.util.Locale jvmLocale

### portalLocales

    private static java.util.Locale[] portalLocales

### sessionLocales

    private java.util.Locale[] sessionLocales

### browserLocales

    private java.util.Locale[] browserLocales

### userLocales

    private java.util.Locale[] userLocales

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)

### loadPortalLocales

    private java.util.Locale[] loadPortalLocales()

  Read and parse portal_locales from portal.properties. portal_locales will be in the form of a comma-separated list, e.g. en_US,ja_JP,sv_SE

### 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

### addToLocaleList

    private void addToLocaleList(java.util.List localeList,
                                 java.util.Locale[] locales)

  Add locales to the locale list if they aren't in there already

### 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()

  Overrides:
    `toString` in class `java.lang.Object`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD