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

Print this page
rev 7998 : [mq]: 8024332


 344 
 345     public Set<String> getLanguageTagSet(String category) {
 346         Set<String> tagset = langtagSets.get(category);
 347         if (tagset == null) {
 348             tagset = createLanguageTagSet(category);
 349             Set<String> ts = langtagSets.putIfAbsent(category, tagset);
 350             if (ts != null) {
 351                 tagset = ts;
 352             }
 353         }
 354         return tagset;
 355     }
 356 
 357     protected Set<String> createLanguageTagSet(String category) {
 358         String supportedLocaleString = LocaleDataMetaInfo.getSupportedLocaleString(category);
 359         Set<String> tagset = new HashSet<>();
 360         StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
 361         while (tokens.hasMoreTokens()) {
 362             String token = tokens.nextToken();
 363             if (token.equals("|")) {
 364                 if (isNonUSLangSupported()) {
 365                     continue;
 366                 }
 367                 break;
 368             }
 369             tagset.add(token);
 370         }
 371 
 372         return tagset;
 373     }
 374 
 375     /**
 376      * Lazy load available locales.
 377      */
 378     private static class AvailableJRELocales {
 379         private static final Locale[] localeList = createAvailableLocales();
 380         private AvailableJRELocales() {
 381         }
 382     }
 383 
 384     private static Locale[] createAvailableLocales() {
 385         /*
 386          * Gets the locale string list from LocaleDataMetaInfo class and then
 387          * contructs the Locale array and a set of language tags based on the
 388          * locale string returned above.
 389          */
 390         String supportedLocaleString = LocaleDataMetaInfo.getSupportedLocaleString("AvailableLocales");
 391 
 392         if (supportedLocaleString.length() == 0) {
 393             throw new InternalError("No available locales for JRE");
 394         }
 395 
 396         /*
 397          * Look for "|" and construct a new locale string list.
 398          */
 399         int barIndex = supportedLocaleString.indexOf('|');
 400         StringTokenizer localeStringTokenizer;
 401         if (isNonUSLangSupported()) {
 402             localeStringTokenizer = new StringTokenizer(supportedLocaleString.substring(0, barIndex)
 403                     + supportedLocaleString.substring(barIndex + 1));
 404         } else {
 405             localeStringTokenizer = new StringTokenizer(supportedLocaleString.substring(0, barIndex));
 406         }
 407 
 408         int length = localeStringTokenizer.countTokens();
 409         Locale[] locales = new Locale[length + 1];
 410         locales[0] = Locale.ROOT;
 411         for (int i = 1; i <= length; i++) {
 412             String currentToken = localeStringTokenizer.nextToken();
 413             switch (currentToken) {
 414                 case "ja-JP-JP":
 415                     locales[i] = JRELocaleConstants.JA_JP_JP;
 416                     break;
 417                 case "no-NO-NY":
 418                     locales[i] = JRELocaleConstants.NO_NO_NY;
 419                     break;
 420                 case "th-TH-TH":
 421                     locales[i] = JRELocaleConstants.TH_TH_TH;
 422                     break;
 423                 default:
 424                     locales[i] = Locale.forLanguageTag(currentToken);
 425             }
 426         }
 427         return locales;
 428     }
 429 
 430     private static volatile Boolean isNonUSSupported = null;
 431 
 432     /*
 433      * Returns true if the non US resources jar file exists in jre
 434      * extension directory. @returns true if the jar file is there. Otherwise,
 435      * returns false.
 436      */
 437     private static boolean isNonUSLangSupported() {
 438         if (isNonUSSupported == null) {
 439             synchronized (JRELocaleProviderAdapter.class) {
 440                 if (isNonUSSupported == null) {
 441                     final String sep = File.separator;
 442                     String localeDataJar =
 443                             java.security.AccessController.doPrivileged(
 444                             new sun.security.action.GetPropertyAction("java.home"))
 445                             + sep + "lib" + sep + "ext" + sep + LOCALE_DATA_JAR_NAME;
 446 
 447                     /*
 448                      * Peek at the installed extension directory to see if
 449                      * localedata.jar is installed or not.
 450                      */
 451                     final File f = new File(localeDataJar);
 452                     isNonUSSupported =
 453                         AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
 454                             @Override
 455                             public Boolean run() {
 456                                 return f.exists();
 457                             }
 458                         });
 459                }
 460             }
 461         }
 462         return isNonUSSupported;
 463     }
 464 }


 344 
 345     public Set<String> getLanguageTagSet(String category) {
 346         Set<String> tagset = langtagSets.get(category);
 347         if (tagset == null) {
 348             tagset = createLanguageTagSet(category);
 349             Set<String> ts = langtagSets.putIfAbsent(category, tagset);
 350             if (ts != null) {
 351                 tagset = ts;
 352             }
 353         }
 354         return tagset;
 355     }
 356 
 357     protected Set<String> createLanguageTagSet(String category) {
 358         String supportedLocaleString = LocaleDataMetaInfo.getSupportedLocaleString(category);
 359         Set<String> tagset = new HashSet<>();
 360         StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
 361         while (tokens.hasMoreTokens()) {
 362             String token = tokens.nextToken();
 363             if (token.equals("|")) {
 364                 if (isNonENLangSupported()) {
 365                     continue;
 366                 }
 367                 break;
 368             }
 369             tagset.add(token);
 370         }
 371 
 372         return tagset;
 373     }
 374 
 375     /**
 376      * Lazy load available locales.
 377      */
 378     private static class AvailableJRELocales {
 379         private static final Locale[] localeList = createAvailableLocales();
 380         private AvailableJRELocales() {
 381         }
 382     }
 383 
 384     private static Locale[] createAvailableLocales() {
 385         /*
 386          * Gets the locale string list from LocaleDataMetaInfo class and then
 387          * contructs the Locale array and a set of language tags based on the
 388          * locale string returned above.
 389          */
 390         String supportedLocaleString = LocaleDataMetaInfo.getSupportedLocaleString("AvailableLocales");
 391 
 392         if (supportedLocaleString.length() == 0) {
 393             throw new InternalError("No available locales for JRE");
 394         }
 395 
 396         /*
 397          * Look for "|" and construct a new locale string list.
 398          */
 399         int barIndex = supportedLocaleString.indexOf('|');
 400         StringTokenizer localeStringTokenizer;
 401         if (isNonENLangSupported()) {
 402             localeStringTokenizer = new StringTokenizer(supportedLocaleString.substring(0, barIndex)
 403                     + supportedLocaleString.substring(barIndex + 1));
 404         } else {
 405             localeStringTokenizer = new StringTokenizer(supportedLocaleString.substring(0, barIndex));
 406         }
 407 
 408         int length = localeStringTokenizer.countTokens();
 409         Locale[] locales = new Locale[length + 1];
 410         locales[0] = Locale.ROOT;
 411         for (int i = 1; i <= length; i++) {
 412             String currentToken = localeStringTokenizer.nextToken();
 413             switch (currentToken) {
 414                 case "ja-JP-JP":
 415                     locales[i] = JRELocaleConstants.JA_JP_JP;
 416                     break;
 417                 case "no-NO-NY":
 418                     locales[i] = JRELocaleConstants.NO_NO_NY;
 419                     break;
 420                 case "th-TH-TH":
 421                     locales[i] = JRELocaleConstants.TH_TH_TH;
 422                     break;
 423                 default:
 424                     locales[i] = Locale.forLanguageTag(currentToken);
 425             }
 426         }
 427         return locales;
 428     }
 429 
 430     private static volatile Boolean isNonENSupported = null;
 431 
 432     /*
 433      * Returns true if the non EN resources jar file exists in jre
 434      * extension directory. @returns true if the jar file is there. Otherwise,
 435      * returns false.
 436      */
 437     private static boolean isNonENLangSupported() {
 438         if (isNonENSupported == null) {
 439             synchronized (JRELocaleProviderAdapter.class) {
 440                 if (isNonENSupported == null) {
 441                     final String sep = File.separator;
 442                     String localeDataJar =
 443                             java.security.AccessController.doPrivileged(
 444                             new sun.security.action.GetPropertyAction("java.home"))
 445                             + sep + "lib" + sep + "ext" + sep + LOCALE_DATA_JAR_NAME;
 446 
 447                     /*
 448                      * Peek at the installed extension directory to see if
 449                      * localedata.jar is installed or not.
 450                      */
 451                     final File f = new File(localeDataJar);
 452                     isNonENSupported =
 453                         AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
 454                             @Override
 455                             public Boolean run() {
 456                                 return f.exists();
 457                             }
 458                         });
 459                }
 460             }
 461         }
 462         return isNonENSupported;
 463     }
 464 }