< prev index next >

src/java.base/share/classes/sun/util/locale/provider/JRELocaleProviderAdapter.java

Print this page
rev 54380 : 8221701: Archive constant BaseLocales
Reviewed-by: naoto


 474                     }
 475                 }
 476                 return tags.toString();
 477             });
 478 
 479             if (nonBaseTags != null) {
 480                 supportedLocaleString += " " + nonBaseTags;
 481             }
 482         } catch (PrivilegedActionException pae) {
 483             throw new InternalError(pae.getCause());
 484         }
 485 
 486         return supportedLocaleString;
 487     }
 488 
 489     /**
 490      * Lazy load available locales.
 491      */
 492     private static class AvailableJRELocales {
 493         private static final Locale[] localeList = createAvailableLocales();
 494         private AvailableJRELocales() {
 495         }
 496     }
 497 
 498     private static Locale[] createAvailableLocales() {
 499         /*
 500          * Gets the locale string list from LocaleDataMetaInfo classes and then
 501          * contructs the Locale array and a set of language tags based on the
 502          * locale string returned above.
 503          */
 504         String supportedLocaleString = createSupportedLocaleString("AvailableLocales");
 505 
 506         if (supportedLocaleString.isEmpty()) {
 507             throw new InternalError("No available locales for JRE");
 508         }
 509 
 510         StringTokenizer localeStringTokenizer = new StringTokenizer(supportedLocaleString);
 511 
 512         int length = localeStringTokenizer.countTokens();
 513         Locale[] locales = new Locale[length + 1];
 514         locales[0] = Locale.ROOT;
 515         for (int i = 1; i <= length; i++) {


 518                 case "ja-JP-JP":
 519                     locales[i] = JRELocaleConstants.JA_JP_JP;
 520                     break;
 521                 case "no-NO-NY":
 522                     locales[i] = JRELocaleConstants.NO_NO_NY;
 523                     break;
 524                 case "th-TH-TH":
 525                     locales[i] = JRELocaleConstants.TH_TH_TH;
 526                     break;
 527                 default:
 528                     locales[i] = Locale.forLanguageTag(currentToken);
 529             }
 530         }
 531         return locales;
 532     }
 533 
 534     @Override
 535     public boolean isSupportedProviderLocale(Locale locale,  Set<String> langtags) {
 536         if (Locale.ROOT.equals(locale)) {
 537             return true;
 538 }
 539 
 540         locale = locale.stripExtensions();
 541         if (langtags.contains(locale.toLanguageTag())) {
 542             return true;
 543         }
 544 
 545         String oldname = locale.toString().replace('_', '-');
 546         return langtags.contains(oldname) ||
 547                    "ja-JP-JP".equals(oldname) ||
 548                    "th-TH-TH".equals(oldname) ||
 549                    "no-NO-NY".equals(oldname);
 550     }
 551 }


 474                     }
 475                 }
 476                 return tags.toString();
 477             });
 478 
 479             if (nonBaseTags != null) {
 480                 supportedLocaleString += " " + nonBaseTags;
 481             }
 482         } catch (PrivilegedActionException pae) {
 483             throw new InternalError(pae.getCause());
 484         }
 485 
 486         return supportedLocaleString;
 487     }
 488 
 489     /**
 490      * Lazy load available locales.
 491      */
 492     private static class AvailableJRELocales {
 493         private static final Locale[] localeList = createAvailableLocales();
 494         private AvailableJRELocales() {}

 495     }
 496 
 497     private static Locale[] createAvailableLocales() {
 498         /*
 499          * Gets the locale string list from LocaleDataMetaInfo classes and then
 500          * contructs the Locale array and a set of language tags based on the
 501          * locale string returned above.
 502          */
 503         String supportedLocaleString = createSupportedLocaleString("AvailableLocales");
 504 
 505         if (supportedLocaleString.isEmpty()) {
 506             throw new InternalError("No available locales for JRE");
 507         }
 508 
 509         StringTokenizer localeStringTokenizer = new StringTokenizer(supportedLocaleString);
 510 
 511         int length = localeStringTokenizer.countTokens();
 512         Locale[] locales = new Locale[length + 1];
 513         locales[0] = Locale.ROOT;
 514         for (int i = 1; i <= length; i++) {


 517                 case "ja-JP-JP":
 518                     locales[i] = JRELocaleConstants.JA_JP_JP;
 519                     break;
 520                 case "no-NO-NY":
 521                     locales[i] = JRELocaleConstants.NO_NO_NY;
 522                     break;
 523                 case "th-TH-TH":
 524                     locales[i] = JRELocaleConstants.TH_TH_TH;
 525                     break;
 526                 default:
 527                     locales[i] = Locale.forLanguageTag(currentToken);
 528             }
 529         }
 530         return locales;
 531     }
 532 
 533     @Override
 534     public boolean isSupportedProviderLocale(Locale locale,  Set<String> langtags) {
 535         if (Locale.ROOT.equals(locale)) {
 536             return true;
 537         }
 538 
 539         locale = locale.stripExtensions();
 540         if (langtags.contains(locale.toLanguageTag())) {
 541             return true;
 542         }
 543 
 544         String oldname = locale.toString().replace('_', '-');
 545         return langtags.contains(oldname) ||
 546                    "ja-JP-JP".equals(oldname) ||
 547                    "th-TH-TH".equals(oldname) ||
 548                    "no-NO-NY".equals(oldname);
 549     }
 550 }
< prev index next >