org.apache.turbine.services.localization
Class LocaleDetector

java.lang.Object
  |
  +--org.apache.turbine.services.localization.LocaleDetector

public class LocaleDetector
extends java.lang.Object

This class returns a Locale object based on the HTTP Accept-Language header. This class is based on examples from Jason Hunter's book Java Servlet Programming.

Version:
$Id$
Author:
Frank Y. Kim, Jon S. Stevens

Constructor Summary
LocaleDetector()
           
 
Method Summary
static java.util.Locale getLocale(RunData data)
          Attempts to pull the "Accept-Language" header out of the HttpServletRequest object and then parse it.
static java.util.Locale getLocale(java.lang.String languageHeader)
          This method parses the Accept-Language header and attempts to create a Locale out of it.
private static java.util.Locale getLocaleForLanguage(java.lang.String language)
          This method creates a Locale from the language.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

LocaleDetector

public LocaleDetector()
Method Detail

getLocale

public static java.util.Locale getLocale(RunData data)
Attempts to pull the "Accept-Language" header out of the HttpServletRequest object and then parse it. If the header is not present, it will return a null Locale.
Parameters:
data - Turbine information.
Returns:
A Locale.

getLocale

public static java.util.Locale getLocale(java.lang.String languageHeader)
This method parses the Accept-Language header and attempts to create a Locale out of it.
Parameters:
languageHeader - A String with the language header.
Returns:
A Locale.

getLocaleForLanguage

private static java.util.Locale getLocaleForLanguage(java.lang.String language)
This method creates a Locale from the language.
Parameters:
language - A String with the language.
Returns:
A Locale.


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.