Applicet Framework for Applets and Applications v2.03

be.arci.applet
Class I18NDelegate

java.lang.Object
  |
  +--be.arci.applet.I18NDelegate

public class I18NDelegate
extends java.lang.Object

Groups all internationalization (I18N) support for the Applicet Framework, allowing to leave this out of the distribution package for basic applets. The Applicet I18N methods delegate to this class, of which a single instance is associated with the Applicet as soon as needed.

Use setLocale() to change the default locale of the Applicet. Use setI18NDefault() to change the I18N set of .properties files to use with getI18NString(), formatI18NString() etc. Use getI18NSet() to retrieve and read an I18N set of .properties files for yourself.

Note: We could have let you use ResourceBundle.getBundle() instead, but older versions of ResourceBundle, as used in many browsers, step on their own foot when trying to retrieve a .properties file with the same basename as a .class file. Also our I18N methods are more forgiving on missing resources. You might still want to use ResourceBundle for retrieving non-textual localized resources.

See Also:
Applicet.getI18NDelegate, JApplicet.getI18NDelegate, "Internationalization support", "java.awt.Component.setLocale()"

Method Summary
 java.lang.String formatI18NString(java.util.Properties prpI18NSet, java.lang.String sPatternName, java.lang.String sDefaultPattern, java.lang.Object[] aoArgs)
          Formats an array of Object arguments to a localized message according to the named pattern; the pattern name is used to look up both the localized pattern as well as localized argument Strings for those Object arguments that are null.
 java.util.Properties getI18NDefault()
          Returns the default I18N set of .properties files that is used by getI18NString(), formatI18NString() etc.
 java.lang.String[][] getI18NParameterInfo(java.util.Properties prpI18N, java.lang.String[][] aasDefault, char cDelimiter)
          Retrieves localized parameterinfo based on a default array of parameterinfo Strings.
 java.util.Properties getI18NSet()
          Loads and returns an I18N set of .properties files for the default locale, using the qualified Applicet subclass name as base name; if not found, an empty Properties object is returned.
 java.util.Properties getI18NSet(java.lang.Class clsBase)
          Loads and returns an I18N set of .properties files for the default locale, using the qualified name of the supplied class as base name; if not found, an empty Properties object is returned.
 java.util.Properties getI18NSet(java.lang.Class clsBase, java.util.Locale locTopLevel)
          Loads and returns an I18N set of .properties files for a specific locale, using the qualified name of the supplied class as base name; if not found, an empty Properties object is returned.
 java.util.Properties getI18NSet(java.util.Locale locTopLevel)
          Loads and returns an I18N set of .properties files for a specific locale, using the qualified name of the Applicet subclass as base name; if not found, an empty Properties object is returned.
 java.util.Properties getI18NSet(java.lang.String sBaseName)
          Loads and returns an I18N set of .properties files for the default locale, using the supplied qualified base name; if not found, an empty Properties object is returned.
 java.util.Properties getI18NSet(java.lang.String sBaseName, java.util.Locale locTopLevel)
          Loads and returns an I18N set of .properties files for a specific locale and qualified base name; if not found, an empty Properties object is returned.
 java.lang.String getI18NString(java.util.Properties prpI18NSet, java.lang.String sName, java.lang.String sDefault)
          Searches for the localized String with the specified name in the specified I18N set of .properties files.
 java.lang.String[] getI18NStringArray(java.util.Properties prpI18NSet, java.lang.String sName, java.lang.String sDefault, char cDelimiter)
          Searches for the localized String with the specified name in the specified I18N set of .properties files for this Applicet, and splits it into an array of Strings using the delimiter character.
 void setI18NDefault(java.util.Properties prpI18NDefault)
          Sets the default I18N set of .properties files for use in subsequent calls to getI18NString(), formatI18NString() etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getI18NString

public java.lang.String getI18NString(java.util.Properties prpI18NSet,
                                      java.lang.String sName,
                                      java.lang.String sDefault)
Searches for the localized String with the specified name in the specified I18N set of .properties files.

Parameters:
prpI18NSet - the I18N set of .properties files in which to look up localized Strings.
sName - the property name.
sDefault - the default value for the localized String.
Returns:
the localized String with the specified property name in the specified I18N properties set, or if not found the default value.
See Also:
Applicet.getI18NString, JApplicet.getI18NString, setI18NDefault

getI18NStringArray

public java.lang.String[] getI18NStringArray(java.util.Properties prpI18NSet,
                                             java.lang.String sName,
                                             java.lang.String sDefault,
                                             char cDelimiter)
Searches for the localized String with the specified name in the specified I18N set of .properties files for this Applicet, and splits it into an array of Strings using the delimiter character. Each array element is trimmed to remove leading and trailing whitespace. An empty String returns an array with 0 elements, a non-empty String without the delimiter character in it returns a 1-element array in which that element equals the trimmed String. A null String returns null.

Parameters:
prpI18NSet - the I18N set of .properties files in which to look up localized Strings.
sName - the property name.
sDefault - the default value for the localized String.
cDelimiter - character delimiting the String array elements in the localized String entry in the .properties files.
Returns:
the localized String split into an array, or if not found the default value split into an array using the same delimiter.
See Also:
Applicet.getStringArray, JApplicet.getStringArray, setI18NDefault, Applicet.getStringArray, JApplicet.getStringArray

formatI18NString

public java.lang.String formatI18NString(java.util.Properties prpI18NSet,
                                         java.lang.String sPatternName,
                                         java.lang.String sDefaultPattern,
                                         java.lang.Object[] aoArgs)
Formats an array of Object arguments to a localized message according to the named pattern; the pattern name is used to look up both the localized pattern as well as localized argument Strings for those Object arguments that are null.

Localized Strings are retrieved from the specified I18N set of .properties files

Formatting is done through java.text.MessageFormat, using the current locale of the Applicet (getLocale()). If an Object argument is not null, it is used as such (these Object arguments can be Strings too). If an Object argument is null, it is replaced with the localized String named "patternname.i", where i is the number (0-9) of the argument; if such localized String cannot be found, its name is used as default value.

If no formatting can be done (named pattern not found and no default pattern given), a return value is composed of the pattern name and the String representation of the Object arguments that are not null.

Parameters:
prpI18NSet - the I18N set of .properties files in which to look up localized Strings.
sPatternName - the property name of the pattern.
sDefaultPattern - the default pattern to use if the named pattern is not found.
aoArgs - array of Objects to format into the localized pattern String; a null Object aoArgs[i] is replaced by a localized String from the I18N set that has the property name (sPatternName + "." + i)
Returns:
the formatted localized message.
See Also:
Applicet.formatI18NString, JApplicet.formatI18NString, setI18NDefault

getI18NParameterInfo

public java.lang.String[][] getI18NParameterInfo(java.util.Properties prpI18N,
                                                 java.lang.String[][] aasDefault,
                                                 char cDelimiter)
Retrieves localized parameterinfo based on a default array of parameterinfo Strings. Localized Strings for type and description are retrieved from the specified I18N set of .properties files, using as key the parameter name prefixed with "info."; type and description entries in the .properties file should be separated by the delimiter character. The parameter names themselves are not localized.

An example of an appropriate parameter info definition can be found in be/arci/applet/Applicet.properties.

Parameters:
prpI18NSet - the I18N set of .properties files in which to look up localized Strings.

aasParameterInfo - array of parameter info Strings that acts as default. Each element of the array should be a String array with as first element the parameter name. Subsequent elements can supply default Strings for the type and description of the parameter. Default type and description String elements that are not present in the array or are null, will be replaced by an empty String if no localized String is found for them.

cDelimiter - separator between type and description Strings in the .properties files; one separated the respective Strings are trimmed.
Returns:
a validly structured return value for getParameterInfo().
See Also:
Applicet.getI18NParameterInfo, JApplicet.getI18NParameterInfo

getI18NDefault

public java.util.Properties getI18NDefault()
Returns the default I18N set of .properties files that is used by getI18NString(), formatI18NString() etc. If the I18N set is not yet loaded, it is done now.

IMPORTANT:
We are sure you know this already, but just that you don't forget:
use the getProperty() method of java.util.Properties on the return value, not the get() method of its superclass java.util.Hashtable. The get() wouldn't let you go down the hierarchical default of the I18N set.

Returns:
the current I18N set of Properties that is used in calls to getI18NString() and formatI18NString().
See Also:
Applicet.getI18NString, JApplicet.getI18NString, setI18NDefault, getI18NSet

setI18NDefault

public void setI18NDefault(java.util.Properties prpI18NDefault)
Sets the default I18N set of .properties files for use in subsequent calls to getI18NString(), formatI18NString() etc.
See Also:
Applicet.getI18NString, JApplicet.getI18NString, getI18NDefault, getI18NSet

getI18NSet

public java.util.Properties getI18NSet()
Loads and returns an I18N set of .properties files for the default locale, using the qualified Applicet subclass name as base name; if not found, an empty Properties object is returned.
See Also:
getI18NSet(String sBaseName, Locale locTopLevel), setI18NDefault, getI18NDefault

getI18NSet

public java.util.Properties getI18NSet(java.lang.Class clsBase)
Loads and returns an I18N set of .properties files for the default locale, using the qualified name of the supplied class as base name; if not found, an empty Properties object is returned.
See Also:
getI18NSet(Class clsBase, Locale locTopLevel), setI18NDefault, getI18NDefault

getI18NSet

public java.util.Properties getI18NSet(java.lang.String sBaseName)
Loads and returns an I18N set of .properties files for the default locale, using the supplied qualified base name; if not found, an empty Properties object is returned.
See Also:
getI18NSet(String sBaseName, Locale locTopLevel), setI18NDefault, getI18NDefault

getI18NSet

public java.util.Properties getI18NSet(java.util.Locale locTopLevel)
Loads and returns an I18N set of .properties files for a specific locale, using the qualified name of the Applicet subclass as base name; if not found, an empty Properties object is returned.
See Also:
getI18NSet(String sBaseName, Locale locTopLevel), setI18NDefault, getI18NDefault

getI18NSet

public java.util.Properties getI18NSet(java.lang.Class clsBase,
                                       java.util.Locale locTopLevel)
Loads and returns an I18N set of .properties files for a specific locale, using the qualified name of the supplied class as base name; if not found, an empty Properties object is returned.
Parameters:
baseClass - class that the requested .properties file is associated with; the qualified name of the class (without extension) serves as basename.
locTopLevel - highest locale in the I18N set hierarchy
See Also:
getI18NSet(String sBaseName, Locale locTopLevel), setI18NDefault, getI18NDefault

getI18NSet

public java.util.Properties getI18NSet(java.lang.String sBaseName,
                                       java.util.Locale locTopLevel)
Loads and returns an I18N set of .properties files for a specific locale and qualified base name; if not found, an empty Properties object is returned.

See Also:
getI18NSet(), getI18NSet(Locale), getI18NSet(String), setI18NDefault, getI18NDefault

Applicet Framework for Applets and Applications v2.03