public class

LocaleInfo

extends Object
java.lang.Object
   ↳ com.microstrategy.utils.localization.LocaleInfo

Class Overview

Class to provide locale-specific information such as date format, decimal separator, and thousands separator. Initialize a given instance of the class using a java.util.Locale object or a Windows LCID. getLocaleID and getLocale provide conversions between Windows- based locale ID's and Java Locale objects when necessary.

Summary

Constants
int MASK_COUNTRY
int MASK_CUSTOM_VARIANT
int MASK_LANGUAGE
String UNIT_CM Centimeter measurement units
String UNIT_IN Inch measurement units
String UNIT_MM Millimeter measurement units
String UNIT_PC Pica measurement units
String UNIT_PT Point measurement units
String UNIT_PX Pixel measurement units
Fields
public static final Locale NEUTRAL
Public Methods
static int convertJavaLocaleToLCID(Locale jLocale)
Converts a Java Locale to a Windows-based Locale ID.
static Locale convertLCIDToJavaLocale(int localeID)
Converts a Windows-based Locale ID to a Java Locale.
static Locale findBestSupportedLocale(Locale[] requested, Locale[] supported)
Returns the best supported locale given a requested list locale.
static Locale findBestSupportedLocale(Locale target, Locale[] supported)
String getCurrencyFormatString()
Returns the currency format string for the locale.
String getCurrencySymbol()
Returns the currency symbol for the locale.
int getCurrencySymbolPosition()
Returns the currency symbol position for the currency format corresponding to the locale.
char getDecimalSeparator()
Returns the decimal separator for the locale.
String getDecimalSeparatorString()
Returns the decimal separator for the locale as a String.
char getGroupingSeparator()
Returns the grouping (thousands) separator for the locale.
String getGroupingSeparatorString()
Returns the grouping (thousands) separator for the locale as a String.
static LocaleInfo getInstance()
Get a new LocaleInfo instance corresponding to the default locale.
static LocaleInfo getInstance(Locale jLocale)
Get a new LocaleInfo instance corresponding to the Locale passed in.
static LocaleInfo getInstance(int localeID)
Get a new LocaleInfo instance corresponding to the Windows-based locale ID passed in.
String getListSeparator()
Locale getLocale()
Returns the Java Locale for this object.
int getLocaleID()
Returns the Windows-based locale ID corresponding to the Java Locale for this object.
String getShortDateFormatString()
Returns the short date format string for the locale.
static void init(InputStream localesXML)
This should only be called ONCE during application initialization, as it's an expensive operation (involves file I/O and synchronization).
static void init(MessagesManager localesXML)
static Locale[] parseAcceptLanguage(String acceptLanguage)
String resolveMeasurementUnits(String unitPreference)
The method will resolve the measurement units the application is supposed to work in association with the use preferences set.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MASK_COUNTRY

Constant Value: 65280 (0x0000ff00)

public static final int MASK_CUSTOM_VARIANT

Constant Value: 535822336 (0x1ff00000)

public static final int MASK_LANGUAGE

Constant Value: 255 (0x000000ff)

public static final String UNIT_CM

Centimeter measurement units

Constant Value: "1"

public static final String UNIT_IN

Inch measurement units

Constant Value: "2"

public static final String UNIT_MM

Millimeter measurement units

Constant Value: "3"

public static final String UNIT_PC

Pica measurement units

Constant Value: "5"

public static final String UNIT_PT

Point measurement units

Constant Value: "4"

public static final String UNIT_PX

Pixel measurement units

Constant Value: "6"

Fields

public static final Locale NEUTRAL

Public Methods

public static int convertJavaLocaleToLCID (Locale jLocale)

Converts a Java Locale to a Windows-based Locale ID.

Parameters
jLocale Java locale
Returns
  • localeID int
Throws
IllegalArgumentException Indicates that a Windows-based locale ID could not be found for the Java Locale passed in.

public static Locale convertLCIDToJavaLocale (int localeID)

Converts a Windows-based Locale ID to a Java Locale. If the LCID is not codified in this class or declared in locales.xml, a custom Locale instance will be returned with getLanguage() = LCID & MASK_LANGUAGE, getCountry() = (LCID & MASK_COUNTRY) >>> 8, and getVariant() = (LCID & MASK_CUSTOM_VARIANT) >>> 24.

Parameters
localeID the LCID
Returns
  • java.util.Locale
Throws
IllegalArgumentException

public static Locale findBestSupportedLocale (Locale[] requested, Locale[] supported)

Returns the best supported locale given a requested list locale. If either requested or supported arrays are empty, null is returned.

Returns
  • the best supported locale

public static Locale findBestSupportedLocale (Locale target, Locale[] supported)

public String getCurrencyFormatString ()

Returns the currency format string for the locale. Note that the string returned is not localized (for example, "," and "." are used for the grouping and decimal separators, repectively). The character used for the currency symbol is 'ยค'.

Returns
  • The currency format string for the locale.
Throws
UnsupportedOperationException Thrown if decimal format information could not be obtained for the locale.

public String getCurrencySymbol ()

Returns the currency symbol for the locale. This can be multiple characters.

Returns
  • The currency symbol for the locale.

public int getCurrencySymbolPosition ()

Returns the currency symbol position for the currency format corresponding to the locale. This will be a value from EnumGridNumberCurrencyPosition. Only the positive currency format string is considered when locating the position. The algorithm is as follows: If the symbol is found in the currency format prefix, we return LEFT_SPACE if the symbol is followed by a space and LEFT otherwise. If the symbol is found in the currency format suffix, we return RIGHT_SPACE if the symbol is preceeded by a space and RIGHT otherwise. If the symbol is not found in the format string, we return LEFT.

Returns
  • The currency symbol position for the currency format corresponding to the locale.
Throws
UnsupportedOperationException Thrown if decimal format information could not be obtained for the locale.

public char getDecimalSeparator ()

Returns the decimal separator for the locale. This is the same symbol that would be returned by DecimalFormatSymbols.getDecimalSeparator. For example, in the U.S. locale, this would be '.'.

Returns
  • The decimal separator for the locale.

public String getDecimalSeparatorString ()

Returns the decimal separator for the locale as a String. This is the same symbol that would be returned by DecimalFormatSymbols.getDecimalSeparator. For example, in the U.S. locale, this would be ".". Note that the locale may have a different monetary decimal separator.

Returns
  • The decimal separator for the locale.

public char getGroupingSeparator ()

Returns the grouping (thousands) separator for the locale. This is the same symbol that would be returned by DecimalFormatSymbols.getGroupingSeparator. For example, in the U.S. locale, this would be ','.

Returns
  • The grouping separator for the locale.

public String getGroupingSeparatorString ()

Returns the grouping (thousands) separator for the locale as a String. This is the same symbol that would be returned by DecimalFormatSymbols.getGroupingSeparator. For example, in the U.S. locale, this would be ",".

Returns
  • The grouping separator for the locale.

public static LocaleInfo getInstance ()

Get a new LocaleInfo instance corresponding to the default locale.

Returns
  • Reference to a newly created LocaleInfo instance.

public static LocaleInfo getInstance (Locale jLocale)

Get a new LocaleInfo instance corresponding to the Locale passed in.

Parameters
jLocale A java.util.Locale object corresponding to the locale for which you want formatting information.
Returns
  • Reference to a newly created LocaleInfo instance.

public static LocaleInfo getInstance (int localeID)

Get a new LocaleInfo instance corresponding to the Windows-based locale ID passed in.

Parameters
localeID A Windows-based locale ID corresponding to the locale for which you want formatting information.
Returns
  • Reference to a newly created LocaleInfo instance.
Throws
IllegalArgumentException Indicates that a Java Locale could not be found for the Windows-based locale ID passed in.

public String getListSeparator ()

public Locale getLocale ()

Returns the Java Locale for this object.

Returns
  • java.util.Locale

public int getLocaleID ()

Returns the Windows-based locale ID corresponding to the Java Locale for this object. If this object was initialized with a Windows-based locale ID, then that locale ID will be returned. Otherwise, the internal Java Locale will be converted to a Windows locale ID.

Returns
  • The Windows-based locale ID corresponding to the internal locale.
Throws
UnsupportedOperationException Thrown in the event that the object was not originally initialized with a Windows LCID, and the internal Java Locale could not be converted into a Windows LCID.

public String getShortDateFormatString ()

Returns the short date format string for the locale. This is the same date format that would be returned by SimpleDateFormat.toPattern, assuming the date style is DateFormat.SHORT. For example, in the U.S. locale, this would be "M/d/yy".

Returns
  • The short date format string for the locale.
Throws
UnsupportedOperationException Thrown if the locale does not support returning a date format string.

public static void init (InputStream localesXML)

This should only be called ONCE during application initialization, as it's an expensive operation (involves file I/O and synchronization). It's important to ensure all commonly utilized locales are declared in locales.xml for optimal performance.

Parameters
localesXML locales.xml file location
Throws
SAXException thrown if an error occurs while parsing.
IOException thrown if an error occurs while reading file.

public static void init (MessagesManager localesXML)

public static Locale[] parseAcceptLanguage (String acceptLanguage)

Parameters
acceptLanguage The HTTP Accept-Language header value as defined by http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Returns
  • requested locales array sorted by quality, highest first

public String resolveMeasurementUnits (String unitPreference)

The method will resolve the measurement units the application is supposed to work in association with the use preferences set.

Parameters
unitPreference String to represent the preference for measurement unit.
Returns
  • The associated units constant.