44 import java.security.PrivilegedAction; |
44 import java.security.PrivilegedAction; |
45 import java.util.Iterator; |
45 import java.util.Iterator; |
46 import java.util.List; |
46 import java.util.List; |
47 import java.util.Locale; |
47 import java.util.Locale; |
48 import java.util.ResourceBundle; |
48 import java.util.ResourceBundle; |
|
49 import sun.util.locale.provider.LocaleDataMetaInfo; |
49 import sun.util.locale.provider.LocaleProviderAdapter; |
50 import sun.util.locale.provider.LocaleProviderAdapter; |
50 import static sun.util.locale.provider.LocaleProviderAdapter.Type.JRE; |
51 import static sun.util.locale.provider.LocaleProviderAdapter.Type.JRE; |
51 import sun.util.locale.provider.LocaleDataMetaInfo; |
|
52 |
52 |
53 /** |
53 /** |
54 * Provides information about and access to resource bundles in the |
54 * Provides information about and access to resource bundles in the |
55 * sun.text.resources and sun.util.resources packages or in their corresponding |
55 * sun.text.resources and sun.util.resources packages or in their corresponding |
56 * packages for CLDR. |
56 * packages for CLDR. |
92 |
92 |
93 /** |
93 /** |
94 * Gets a time zone names resource bundle, using privileges |
94 * Gets a time zone names resource bundle, using privileges |
95 * to allow accessing a sun.* package. |
95 * to allow accessing a sun.* package. |
96 */ |
96 */ |
97 public OpenListResourceBundle getTimeZoneNames(Locale locale) { |
97 public TimeZoneNamesBundle getTimeZoneNames(Locale locale) { |
98 return (OpenListResourceBundle) getBundle(type.getUtilResourcesPackage() + ".TimeZoneNames", locale); |
98 return (TimeZoneNamesBundle) getBundle(type.getUtilResourcesPackage() + ".TimeZoneNames", locale); |
99 } |
99 } |
100 |
100 |
101 /** |
101 /** |
102 * Gets a collation data resource bundle, using privileges |
102 * Gets a collation data resource bundle, using privileges |
103 * to allow accessing a sun.* package. |
103 * to allow accessing a sun.* package. |
156 public List<Locale> getCandidateLocales(String baseName, Locale locale) { |
156 public List<Locale> getCandidateLocales(String baseName, Locale locale) { |
157 List<Locale> candidates = super.getCandidateLocales(baseName, locale); |
157 List<Locale> candidates = super.getCandidateLocales(baseName, locale); |
158 /* Get the locale string list from LocaleDataMetaInfo class. */ |
158 /* Get the locale string list from LocaleDataMetaInfo class. */ |
159 String localeString = LocaleDataMetaInfo.getSupportedLocaleString(baseName); |
159 String localeString = LocaleDataMetaInfo.getSupportedLocaleString(baseName); |
160 |
160 |
161 if (localeString == null || localeString.length() == 0) { |
161 if (localeString != null && localeString.length() != 0) { |
162 return candidates; |
162 for (Iterator<Locale> l = candidates.iterator(); l.hasNext();) { |
163 } |
163 Locale loc = l.next(); |
164 |
164 String lstr; |
165 for (Iterator<Locale> l = candidates.iterator(); l.hasNext(); ) { |
165 if (loc.getScript().length() > 0) { |
166 Locale loc = l.next(); |
166 lstr = loc.toLanguageTag().replace('-', '_'); |
167 String lstr; |
167 } else { |
168 if (loc.getScript().length() > 0) { |
168 lstr = loc.toString(); |
169 lstr = loc.toLanguageTag().replace('-', '_'); |
169 int idx = lstr.indexOf("_#"); |
170 } else { |
170 if (idx >= 0) { |
171 lstr = loc.toString(); |
171 lstr = lstr.substring(0, idx); |
172 int idx = lstr.indexOf("_#"); |
172 } |
173 if (idx >= 0) { |
173 } |
174 lstr = lstr.substring(0, idx); |
174 /* Every locale string in the locale string list returned from |
|
175 the above getSupportedLocaleString is enclosed |
|
176 within two white spaces so that we could check some locale |
|
177 such as "en". |
|
178 */ |
|
179 if (lstr.length() != 0 && localeString.indexOf(" " + lstr + " ") == -1) { |
|
180 l.remove(); |
175 } |
181 } |
176 } |
182 } |
177 /* Every locale string in the locale string list returned from |
183 } |
178 the above getSupportedLocaleString is enclosed |
184 // Force fallback to Locale.ENGLISH for CLDR time zone names support |
179 within two white spaces so that we could check some locale |
185 if (locale.getLanguage() != "en" |
180 such as "en". |
186 && baseName.contains(CLDR) && baseName.endsWith("TimeZoneNames")) { |
181 */ |
187 candidates.add(candidates.size() - 1, Locale.ENGLISH); |
182 if (lstr.length() != 0 && localeString.indexOf(" " + lstr + " ") == -1) { |
|
183 l.remove(); |
|
184 } |
|
185 } |
188 } |
186 return candidates; |
189 return candidates; |
187 } |
190 } |
188 |
191 |
189 /* |
192 /* |