com.izforge.izpack
Class LocaleDatabase

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.TreeMap
          extended by com.izforge.izpack.LocaleDatabase
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map, java.util.SortedMap

public class LocaleDatabase
extends java.util.TreeMap

Represents a database of a locale.

Author:
Julien Ponge, J. Chris Folsom
See Also:
Serialized Form

Field Summary
private static java.util.Map<java.lang.String,LocaleDatabase> cachedLocales
           
static java.lang.String LOCALE_DATABASE_DEF_SUFFIX
          The suffix for language pack definitions (.xml).
static java.lang.String LOCALE_DATABASE_DIRECTORY
          The directory where language packs are kept inside the installer jar file.
(package private) static long serialVersionUID
           
 
Constructor Summary
LocaleDatabase(java.io.InputStream in)
          The constructor.
 
Method Summary
 void add(java.io.InputStream in)
          Adds the contents of the given stream to the data base.
static LocaleDatabase getLocaleDatabase()
          Load the current default LocaleDatabase.
static LocaleDatabase getLocaleDatabase(java.lang.String isoCode)
          Load a locale database.
static LocaleDatabase getLocaleDatabase(java.lang.String isoCode, boolean reload)
          Load a LocaleDatabase.
 java.lang.String getString(java.lang.String key)
          Convenience method to retrieve an element.
 java.lang.String getString(java.lang.String key, java.lang.String[] variables)
          Convenience method to retrieve an element and simultaneously insert variables into the string.
 
Methods inherited from class java.util.TreeMap
clear, clone, comparator, containsKey, containsValue, entrySet, firstKey, get, headMap, keySet, lastKey, put, putAll, remove, size, subMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, isEmpty
 

Field Detail

cachedLocales

private static java.util.Map<java.lang.String,LocaleDatabase> cachedLocales

LOCALE_DATABASE_DIRECTORY

public static final java.lang.String LOCALE_DATABASE_DIRECTORY
The directory where language packs are kept inside the installer jar file.

See Also:
Constant Field Values

LOCALE_DATABASE_DEF_SUFFIX

public static final java.lang.String LOCALE_DATABASE_DEF_SUFFIX
The suffix for language pack definitions (.xml).

See Also:
Constant Field Values

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

LocaleDatabase

public LocaleDatabase(java.io.InputStream in)
               throws java.lang.Exception
The constructor.

Parameters:
in - An InputStream to read the translation from.
Throws:
java.lang.Exception - Description of the Exception
Method Detail

getLocaleDatabase

public static LocaleDatabase getLocaleDatabase(java.lang.String isoCode)
                                        throws java.lang.Exception
Load a locale database. If the database has already been loaded it will not be reloaded.

Parameters:
isoCode - The io code of the locale database.
Returns:
The locale database or null if it cannot be found.
Throws:
java.lang.Exception

getLocaleDatabase

public static LocaleDatabase getLocaleDatabase(java.lang.String isoCode,
                                               boolean reload)
                                        throws java.lang.Exception
Load a LocaleDatabase.

Parameters:
isoCode - The ISO language prefix for the locale.
reload - Whether or not to reload the locale database if it has already been loaded.
Returns:
The locale database or null if it cannot be found.

FIXME Maybe we should define some custom exception like LocaleLoadException or something similar so that this class can have a method signature that does not throw Exception

Throws:
java.lang.Exception

getLocaleDatabase

public static LocaleDatabase getLocaleDatabase()
                                        throws java.lang.Exception
Load the current default LocaleDatabase.

Throws:
java.lang.Exception - FIXME

add

public void add(java.io.InputStream in)
         throws java.lang.Exception
Adds the contents of the given stream to the data base. The stream have to contain key value pairs as declared by the DTD langpack.dtd.

Parameters:
in - an InputStream to read the translation from.
Throws:
java.lang.Exception

getString

public java.lang.String getString(java.lang.String key)
Convenience method to retrieve an element.

Parameters:
key - The key of the element to retrieve.
Returns:
The element value or the key if not found.

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String[] variables)
Convenience method to retrieve an element and simultaneously insert variables into the string. A place holder has to be build with the substring {n} where n is the parameter argument beginning with 0. The first argument is therefore {0}. If a parameter starts with a dollar sign the value will be used as key into the LocalDatabase. The key can be written as $MYKEY or ${MYKEY}. For all place holders an argument should be exist and vis a versa.

Parameters:
key - The key of the element to retrieve.
variables - the variables to insert
Returns:
The element value with the variables inserted or the key if not found.