34 * 6509039 6609737 6610748 6645271 6507067 6873931 6450945 6645268 6646611 |
34 * 6509039 6609737 6610748 6645271 6507067 6873931 6450945 6645268 6646611 |
35 * 6645405 6650730 6910489 6573250 6870908 6585666 6716626 6914413 6916787 |
35 * 6645405 6650730 6910489 6573250 6870908 6585666 6716626 6914413 6916787 |
36 * 6919624 6998391 7019267 7020960 7025837 7020583 7036905 7066203 7101495 |
36 * 6919624 6998391 7019267 7020960 7025837 7020583 7036905 7066203 7101495 |
37 * 7003124 7085757 7028073 7171028 7189611 8000983 7195759 8004489 8006509 |
37 * 7003124 7085757 7028073 7171028 7189611 8000983 7195759 8004489 8006509 |
38 * 7114053 7074882 7040556 8008577 8013836 8021121 6192407 6931564 8027695 |
38 * 7114053 7074882 7040556 8008577 8013836 8021121 6192407 6931564 8027695 |
39 * 8017142 8037343 8055222 8042126 8074791 8075173 8080774 8129361 |
39 * 8017142 8037343 8055222 8042126 8074791 8075173 8080774 8129361 8134916 |
40 * @summary Verify locale data |
40 * @summary Verify locale data |
41 * @run main LocaleDataTest |
41 * @run main LocaleDataTest |
42 * @run main LocaleDataTest -cldr |
42 * @run main LocaleDataTest -cldr |
43 * |
43 * |
44 */ |
44 */ |
147 import java.text.*; |
147 import java.text.*; |
148 import java.util.Locale; |
148 import java.util.Locale; |
149 import java.util.ResourceBundle; |
149 import java.util.ResourceBundle; |
150 import java.util.ResourceBundle.Control; |
150 import java.util.ResourceBundle.Control; |
151 import java.util.MissingResourceException; |
151 import java.util.MissingResourceException; |
|
152 import sun.util.resources.LocaleData; |
152 |
153 |
153 public class LocaleDataTest |
154 public class LocaleDataTest |
154 { |
155 { |
155 static final String TEXT_RESOURCES_PACKAGE ="sun.text.resources"; |
156 static final String TEXT_RESOURCES_PACKAGE ="sun.text.resources"; |
156 static final String UTIL_RESOURCES_PACKAGE ="sun.util.resources"; |
157 static final String UTIL_RESOURCES_PACKAGE ="sun.util.resources"; |
310 if (use_tag) { |
311 if (use_tag) { |
311 locale = Locale.forLanguageTag(localeName); |
312 locale = Locale.forLanguageTag(localeName); |
312 } else { |
313 } else { |
313 locale = new Locale(language, country, variant); |
314 locale = new Locale(language, country, variant); |
314 } |
315 } |
315 ResourceBundle bundle = ResourceBundle.getBundle(fullName, |
316 ResourceBundle bundle = LocaleData.getBundle(fullName, locale); |
316 locale, |
|
317 JRELocaleResourceBundleControl.INSTANCE); |
|
318 resource = bundle.getObject(resTag); |
317 resource = bundle.getObject(resTag); |
319 } |
318 } |
320 catch (MissingResourceException e) { |
319 catch (MissingResourceException e) { |
321 } |
320 } |
322 |
321 |
365 else { |
364 else { |
366 if (writeNewFile) |
365 if (writeNewFile) |
367 out.println(key + "=" + expectedValue); |
366 out.println(key + "=" + expectedValue); |
368 } |
367 } |
369 return true; |
368 return true; |
370 } |
|
371 |
|
372 private static class JRELocaleResourceBundleControl extends ResourceBundle.Control { |
|
373 static final JRELocaleResourceBundleControl INSTANCE = new JRELocaleResourceBundleControl(); |
|
374 |
|
375 private JRELocaleResourceBundleControl() { |
|
376 } |
|
377 |
|
378 @Override |
|
379 public Locale getFallbackLocale(String baseName, Locale locale) { |
|
380 if (baseName == null || locale == null) { |
|
381 throw new NullPointerException(); |
|
382 } |
|
383 return null; |
|
384 } |
|
385 |
|
386 /** |
|
387 * Changes baseName to its per-language/country package name and |
|
388 * calls the super class implementation. For example, |
|
389 * if the baseName is "sun.text.resources.FormatData" and locale is ja_JP, |
|
390 * the baseName is changed to "sun.text.resources.ja.JP.FormatData". If |
|
391 * baseName contains "cldr", such as "sun.text.resources.cldr.FormatData", |
|
392 * the name is changed to "sun.text.resources.cldr.ja.JP.FormatData". |
|
393 */ |
|
394 @Override |
|
395 public String toBundleName(String baseName, Locale locale) { |
|
396 String newBaseName = baseName; |
|
397 String lang = locale.getLanguage(); |
|
398 String ctry = locale.getCountry(); |
|
399 if (lang.length() > 0) { |
|
400 if (baseName.startsWith(UTIL_RESOURCES_PACKAGE + cldrSuffix) |
|
401 || baseName.startsWith(TEXT_RESOURCES_PACKAGE + cldrSuffix)) { |
|
402 // Assume the lengths are the same. |
|
403 if (UTIL_RESOURCES_PACKAGE.length() |
|
404 != TEXT_RESOURCES_PACKAGE.length()) { |
|
405 throw new InternalError("The resources package names have different lengths."); |
|
406 } |
|
407 int index = (TEXT_RESOURCES_PACKAGE + cldrSuffix).length(); |
|
408 ctry = (ctry.length() == 2) ? ("." + ctry) : ""; |
|
409 newBaseName = baseName.substring(0, index + 1) + lang + ctry |
|
410 + baseName.substring(index); |
|
411 } |
|
412 } |
|
413 return super.toBundleName(newBaseName, locale); |
|
414 } |
|
415 } |
369 } |
416 } |
370 } |
417 |
371 |
418 class EscapeReader extends FilterReader { |
372 class EscapeReader extends FilterReader { |
419 public EscapeReader(Reader in) { |
373 public EscapeReader(Reader in) { |