velosurf.web.l10n
Class SimpleDBLocalizer

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

public class SimpleDBLocalizer
extends HTTPLocalizerTool

A basic database based Localizer implementation.

The following toolbox.xml parameters are available:

You can find on the web the list of ISO Language Codes and the list of ISO Country Codes.


Field Summary
private  java.util.Map config
          tool configuration.
private  java.util.Map<java.lang.Object,java.lang.String> currentStrings
          map (id -> localized) for the current locale.
private static java.lang.String ID_FIELD_DEFAULT
          default id fied name.
private static java.lang.String ID_FIELD_KEY
          id field name parameter key.
private static java.lang.String idField
          id field name.
private static boolean initialized
          initialization status.
private static java.lang.String LOCALE_FIELD_DEFAULT
          default locale field name.
private static java.lang.String LOCALE_FIELD_KEY
          locale field name parameter key.
private static java.lang.String localeField
          locale field name.
private static java.util.Map<java.util.Locale,java.util.Map<java.lang.Object,java.lang.String>> localeStrings
          map locale -> (id -> localized).
private static java.lang.String LOCALIZED_TABLE_DEFAULT
          default localized table name.
private static java.lang.String LOCALIZED_TABLE_KEY
          localized table name parameter key.
private static java.lang.String localizedTable
          localized table name.
private static java.lang.String STRING_FIELD_DEFAULT
          default localized string field name.
private static java.lang.String STRING_FIELD_KEY
          localized string field name parameter key.
private static java.lang.String stringField
          localized string field name.
 
Fields inherited from class velosurf.web.l10n.HTTPLocalizerTool
locale
 
Constructor Summary
SimpleDBLocalizer()
          Constructor.
 
Method Summary
 void configure(java.util.Map config)
          Configure this tool.
 java.lang.String get(java.lang.Object id)
          Localized message getter.
 boolean hasLocale(java.util.Locale locale)
          Check for the presence of a locale.
 void init(java.lang.Object initData)
          Initialize this tool.
private static void readLocales(javax.servlet.ServletContext ctx)
          read localized messages into memory.
 void setLocale(java.util.Locale locale)
          Locale setter.
 
Methods inherited from class velosurf.web.l10n.HTTPLocalizerTool
checkLocaleChange, get, getBestLocale, getLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALIZED_TABLE_KEY

private static final java.lang.String LOCALIZED_TABLE_KEY
localized table name parameter key.

See Also:
Constant Field Values

ID_FIELD_KEY

private static final java.lang.String ID_FIELD_KEY
id field name parameter key.

See Also:
Constant Field Values

LOCALE_FIELD_KEY

private static final java.lang.String LOCALE_FIELD_KEY
locale field name parameter key.

See Also:
Constant Field Values

STRING_FIELD_KEY

private static final java.lang.String STRING_FIELD_KEY
localized string field name parameter key.

See Also:
Constant Field Values

LOCALIZED_TABLE_DEFAULT

private static final java.lang.String LOCALIZED_TABLE_DEFAULT
default localized table name.

See Also:
Constant Field Values

ID_FIELD_DEFAULT

private static final java.lang.String ID_FIELD_DEFAULT
default id fied name.

See Also:
Constant Field Values

LOCALE_FIELD_DEFAULT

private static final java.lang.String LOCALE_FIELD_DEFAULT
default locale field name.

See Also:
Constant Field Values

STRING_FIELD_DEFAULT

private static final java.lang.String STRING_FIELD_DEFAULT
default localized string field name.

See Also:
Constant Field Values

localizedTable

private static java.lang.String localizedTable
localized table name.


idField

private static java.lang.String idField
id field name.


localeField

private static java.lang.String localeField
locale field name.


stringField

private static java.lang.String stringField
localized string field name.


initialized

private static boolean initialized
initialization status.


localeStrings

private static java.util.Map<java.util.Locale,java.util.Map<java.lang.Object,java.lang.String>> localeStrings
map locale -> (id -> localized).


currentStrings

private java.util.Map<java.lang.Object,java.lang.String> currentStrings
map (id -> localized) for the current locale.


config

private java.util.Map config
tool configuration.

Constructor Detail

SimpleDBLocalizer

public SimpleDBLocalizer()
Constructor.

Method Detail

configure

public void configure(java.util.Map config)
Configure this tool.

Parameters:
config - tool configuration

init

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

Overrides:
init in class HTTPLocalizerTool
Parameters:
initData - a view context

readLocales

private static void readLocales(javax.servlet.ServletContext ctx)
read localized messages into memory.

Parameters:
ctx - servlet context

hasLocale

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

Specified by:
hasLocale in class HTTPLocalizerTool
Parameters:
locale - locale
Returns:
true if present

setLocale

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

Specified by:
setLocale in interface Localizer
Overrides:
setLocale in class HTTPLocalizerTool
Parameters:
locale - locale

get

public java.lang.String get(java.lang.Object id)
Localized message getter.

Specified by:
get in interface Localizer
Specified by:
get in class HTTPLocalizerTool
Parameters:
id - message id
Returns:
localized message or id itself if not found


~ooOoo~