Class I18n
- java.lang.Object
-
- com.iplanet.services.util.I18n
-
public class I18n extends Object
TheI18nclass provides methods for applications and services to internationalize their messages.In order for
I18nto internationalize messages, it needs to determine the resource bundle name, i.e., properties file name.I18nsupports two techniques by which applications and services can specify their I18N resource bundle name. The recommendation is to specify them during service (or application) registration via SMS using a XML file (seecom.iplanet.services.ServiceManagerand service registration DTD). The XML file could specify the resource bundle name (the attribute defined in the DTD isi18nFileName) and optionally URL of the jar file which contains the property file (the attribute defined in the DTD isresourceBundleURL). If URL for the jar file is not specified it is assumed that the resource bundle is in theCLASSPATH. Using this technique it is possible to customize resource bundle name and URL of the jar file by using SMS APIs, commands (CLI) or GUI. The solution makes internationalization of messages very dynamic and highly customizable.I18nclass be instantiated by calling the staticgetInstance(String serviceName)method. The parameterserviceNamespecifies the name of the service as mentioned in the XML file at the time of service registration.Alternatively services and application can instantiate
I18nobject by specifying the resource bundle name (i.e., properties file name). Using this technique it is not possible to customize at runtime either the resource bundle name or the URL of the jar file that contains the properties file name. It is assumed that the properties file is present inCLASSPATH
-
-
Field Summary
Fields Modifier and Type Field Description static StringASCII_CHARSET
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringdecodeCharset(String s, String charset)Decodes the string into specified charsetstatic Stringformat(String pattern, Integer i, String l)Formats the objects into specified message format.static Stringformat(String pattern, Long j, String l)Formats the objects into specified message format.static Stringformat(String pattern, Date d, TimeZone tz, String l)Formats the objects into specified message formatstatic I18ngetInstance(String serviceName)Method to get an instance of I18n object that has been either previously created or to obtain a new instance if it does'nt existstatic LocalegetLocale(String stringformat)Method to obtain Locale object given its string representationStringgetResBundleName()Returns the resource file name associated with the serviceStringgetString(String key)Method to obtain internationalized message from the resource bundle given the key.StringgetString(String key, Object[] params)Method to obtain internationalized message from the resource bundle given the key and parameters.StringgetString(String key, String locale)Method to obtain internationalized message from the resource bundle given the key and locale.StringgetString(String key, String locale, Object[] params)Method to obtain internationalized message from the resource bundle given the key, locale and parameters.static booleanisAscii(String s)Checks whether the string is ascii or not
-
-
-
Field Detail
-
ASCII_CHARSET
public static final String ASCII_CHARSET
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
I18n
protected I18n(String serviceName)
This constructor takes the name of the component as an argument and it should match with name of the resource bundle
-
-
Method Detail
-
getInstance
public static I18n getInstance(String serviceName)
Method to get an instance of I18n object that has been either previously created or to obtain a new instance if it does'nt exist- Parameters:
serviceName- name of the service for which messages must be internationalized- Returns:
- I18n object
-
getLocale
public static Locale getLocale(String stringformat)
Method to obtain Locale object given its string representation- Parameters:
stringformat- Locale in a string format- Returns:
- Locale object
-
getResBundleName
public String getResBundleName()
Returns the resource file name associated with the service- Returns:
- Returns the the ResourceBundle name associated with the service
-
getString
public String getString(String key, String locale)
Method to obtain internationalized message from the resource bundle given the key and locale.- Parameters:
key- key string in the properties filelocale- locale in a string format- Returns:
- returns internationalized message for the specified key
-
getString
public String getString(String key)
Method to obtain internationalized message from the resource bundle given the key.- Parameters:
key- Key string in the properties file- Returns:
- Returns value to the specified key
-
getString
public String getString(String key, String locale, Object[] params)
Method to obtain internationalized message from the resource bundle given the key, locale and parameters.- Parameters:
key- key string in the properties filelocale- locale in a string formatparams- parameters to be applied to the message- Returns:
- returns internationalized message for the specified key
-
getString
public String getString(String key, Object[] params)
Method to obtain internationalized message from the resource bundle given the key and parameters.- Parameters:
key- Key string in the properties fileparams- parameters to be applied to the message- Returns:
- Returns value to the specified key
-
decodeCharset
public static String decodeCharset(String s, String charset)
Decodes the string into specified charset- Parameters:
s- string to be decodedcharset- character set in which the string to be decoded- Returns:
- Returns the decoded string
-
isAscii
public static boolean isAscii(String s)
Checks whether the string is ascii or not- Parameters:
s- string to be checked- Returns:
- true if the string is ascii, otherwise false
-
format
public static String format(String pattern, Long j, String l)
Formats the objects into specified message format.- Parameters:
pattern- pattern for which the message to be formattedj- Object to be formatted & substitutedl- locale in a string format- Returns:
- Returns the formatted message
-
format
public static String format(String pattern, Integer i, String l)
Formats the objects into specified message format.- Parameters:
pattern- pattern for which the message to be formattedi- Integer to be formatted & substitutedl- locale in a string format- Returns:
- Returns the formatted message
-
-