wt.util
Class LocaleUtilities

java.lang.Object
  extended bywt.util.LocaleUtilities

public class LocaleUtilities
extends Object

LocaleUtilities provides utility methods for working with Locales.

Supported API: true

Extendable: false

See Also:
Locale

Field Summary
private static Hashtable cvEncodings
           
static String LOCALE_CHARSET_PROPERTY
           
private static Locale[] supportedLocales
           
private static byte[] UTF8_BOM
           
 
Constructor Summary
LocaleUtilities()
           
 
Method Summary
static String getDefaultEncoding()
          Gets the default file encoding.
static String getEncoding(Locale locale)
          Gets the localized file encoding for the locale.
static String getEncoding(Locale locale, String file_name)
          Gets the localized file encoding for the locale code.
static String getEncoding(String locale_code)
          Gets the localized file encoding for the locale code.
static String getEncoding(String base_property, Locale locale)
          Gets the localized file encoding for the locale.
static String getEncoding(String base_property, Locale locale, String file_name)
          Gets the localized file encoding for the locale code.
static String getEncoding(String base_property, String locale_code)
          Gets the localized file encoding for the locale code.
static String getEncoding(String base_property, String locale_code, String file_name)
          Gets the localized file encoding for the locale code.
static Locale[] getSupportedLocales()
          Gets the array of supported Locales, as defined by the wt.locale.set property in wt.properties.
static boolean hasUTF8ByteOrderMark(String file_name)
          Determine if a file has a UTF-8 byte order mark.
static Locale makeLocale(String locale)
          Construct a Locale instance for the locale String.
static Locale makeLocale(String[] args, int startIndex)
          Construct a Locale instance for the args String array.
static Locale[] makeLocales(String delimitedlist, String separators)
          Construct an array of Locales, based on a delimited String.
static String toString(Locale[] locales)
          Construct a String that represents the contents of an array of Locales.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALE_CHARSET_PROPERTY

public static final String LOCALE_CHARSET_PROPERTY
See Also:
Constant Field Values

supportedLocales

private static Locale[] supportedLocales

cvEncodings

private static Hashtable cvEncodings

UTF8_BOM

private static final byte[] UTF8_BOM
Constructor Detail

LocaleUtilities

public LocaleUtilities()
Method Detail

hasUTF8ByteOrderMark

public static boolean hasUTF8ByteOrderMark(String file_name)
                                    throws IOException
Determine if a file has a UTF-8 byte order mark.

Returns:
true if file contain the UTF-8 BOM.
Throws:
IOException

getEncoding

public static String getEncoding(Locale locale,
                                 String file_name)
                          throws IOException
Gets the localized file encoding for the locale code. This encoding is specified in wt.properties, with the default base property being defined by LOCALE_CHARSET_PROPERTY, if not embedded in the file.

This method should be used to get the encoding of a file being read (e.g., .rbInfo or .ser file). To get the encoding value to set for an HTML file being written, use the getEncoding method in wt.htmlutil.HtmlUtil.

Parameters:
locale - - the locale for which encoding is needed
file_name - - name of file to check
Returns:
The encoding name for the file and/or locale.
Throws:
IOException
See Also:
HtmlUtil

getEncoding

public static String getEncoding(String base_property,
                                 Locale locale,
                                 String file_name)
                          throws IOException
Gets the localized file encoding for the locale code. This encoding is specified in wt.properties, for the base property, if not embedded in the file.

This method should be used to get the encoding of a file being read (e.g., .rbInfo or .ser file). To get the encoding value to set for an HTML file being written, use the getEncoding method in wt.htmlutil.HtmlUtil.

Parameters:
base_property - - the base property name to use
locale - - the locale for which encoding is needed
file_name - - name of file to check
Returns:
The encoding name for the file and/or locale.
Throws:
IOException
See Also:
HtmlUtil

getEncoding

public static String getEncoding(String base_property,
                                 String locale_code,
                                 String file_name)
                          throws IOException
Gets the localized file encoding for the locale code. This encoding is specified in wt.properties, for the base property, if not embedded in the file.

This method should be used to get the encoding of a file being read (e.g., .rbInfo or .ser file). To get the encoding value to set for an HTML file being written, use the getEncoding method in wt.htmlutil.HtmlUtil.

Parameters:
base_property - - the base property name to use
locale_code - - the locale code for which encoding is needed
file_name - - name of file for which encoding is needed
Returns:
The encoding name for the file and/or locale.
Throws:
IOException
See Also:
HtmlUtil

getDefaultEncoding

public static String getDefaultEncoding()
Gets the default file encoding. This encoding is specified in wt.properties.

This method should be used to get the encoding of a file being read (e.g., .rbInfo or .ser file). To get the encoding value to set for an HTML file being written, use the getDefaultEncoding method in wt.htmlutil.HtmlUtil.

Returns:
The encoding name for the locale.
See Also:
HtmlUtil

getEncoding

public static String getEncoding(String locale_code)
Gets the localized file encoding for the locale code. This encoding is specified in wt.properties, with the default base property being defined by LOCALE_CHARSET_PROPERTY.

This method should be used to get the encoding of a file being read (e.g., .rbInfo or .ser file). To get the encoding value to set for an HTML file being written, use the getEncoding method in wt.htmlutil.HtmlUtil.

Parameters:
locale_code - - the locale code for which encoding is needed
Returns:
The encoding name for the locale.
See Also:
LOCALE_CHARSET_PROPERTY, HtmlUtil

getEncoding

public static String getEncoding(String base_property,
                                 String locale_code)
Gets the localized file encoding for the locale code. This encoding is specified in wt.properties, for the baseProperty.

This method should be used to get the encoding of a file being read (e.g., .rbInfo or .ser file). To get the encoding value to set for an HTML file being written, use the getEncoding method in wt.htmlutil.HtmlUtil.

Parameters:
base_property - - the base property name to use
locale_code - - the locale code for which encoding is needed
Returns:
The encoding name for the locale.
See Also:
HtmlUtil

getEncoding

public static String getEncoding(String base_property,
                                 Locale locale)
Gets the localized file encoding for the locale. This encoding is specified in wt.properties, for the baseProperty.

This method should be used to get the encoding of a file being read (e.g., .rbInfo or .ser file). To get the encoding value to set for an HTML file being written, use the getEncoding method in wt.htmlutil.HtmlUtil.

Parameters:
base_property - - the base property name to use
locale - - the Locale for which encoding is needed
Returns:
The encoding name for the locale.
See Also:
HtmlUtil

getEncoding

public static String getEncoding(Locale locale)
Gets the localized file encoding for the locale. This encoding is specified in wt.properties, with the default base property being defined by LOCALE_CHARSET_PROPERTY.

This method should be used to get the encoding of a file being read (e.g., .rbInfo or .ser file). To get the encoding value to set for an HTML file being written, use the getEncoding method in wt.htmlutil.HtmlUtil.

Parameters:
locale - - the Locale for which encoding is needed
Returns:
The encoding name for the locale.
See Also:
LOCALE_CHARSET_PROPERTY, HtmlUtil

getSupportedLocales

public static Locale[] getSupportedLocales()
Gets the array of supported Locales, as defined by the wt.locale.set property in wt.properties.

Returns:
An array of the supported Locales.

makeLocale

public static Locale makeLocale(String[] args,
                                int startIndex)
Construct a Locale instance for the args String array.
   Example Usage:
  	LocaleUtilities.makeLocale( ["xyz","fr"], 1 )   // returns fr Locale

  	LocaleUtilities.makeLocale( ["fr","CA"], 0 )    // returns fr_CA Locale

  

Parameters:
args - - series of Strings that, starting at the specified index, represent a Locale
startIndex - - the index of the array that begins Locale specification
Returns:
A Locale for the args String array.

makeLocale

public static Locale makeLocale(String locale)
Construct a Locale instance for the locale String.
   Example Usage:
  	LocaleUtilities.makeLocale( "fr" )     // returns fr Locale

  	LocaleUtilities.makeLocale( "fr_CA" )  // returns fr_CA Locale

  

Parameters:
locale - - the String representation of a Locale
Returns:
A Locale for the locale String.

makeLocales

public static Locale[] makeLocales(String delimitedlist,
                                   String separators)
Construct an array of Locales, based on a delimited String.
   Example Usage:
  	LocaleUtilities.makeLocales( "fr,de", "," )     // returns [fr,de]

  	LocaleUtilities.makeLocales( "fr_CA,de", "," )  // returns [fr_CA,de]

  	LocaleUtilities.makeLocales( "fr_CA,de", ",_" ) // returns [fr,CA,de]

  

Parameters:
delimitedlist - - the String to convert
separators - - the separators to consider
Returns:
A Locale array, which contains that Strings that were in the delimitedList.

toString

public static String toString(Locale[] locales)
Construct a String that represents the contents of an array of Locales.
   Example Usage:
  	LocaleUtilities.toString( [fr,de] )     // returns "fr,de"

  	LocaleUtilities.toString( [fr_CA,de] )  // returns "fr_CA,de"

  	LocaleUtilities.toString( [fr,CA,de] )  // returns "fr,CA,de"

  

Parameters:
locales - - an array of Locale objects
Returns:
A comma delimited String of locale codes.