com.arsdigita.globalization
Class LocaleNegotiator

java.lang.Object
  extended bycom.arsdigita.globalization.LocaleNegotiator

public class LocaleNegotiator
extends Object

Adapted from com.oreilly.servlet.LocaleNegotiator. Determines the appropriate Locale, Charset, and ResourceBundle for a request.

The Locale for a request is determined in one of four ways in order of precedence:

  1. Locale associated with the current PackageInstance.
  2. User's preferred Locale as determined by the ACS.
  3. User's preferred Locale as determined by the Accept-Language header. For a definition of the format for the Accept-Language HTTP header look at RFC 2616.

    We handle quality values (or q values) for the Accept-Language HTTP header. This is how we interpret q-values:

  4. The default Locale of the system.

The Charset for a request Charset is determined in one of three ways in order of precedence:

  1. User's preferred Charset as determined by the ACS (as long as it is supported by the selected Locale.
  2. User's preferred Charset as determined by the Accept-Charset headers.
  3. The default Charset of the selected Locale.

The ResourceBundle is determined by the targetBundle as determined by the application and the selected Locale.

Version:
$Revision: #9 $ $Date: 2004/04/07 $

Field Summary
static String versionId
           
 
Constructor Summary
LocaleNegotiator(String targetBundle, String acceptLanguages, String acceptCharsets, Locale packageLocale)
           Select appropriate Locale, Charset, and ResourceBundle for a request.
 
Method Summary
static LocaleProvider getApplicationLocaleProvider()
           Get the application LocaleProvider.
 ResourceBundle getBundle()
           The negotiated ResourceBundle for this request
 String getCharset()
           The negotiated character set for this request
protected  String getCharsetForLocale(Locale locale, String acceptCharsets)
           Get the character set associated with a request.
static LocaleProvider getClientLocaleProvider()
           Get the client LocaleProvider.
 Locale getLocale()
           The negotiated Locale for this request
static LocaleProvider getSystemLocaleProvider()
           Get the system LocaleProvider.
static LocaleProvider getUserLocaleProvider()
           Get the user LocaleProvider.
static void setApplicationLocaleProvider(LocaleProvider lp)
           Set the LocaleProvider for the application.
static void setClientLocaleProvider(LocaleProvider lp)
           Set the LocaleProvider for the client.
static void setSystemLocaleProvider(LocaleProvider lp)
           Set the LocaleProvider for the system.
static void setUserLocaleProvider(LocaleProvider lp)
           Set the LocaleProvider for the user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

LocaleNegotiator

public LocaleNegotiator(String targetBundle,
                        String acceptLanguages,
                        String acceptCharsets,
                        Locale packageLocale)

Select appropriate Locale, Charset, and ResourceBundle for a request.

Parameters:
targetBundle - The target ResourceBundle for this request.
acceptLanguages - Acceptable languages according to the client.
acceptCharsets - Acceptable character sets according to the client.
Method Detail

getLocale

public Locale getLocale()

The negotiated Locale for this request

Returns:
Locale

getCharset

public String getCharset()

The negotiated character set for this request

Returns:
String

getBundle

public ResourceBundle getBundle()

The negotiated ResourceBundle for this request

Returns:
ResourceBundle

getCharsetForLocale

protected String getCharsetForLocale(Locale locale,
                                     String acceptCharsets)

Get the character set associated with a request. XXX We ignore the client charsets for now. Need to add this!

Parameters:
locale - The Locale object representing the language we want.
acceptCharsets - Accpetable character sets according to the client.

getApplicationLocaleProvider

public static LocaleProvider getApplicationLocaleProvider()

Get the application LocaleProvider.

Returns:
LocaleProvider

setApplicationLocaleProvider

public static void setApplicationLocaleProvider(LocaleProvider lp)

Set the LocaleProvider for the application. This type of provider has the highest priority.


getUserLocaleProvider

public static LocaleProvider getUserLocaleProvider()

Get the user LocaleProvider.

Returns:
LocaleProvider

setUserLocaleProvider

public static void setUserLocaleProvider(LocaleProvider lp)

Set the LocaleProvider for the user. This type of provider has the second highest priority.


getClientLocaleProvider

public static LocaleProvider getClientLocaleProvider()

Get the client LocaleProvider.

Returns:
LocaleProvider

setClientLocaleProvider

public static void setClientLocaleProvider(LocaleProvider lp)

Set the LocaleProvider for the client. This type of provider has the third highest priority.


getSystemLocaleProvider

public static LocaleProvider getSystemLocaleProvider()

Get the system LocaleProvider.

Returns:
LocaleProvider

setSystemLocaleProvider

public static void setSystemLocaleProvider(LocaleProvider lp)

Set the LocaleProvider for the system. This type of provider has the lowest priority.



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC