/* try the cache first */
String[][] data = (String[][]) cachedLocaleData.get(locale);
String[] numberElements;
if (data == null) { /* cache miss */
data = new String[1][];
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.
getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
data[0] = rb.getStringArray("NumberElements");
/* update cache */
cachedLocaleData.put(locale, data);
}
numberElements = data[0];
ICUResourceBundle r = (ICUResourceBundle)UResourceBundle.
getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
// TODO: Determine actual and valid locale correctly.
ULocale uloc = r.getULocale();
setLocale(uloc, uloc);
// {dlf} clean up below now that we have our own resource data
decimalSeparator = numberElements[0].charAt(0);
groupingSeparator = numberElements[1].charAt(0);
// Temporary hack to support old JDK 1.1 resources
// patternSeparator = numberElements[2].length() > 0 ?
// numberElements[2].charAt(0) : ';';
patternSeparator = numberElements[2].charAt(0);
percent = numberElements[3].charAt(0);
zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
digit = numberElements[5].charAt(0);
minusSign = numberElements[6].charAt(0);
// Temporary hack to support JDK versions before 1.1.6 (?)
// exponentSeparator = numberElements.length >= 9 ?
// numberElements[7] : DecimalFormat.PATTERN_EXPONENT;
// perMill = numberElements.length >= 9 ?
// numberElements[8].charAt(0) : '\u2030';
// infinity = numberElements.length >= 10 ?
// numberElements[9] : "\u221e";
// NaN = numberElements.length >= 11 ?
// numberElements[10] : "\ufffd";
exponentSeparator = numberElements[7];
perMill = numberElements[8].charAt(0);
infinity = numberElements[9];
NaN = numberElements[10];
plusSign =numberElements[11].charAt(0);
padEscape = DecimalFormat.PATTERN_PAD_ESCAPE;
sigDigit = DecimalFormat.PATTERN_SIGNIFICANT_DIGIT;
// Attempt to set the zero digit based on the numbering system for the locale requested
//
NumberingSystem ns = NumberingSystem.getInstance(locale);
if ( ns != null && ns.getRadix() == 10 && !ns.isAlgorithmic()) {
zeroDigit = ns.getDescription().charAt(0);
}
// Obtain currency data from the currency API. This is strictly
// for backward compatibility; we don't use DecimalFormatSymbols
// for currency data anymore.
String currname = null;
currency = Currency.getInstance(locale);
if (currency != null) {
intlCurrencySymbol = currency.getCurrencyCode();
boolean[] isChoiceFormat = new boolean[1];
currname = currency.getName(locale,
Currency.SYMBOL_NAME,
isChoiceFormat);
// If this is a ChoiceFormat currency, then format an
// arbitrary value; pick something != 1; more common.
currencySymbol = isChoiceFormat[0]
? new ChoiceFormat(currname).format(2.0)
: currname;
} else {
intlCurrencySymbol = "XXX";
currencySymbol = "\u00A4"; // 'OX' currency symbol
}
// If there is a currency decimal, use it.
monetarySeparator = decimalSeparator;
monetaryGroupingSeparator = groupingSeparator;
Currency curr = Currency.getInstance(locale);
if(curr!=null){
String currencyCode = curr.getCurrencyCode();
if(currencyCode != null) {
/* An explicit currency was requested */
ICUResourceBundle resource = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
ICUResourceBundle currencyRes = resource.getWithFallback("Currencies");
try{
currencyRes = currencyRes.getWithFallback(currencyCode);
if(currencyRes.getSize()>2) {
currencyRes = (ICUResourceBundle)currencyRes.get(2);
currencyPattern = currencyRes.getString(0);
monetarySeparator = currencyRes.getString(1).charAt(0);
monetaryGroupingSeparator = currencyRes.getString(2).charAt(0);
}
}catch(MissingResourceException ex){
/* else An explicit currency was requested and is unknown or locale data is malformed. */
/* decimal format API will get the correct value later on. */
}
}
/* else no currency keyword used. */
}
//monetarySeparator = numberElements[11].charAt(0);
// Get Currency Spacing data.
currencySpcBeforeSym = new String[CURRENCY_SPC_INSERT+1];
currencySpcAfterSym = new String[CURRENCY_SPC_INSERT+1];
ICUResourceBundle curSpcBundle = (ICUResourceBundle)r.get(CURRENCY_SPACING);
if (curSpcBundle != null) {
ICUResourceBundle beforeCurBundle = (ICUResourceBundle)curSpcBundle.get(BEFORE_CURRENCY);
ICUResourceBundle afterCurBundle = (ICUResourceBundle)curSpcBundle.get(AFTER_CURRENCY);
for (int i = CURRENCY_SPC_CURRENCY_MATCH; i <= CURRENCY_SPC_INSERT; i++) {
currencySpcBeforeSym[i] = beforeCurBundle.getStringWithFallback(CURRENCY_SPACING_KEYS[i]);
currencySpcAfterSym[i] = afterCurBundle.getStringWithFallback(CURRENCY_SPACING_KEYS[i]);
}
}
}