Index: luni/src/main/java/java/util/Currency.java =================================================================== --- luni/src/main/java/java/util/Currency.java (revision 590549) +++ luni/src/main/java/java/util/Currency.java (working copy) @@ -19,8 +19,6 @@ import java.io.Serializable; -import org.apache.harmony.luni.util.Msg; - /** * This class represents a currency as identified in the ISO 4217 currency * codes. @@ -33,10 +31,6 @@ private String currencyCode; - private static String currencyVars = "EURO, HK, PREEURO"; //$NON-NLS-1$ - - private transient int defaultFractionDigits; - /** * @param currencyCode */ @@ -60,20 +54,7 @@ Currency currency = codesToCurrencies.get(currencyCode); if (currency == null) { - ResourceBundle bundle = Locale.getBundle( - "ISO4CurrenciesToDigits", Locale.getDefault()); //$NON-NLS-1$ currency = new Currency(currencyCode); - - String defaultFractionDigits = null; - try { - defaultFractionDigits = bundle.getString(currencyCode); - } catch (MissingResourceException e) { - throw new IllegalArgumentException( - org.apache.harmony.luni.util.Msg.getString( - "K0322", currencyCode)); //$NON-NLS-1$ - } - currency.defaultFractionDigits = Integer - .parseInt(defaultFractionDigits); codesToCurrencies.put(currencyCode, currency); } @@ -91,22 +72,12 @@ * if the locale's country is not a supported ISO 3166 Country */ public static Currency getInstance(Locale locale) { - String country = locale.getCountry(); - String variant = locale.getVariant(); - if (!variant.equals("") && currencyVars.indexOf(variant) > -1) { //$NON-NLS-1$ - country = country + "_" + variant; //$NON-NLS-1$ + com.ibm.icu.util.Currency currency = com.ibm.icu.util.Currency.getInstance(locale); + if(currency == null) { + return null; } + String currencyCode = currency.getCurrencyCode(); - ResourceBundle bundle = Locale.getBundle( - "ISO4Currencies", Locale.getDefault()); //$NON-NLS-1$ - String currencyCode = null; - try { - currencyCode = bundle.getString(country); - } catch (MissingResourceException e) { - throw new IllegalArgumentException(Msg.getString( - "K0323", locale.toString())); //$NON-NLS-1$ - } - if (currencyCode.equals("None")) { //$NON-NLS-1$ return null; } @@ -161,35 +132,7 @@ if (locale.getCountry().equals("")) { //$NON-NLS-1$ return currencyCode; } - - // check in the Locale bundle first, if the local has the same currency - ResourceBundle bundle = Locale.getBundle("Locale", locale); //$NON-NLS-1$ - if (((String) bundle.getObject("IntCurrencySymbol")) //$NON-NLS-1$ - .equals(currencyCode)) { - return (String) bundle.getObject("CurrencySymbol"); //$NON-NLS-1$ - } - - // search for a Currency bundle - bundle = null; - try { - bundle = Locale.getBundle("Currency", locale); //$NON-NLS-1$ - } catch (MissingResourceException e) { - return currencyCode; - } - - // is the bundle found for a different country? (for instance the - // default locale's currency bundle) - if (!bundle.getLocale().getCountry().equals(locale.getCountry())) { - return currencyCode; - } - - // check if the currency bundle for this locale - // has an entry for this currency - String result = (String) bundle.handleGetObject(currencyCode); - if (result != null) { - return result; - } - return currencyCode; + return com.ibm.icu.util.Currency.getInstance(currencyCode).getSymbol(locale); } /** @@ -200,7 +143,7 @@ * @return the default number of fraction digits for this currency */ public int getDefaultFractionDigits() { - return defaultFractionDigits; + return com.ibm.icu.util.Currency.getInstance(currencyCode).getDefaultFractionDigits(); } /** Index: luni/src/main/java/java/util/Calendar.java =================================================================== --- luni/src/main/java/java/util/Calendar.java (revision 590549) +++ luni/src/main/java/java/util/Calendar.java (working copy) @@ -129,12 +129,13 @@ * the locale */ protected Calendar(TimeZone timezone, Locale locale) { - this(timezone); - ResourceBundle bundle = Locale.getBundle("Locale", locale); //$NON-NLS-1$ - setFirstDayOfWeek(((Integer) bundle.getObject("First_Day")).intValue()); //$NON-NLS-1$ - setMinimalDaysInFirstWeek(((Integer) bundle.getObject("Minimal_Days")) //$NON-NLS-1$ - .intValue()); - } + this(timezone); + com.ibm.icu.util.Calendar icuCalendar = com.ibm.icu.util.Calendar + .getInstance(com.ibm.icu.util.SimpleTimeZone + .getTimeZone(timezone.getID()), locale); + setFirstDayOfWeek(icuCalendar.getFirstDayOfWeek()); + setMinimalDaysInFirstWeek(icuCalendar.getMinimalDaysInFirstWeek()); + } /** * Adds the specified amount to a Calendar field. Index: luni/src/main/java/java/util/TimeZone.java =================================================================== --- luni/src/main/java/java/util/TimeZone.java (revision 590549) +++ luni/src/main/java/java/util/TimeZone.java (working copy) @@ -20,6 +20,7 @@ import java.io.Serializable; import java.security.AccessController; +import java.security.PrivilegedAction; import java.text.DateFormatSymbols; import org.apache.harmony.luni.util.PriviAction; @@ -445,8 +446,27 @@ */ public static synchronized void setDefault(TimeZone timezone) { if (timezone != null) { - Default = timezone; - return; + final com.ibm.icu.util.TimeZone icuTZ = com.ibm.icu.util.TimeZone + .getTimeZone(timezone.getID()); + + AccessController + .doPrivileged(new PrivilegedAction() { + public java.lang.reflect.Field run() { + java.lang.reflect.Field field = null; + try { + field = com.ibm.icu.util.TimeZone.class + .getDeclaredField("defaultZone"); + field.setAccessible(true); + field.set("defaultZone", icuTZ); + } catch (Exception e) { + return null; + } + return field; + } + }); + + Default = timezone; + return; } String zone = AccessController.doPrivileged(new PriviAction( Index: luni/src/main/java/java/util/Locale.java =================================================================== --- luni/src/main/java/java/util/Locale.java (revision 590549) +++ luni/src/main/java/java/util/Locale.java (working copy) @@ -24,15 +24,13 @@ import java.io.ObjectStreamField; import java.io.Serializable; import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import org.apache.harmony.luni.internal.locale.Country; -import org.apache.harmony.luni.internal.locale.Language; import org.apache.harmony.luni.util.PriviAction; -import org.apache.harmony.luni.util.Util; +import com.ibm.icu.util.ULocale; + /** * Locale represents a language/country/variant combination. It is an identifier * which dictates particular conventions for the presentation of information. @@ -46,8 +44,6 @@ private static final long serialVersionUID = 9149081749638150636L; - private static volatile Locale[] availableLocales; - // Initialize a default which is used during static // initialization of the default for the platform. private static Locale defaultLocale = new Locale(); @@ -174,6 +170,8 @@ private transient String languageCode; private transient String variantCode; + private transient ULocale uLocale; + /** * Constructs a default which is used during static initialization of the * default for the platform. @@ -218,7 +216,14 @@ if (language == null || country == null || variant == null) { throw new NullPointerException(); } - languageCode = Util.toASCIILowerCase(language); + if(language.length() == 0 && country.length() == 0){ + languageCode = ""; + countryCode = ""; + variantCode = variant; + return; + } + this.uLocale = new ULocale(language, country, variant); + languageCode = uLocale.getLanguage(); // Map new language codes to the obsolete language // codes so the correct resource bundles will be used. if (languageCode.equals("he")) {//$NON-NLS-1$ @@ -230,9 +235,9 @@ } // countryCode is defined in ASCII character set - countryCode = Util.toASCIIUpperCase(country); + countryCode = uLocale.getCountry(); - variantCode = variant; + variantCode = uLocale.getVariant(); } /** @@ -367,15 +372,12 @@ * @return an array of Locale */ public static Locale[] getAvailableLocales() { - if (availableLocales == null) { - availableLocales = AccessController - .doPrivileged(new PrivilegedAction() { - public Locale[] run() { - return find("org/apache/harmony/luni/internal/locale/Locale_"); //$NON-NLS-1$ - } - }); + ULocale[] ulocales = ULocale.getAvailableLocales(); + Locale[] locales = new Locale[ulocales.length]; + for (int i = 0; i < locales.length; i++) { + locales[i] = ulocales[i].toLocale(); } - return availableLocales.clone(); + return locales; } /** @@ -417,24 +419,7 @@ * @return a country name */ public String getDisplayCountry(Locale locale) { - if (countryCode.length() == 0) { - return countryCode; - } - try { - // First try the specified locale - ResourceBundle bundle = getBundle("Country", locale); //$NON-NLS-1$ - String result = (String) bundle.handleGetObject(countryCode); - if (result != null) { - return result; - } - // Now use the default locale - if (locale != Locale.getDefault()) { - bundle = getBundle("Country", Locale.getDefault()); //$NON-NLS-1$ - } - return bundle.getString(countryCode); - } catch (MissingResourceException e) { - return countryCode; - } + return ULocale.forLocale(this).getDisplayCountry(ULocale.forLocale(locale)); } /** @@ -458,24 +443,7 @@ * @return a language name */ public String getDisplayLanguage(Locale locale) { - if (languageCode.length() == 0) { - return languageCode; - } - try { - // First try the specified locale - ResourceBundle bundle = getBundle("Language", locale); //$NON-NLS-1$ - String result = (String) bundle.handleGetObject(languageCode); - if (result != null) { - return result; - } - // Now use the default locale - if (locale != Locale.getDefault()) { - bundle = getBundle("Language", Locale.getDefault()); //$NON-NLS-1$ - } - return bundle.getString(languageCode); - } catch (MissingResourceException e) { - return languageCode; - } + return ULocale.forLocale(this).getDisplayLanguage(ULocale.forLocale(locale)); } /** @@ -546,31 +514,7 @@ * @return a variant name */ public String getDisplayVariant(Locale locale) { - if (variantCode.length() == 0) { - return variantCode; - } - ResourceBundle bundle; - try { - bundle = getBundle("Variant", locale); //$NON-NLS-1$ - } catch (MissingResourceException e) { - return variantCode.replace('_', ','); - } - - StringBuffer result = new StringBuffer(); - StringTokenizer tokens = new StringTokenizer(variantCode, "_"); //$NON-NLS-1$ - while (tokens.hasMoreTokens()) { - String code, variant = tokens.nextToken(); - try { - code = bundle.getString(variant); - } catch (MissingResourceException e) { - code = variant; - } - result.append(code); - if (tokens.hasMoreTokens()) { - result.append(','); - } - } - return result.toString(); + return ULocale.forLocale(this).getDisplayVariant(ULocale.forLocale(locale)); } /** @@ -583,11 +527,7 @@ * when there is no matching three letter ISO country code */ public String getISO3Country() throws MissingResourceException { - if (countryCode.length() == 0) { - return ""; //$NON-NLS-1$ - } - ResourceBundle bundle = getBundle("ISO3Countries", this); //$NON-NLS-1$ - return bundle.getString(countryCode); + return ULocale.forLocale(this).getISO3Country(); } /** @@ -600,11 +540,7 @@ * when there is no matching three letter ISO language code */ public String getISO3Language() throws MissingResourceException { - if (languageCode.length() == 0) { - return ""; //$NON-NLS-1$ - } - ResourceBundle bundle = getBundle("ISO3Languages", this); //$NON-NLS-1$ - return bundle.getString(languageCode); + return ULocale.forLocale(this).getISO3Language(); } /** @@ -614,18 +550,7 @@ * @return an array of String */ public static String[] getISOCountries() { - ListResourceBundle bundle = new Country(); - - // To initialize the table - Enumeration keys = bundle.getKeys(); - int size = bundle.table.size(); - String[] result = new String[size]; - int index = 0; - while (keys.hasMoreElements()) { - String element = keys.nextElement(); - result[index++] = element; - } - return result; + return ULocale.getISOCountries(); } /** @@ -635,14 +560,7 @@ * @return an array of String */ public static String[] getISOLanguages() { - ListResourceBundle bundle = new Language(); - Enumeration keys = bundle.getKeys(); // to initialize the table - String[] result = new String[bundle.table.size()]; - int index = 0; - while (keys.hasMoreElements()) { - result[index++] = keys.nextElement(); - } - return result; + return ULocale.getISOLanguages(); } /** @@ -723,15 +641,6 @@ return result.toString(); } - static ResourceBundle getBundle(final String clName, final Locale locale) { - return AccessController.doPrivileged(new PrivilegedAction() { - public ResourceBundle run() { - return ResourceBundle.getBundle("org.apache.harmony.luni.internal.locale." //$NON-NLS-1$ - + clName, locale); - } - }); - } - private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField("country", String.class), //$NON-NLS-1$ new ObjectStreamField("hashcode", Integer.TYPE), //$NON-NLS-1$