org.opengts.util
Class I18N

java.lang.Object
  extended by org.opengts.util.I18N

public class I18N
extends java.lang.Object

A set of tools for creating i18n compliant code and providing localized text


Nested Class Summary
static class I18N.Text
          Class used to provide lazy localization
 
Field Summary
static java.lang.String _LOCAL_STRINGS
           
protected static java.lang.String I18N_KEY_END
           
protected static java.lang.String I18N_KEY_STARTC
           
protected static java.lang.String I18N_KEY_STARTE
           
static java.lang.String LOCAL_STRINGS
           
 
Method Summary
static I18N.Text _getString(java.lang.Class clazz, java.lang.String key, java.lang.String dft)
          Returns an I18N.Text instance used for lazy localization
protected static java.lang.String decodeNewLine(java.lang.String s)
          Converts "\\n" patterns into literal newlines (\n)
protected static java.lang.StringBuffer decodeNewLine(java.lang.StringBuffer s)
          Converts "\\n" patterns into literal newlines (\n)
static java.util.Locale getDefaultLocale()
          Gets the System default Locale
static I18N getI18N(java.lang.Class pkgClz, java.util.Locale loc)
          Returns an I18N instance based on the specified package name and Locale
static I18N getI18N(java.lang.Package pkg, java.util.Locale loc)
          Returns an I18N instance based on the specified package name and Locale
static I18N getI18N(java.lang.String pkgName, java.util.Locale loc)
          Returns an I18N instance based on the specified package name and Locale
 java.util.Enumeration getKeys()
          Gets an Enumeration of the LocalString keys for this I18N instance
 java.util.Locale getLocale()
          gets the Locale for this I18N instance
static java.util.Locale getLocale(java.util.Locale loc)
          Returns the specified Locale, or the default Locale if the specified Locale is null
static java.util.Locale getLocale(java.lang.String loc)
          Gets the Java Locale instance based on the specified locale name
static java.util.Locale getLocale(java.lang.String loc, java.util.Locale dft)
          Gets the Java Locale instance based on the specified locale name
static I18N.Text getString(java.lang.Class clazz, java.lang.String key, java.lang.String dft)
          Returns an I18N.Text instance used for lazy localization
 java.lang.String getString(java.lang.String key, java.lang.String dft)
          Gets the Localized value for the specified key.
 java.lang.String getString(java.lang.String key, java.lang.String dft, java.lang.Object arg)
          Gets the Localized value for the specified key.
 java.lang.String getString(java.lang.String key, java.lang.String dft, java.lang.Object[] args)
          Gets the Localized value for the specified key.
 java.lang.String getString(java.lang.String key, java.lang.String dft, java.lang.Object arg0, java.lang.Object arg1)
          Gets the Localized value for the specified key.
 java.lang.String getString(java.lang.String key, java.lang.String dft, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2)
          Gets the Localized value for the specified key.
 java.lang.String getString(java.lang.String key, java.lang.String dft, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
          Gets the Localized value for the specified key.
static void main(java.lang.String[] argv)
          Debug/Testing entry point
protected static java.lang.Object NonNull(java.lang.Object obj)
          Returns the specified Object, or an empty String if the specified Object is null
static I18N.Text parseText(java.lang.String pkg, java.lang.String key, java.lang.String dft)
          Returns an I18N.Text instance used for lazy localization.
(use in XML loaders to avoid expression matches when auto-updating 'LocalStrings_XX.properties')
static I18N.Text parseText(java.lang.String pkg, java.lang.String key, java.lang.String dft, boolean showError)
          Returns an I18N.Text instance used for lazy localization.
(use in XML loaders to avoid expression matches when auto-updating 'LocalStrings_XX.properties')
 void printKeyValues()
          Prints all LocalString keys for this I18N instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCAL_STRINGS

public static final java.lang.String LOCAL_STRINGS
See Also:
Constant Field Values

_LOCAL_STRINGS

public static final java.lang.String _LOCAL_STRINGS
See Also:
Constant Field Values

I18N_KEY_STARTE

protected static final java.lang.String I18N_KEY_STARTE
See Also:
Constant Field Values

I18N_KEY_STARTC

protected static final java.lang.String I18N_KEY_STARTC
See Also:
Constant Field Values

I18N_KEY_END

protected static final java.lang.String I18N_KEY_END
See Also:
Constant Field Values
Method Detail

getI18N

public static I18N getI18N(java.lang.Class pkgClz,
                           java.util.Locale loc)
Returns an I18N instance based on the specified package name and Locale

Parameters:
pkgClz - The class from which the class package is derived
loc - The Locale resource from with the localized text is loaded

getI18N

public static I18N getI18N(java.lang.Package pkg,
                           java.util.Locale loc)
Returns an I18N instance based on the specified package name and Locale

Parameters:
pkg - The resource package
loc - The Locale resource from with the localized text is loaded

getI18N

public static I18N getI18N(java.lang.String pkgName,
                           java.util.Locale loc)
Returns an I18N instance based on the specified package name and Locale

Parameters:
pkgName - The resource package name
loc - The Locale resource from with the localized text is loaded

getLocale

public static java.util.Locale getLocale(java.lang.String loc)
Gets the Java Locale instance based on the specified locale name

Parameters:
loc - The name of the Locale
Returns:
The Java Locale instance

getLocale

public static java.util.Locale getLocale(java.lang.String loc,
                                         java.util.Locale dft)
Gets the Java Locale instance based on the specified locale name

Parameters:
loc - The name of the Locale
dft - The default Locale returned
Returns:
The Java Locale instance

getLocale

public static java.util.Locale getLocale(java.util.Locale loc)
Returns the specified Locale, or the default Locale if the specified Locale is null

Parameters:
loc - The default Locale
Returns:
A Java Locale instance

getDefaultLocale

public static java.util.Locale getDefaultLocale()
Gets the System default Locale

Returns:
The default Java Locale instance

getLocale

public java.util.Locale getLocale()
gets the Locale for this I18N instance

Returns:
The Locale

getKeys

public java.util.Enumeration getKeys()
Gets an Enumeration of the LocalString keys for this I18N instance

Returns:
The Enumeration of the LocalString keys for this I18N instance

printKeyValues

public void printKeyValues()
Prints all LocalString keys for this I18N instance


getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String dft)
Gets the Localized value for the specified key. The default String text is returned if the specified key does not exist

Parameters:
key - The LocalStrings key
dft - The default String text to return if the LocalStrings key does not exist
Returns:
The Localized String text

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String dft,
                                  java.lang.Object[] args)
Gets the Localized value for the specified key. The default String text is return if the specified key does not exist

Parameters:
key - The LocalStrings key
dft - The default String text to return if the LocalStrings key does not exist
args - An array of replacement fields
Returns:
The Localized String text

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String dft,
                                  java.lang.Object arg)
Gets the Localized value for the specified key. The default String text is return if the specified key does not exist

Parameters:
key - The LocalStrings key
dft - The default String text to return if the LocalStrings key does not exist
arg - A single replacement field
Returns:
The Localized String text

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String dft,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1)
Gets the Localized value for the specified key. The default String text is return if the specified key does not exist

Parameters:
key - The LocalStrings key
dft - The default String text to return if the LocalStrings key does not exist
arg0 - The first replacement field
arg1 - The second replacement field
Returns:
The Localized String text

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String dft,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1,
                                  java.lang.Object arg2)
Gets the Localized value for the specified key. The default String text is return if the specified key does not exist

Parameters:
key - The LocalStrings key
dft - The default String text to return if the LocalStrings key does not exist
arg0 - The first replacement field
arg1 - The second replacement field
arg2 - The third replacement field
Returns:
The Localized String text

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String dft,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1,
                                  java.lang.Object arg2,
                                  java.lang.Object arg3)
Gets the Localized value for the specified key. The default String text is return if the specified key does not exist

Parameters:
key - The LocalStrings key
dft - The default String text to return if the LocalStrings key does not exist
arg0 - The first replacement field
arg1 - The second replacement field
arg2 - The third replacement field
arg3 - The forth replacement field
Returns:
The Localized String text

NonNull

protected static java.lang.Object NonNull(java.lang.Object obj)
Returns the specified Object, or an empty String if the specified Object is null

Parameters:
obj - The Object to return
Returns:
The specified Object, or an empty String if the specified Object is null

decodeNewLine

protected static java.lang.String decodeNewLine(java.lang.String s)
Converts "\\n" patterns into literal newlines (\n)

Parameters:
s - The String to convert "\\n" to "\n"
Returns:
The decoded String

decodeNewLine

protected static java.lang.StringBuffer decodeNewLine(java.lang.StringBuffer s)
Converts "\\n" patterns into literal newlines (\n)

Parameters:
s - The StringBuffer to convert "\\n" to "\n"
Returns:
The decoded StringBuffer

parseText

public static I18N.Text parseText(java.lang.String pkg,
                                  java.lang.String key,
                                  java.lang.String dft)
Returns an I18N.Text instance used for lazy localization.
(use in XML loaders to avoid expression matches when auto-updating 'LocalStrings_XX.properties')

Parameters:
pkg - The package name
key - The localization key
dft - The default localized text
Returns:
An I18N.Text instance used for lazy localization

parseText

public static I18N.Text parseText(java.lang.String pkg,
                                  java.lang.String key,
                                  java.lang.String dft,
                                  boolean showError)
Returns an I18N.Text instance used for lazy localization.
(use in XML loaders to avoid expression matches when auto-updating 'LocalStrings_XX.properties')

Parameters:
pkg - The package name
key - The localization key
dft - The default localized text
showError - If true, a stacktrace will be display if the key is invalid.
Returns:
An I18N.Text instance used for lazy localization

_getString

public static I18N.Text _getString(java.lang.Class clazz,
                                   java.lang.String key,
                                   java.lang.String dft)
Returns an I18N.Text instance used for lazy localization

Parameters:
clazz - The class from which the package is derived
key - The localization key
dft - The default localized text
Returns:
An I18N.Text instance used for lazy localization

getString

public static I18N.Text getString(java.lang.Class clazz,
                                  java.lang.String key,
                                  java.lang.String dft)
Returns an I18N.Text instance used for lazy localization

Parameters:
clazz - The class from which the package is derived
key - The localization key
dft - The default localized text
Returns:
An I18N.Text instance used for lazy localization

main

public static void main(java.lang.String[] argv)
Debug/Testing entry point

Parameters:
argv - The command-line args