com.infoengine.util
Class LanguagePreference

java.lang.Object
  extended by com.infoengine.util.LanguagePreference

public class LanguagePreference
extends Object

LanguagePreference contains methods used to parse HTTP Accept-Language strings and retrieve the 'sub-parts' of the strings. These methods are for use when localizing a response to a client HTTP request.

Supported API: true
Extendable: false


Constructor Summary
LanguagePreference()
          Supported API: true
LanguagePreference(String language, double qvalue)
          Supported API: true
 
Method Summary
static Vector getAcceptLanguagePreferences(String HTTPAcceptLanguage)
          getAcceptLanguagePreferences parses the HTTPAcceptLanguage string and builds a Vector of String objects to return.
static String getEncoding(Locale locale)
          Returns the url encoding for the specified locale.
 String getLanguage()
          Returns the language string of the LanguagePreference object.
static Locale getLocale(Vector preferences)
          Returns the Locale object for the most preferred language.
 double getQualityValue()
          Returns the qualtityValue of the LanguagePreference object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LanguagePreference

public LanguagePreference()
Supported API: true


LanguagePreference

public LanguagePreference(String language,
                          double qvalue)
Supported API: true

Method Detail

getQualityValue

public double getQualityValue()
Returns the qualtityValue of the LanguagePreference object.

Supported API: true


getLanguage

public String getLanguage()
Returns the language string of the LanguagePreference object.

Supported API: true


getAcceptLanguagePreferences

public static Vector getAcceptLanguagePreferences(String HTTPAcceptLanguage)
                                           throws com.infoengine.util.IEException
getAcceptLanguagePreferences parses the HTTPAcceptLanguage string and builds a Vector of String objects to return. The Vector is populated in order of decreasing preference, that is, position 0 holds the most preferred language, position 1 (if present) holds the second preference, etc.

Supported API: true

Parameters:
HTTPAcceptLanguage - String received from an HTTP request holding the Accept-Language value.
Returns:
Vector of String objects.
Throws:
IEException - Thrown if a parsing error occurs.

getLocale

public static Locale getLocale(Vector preferences)
Returns the Locale object for the most preferred language. In other words, it builds the Locale object for the first element in the given Vector object. If the vector is empty, the default locale is returned.

Supported API: true

Parameters:
preferences - Vector object holding language strings in the order of preference.
Returns:
A Locale object.

getEncoding

public static String getEncoding(Locale locale)
Returns the url encoding for the specified locale.

Supported API: true

Parameters:
locale - Current locale
Returns:
url encoding expected.