velosurf.web.l10n
Class HTTPLocalizerTool

java.lang.Object
  extended by velosurf.web.l10n.HTTPLocalizerTool
All Implemented Interfaces:
Localizer
Direct Known Subclasses:
SimpleDBLocalizer

public abstract class HTTPLocalizerTool
extends java.lang.Object
implements Localizer

This class rely on the "Accepted-Language" HTTP header to detect the appropriate locale to be used.

This tool accepts a "default-locale" configuration parameter in toolbox.xml.

It is meant for the session scope.

Author:
Claude Brisson

Field Summary
protected  java.util.Locale locale
          current locale
private  java.lang.ref.WeakReference<javax.servlet.http.HttpSession> session
          keep a reference on the session
 
Constructor Summary
HTTPLocalizerTool()
           
 
Method Summary
 void checkLocaleChange()
          Check that the locale has not changed in the session.
abstract  java.lang.String get(java.lang.Object id)
          Get the localized message for this key.
 java.lang.String get(java.lang.Object id, java.lang.Object... params)
          Get the localized parameterized message for this key.
 java.util.Locale getBestLocale(java.util.List<java.util.Locale> locales)
          Get the locale best matching available localized data among a list.
 java.util.Locale getLocale()
          Current lcoale getter.
abstract  boolean hasLocale(java.util.Locale locale)
          Check for the presence of a locale.
 void init(java.lang.Object initData)
          Initialize this tool.
private static java.util.List<java.util.Locale> listFromEnum(java.util.Enumeration e)
          Transform an enumeration into a list of locales.
 void setLocale(java.util.Locale locale)
          Current locale setter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

private java.lang.ref.WeakReference<javax.servlet.http.HttpSession> session
keep a reference on the session


locale

protected java.util.Locale locale
current locale

Constructor Detail

HTTPLocalizerTool

public HTTPLocalizerTool()
Method Detail

init

public void init(java.lang.Object initData)
Initialize this tool.

Parameters:
initData - a view context

listFromEnum

private static java.util.List<java.util.Locale> listFromEnum(java.util.Enumeration e)
Transform an enumeration into a list of locales.

Parameters:
e - enumeration
Returns:
a list of locales

getBestLocale

public java.util.Locale getBestLocale(java.util.List<java.util.Locale> locales)
Get the locale best matching available localized data among a list.

Parameters:
locales - list of input locales
Returns:
best matching locale

hasLocale

public abstract boolean hasLocale(java.util.Locale locale)
Check for the presence of a locale.

Parameters:
locale - locale to check
Returns:
true if present

setLocale

public void setLocale(java.util.Locale locale)
Current locale setter.

Specified by:
setLocale in interface Localizer
Parameters:
locale - locale

getLocale

public java.util.Locale getLocale()
Current lcoale getter.

Specified by:
getLocale in interface Localizer
Returns:
current locale

checkLocaleChange

public void checkLocaleChange()
Check that the locale has not changed in the session.


get

public abstract java.lang.String get(java.lang.Object id)
Get the localized message for this key.

Specified by:
get in interface Localizer
Parameters:
id - message key
Returns:
localized message (or id if not found).

get

public java.lang.String get(java.lang.Object id,
                            java.lang.Object... params)
Get the localized parameterized message for this key.

Specified by:
get in interface Localizer
Parameters:
id - message key
params - message parameters
Returns:
localized message (or id if not found).


~ooOoo~