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

Print this page

        

@@ -34,11 +34,13 @@
 import java.text.spi.DateFormatSymbolsProvider;
 import java.text.spi.DecimalFormatSymbolsProvider;
 import java.text.spi.NumberFormatProvider;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Locale;
+import java.util.ResourceBundle;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;

@@ -377,10 +379,17 @@
             }
         }
         return localeData;
     }
 
+    @Override
+    public List<Locale> getCandidateLocales(String baseName, Locale locale) {
+        return ResourceBundle.Control
+            .getNoFallbackControl(ResourceBundle.Control.FORMAT_DEFAULT)
+            .getCandidateLocales(baseName, locale);
+    }
+
     /**
      * Returns a list of the installed locales. Currently, this simply returns
      * the list of locales for which a sun.text.resources.FormatData bundle
      * exists. This bundle family happens to be the one with the broadest
      * locale coverage in the JRE.

@@ -415,16 +424,16 @@
 
         return tagset;
     }
 
     private static String createSupportedLocaleString(String category) {
-        // Directly call English tags, as we know it's in the base module.
-        String supportedLocaleString = EnLocaleDataMetaInfo.getSupportedLocaleString(category);
+        // Directly call Base tags, as we know it's in the base module.
+        String supportedLocaleString = BaseLocaleDataMetaInfo.getSupportedLocaleString(category);
 
         // Use ServiceLoader to dynamically acquire installed locales' tags.
         try {
-            String nonENTags = AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
+            String nonBaseTags = AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
                 @Override
                 public String run() {
                     String tags = null;
                     for (LocaleDataMetaInfo ldmi :
                          ServiceLoader.loadInstalled(LocaleDataMetaInfo.class)) {

@@ -441,12 +450,12 @@
                     }
                     return tags;
                 }
             });
 
-            if (nonENTags != null) {
-                supportedLocaleString += " " + nonENTags;
+            if (nonBaseTags != null) {
+                supportedLocaleString += " " + nonBaseTags;
             }
         }  catch (Exception e) {
             // catch any exception, and ignore them as if non-EN locales do not exist.
         }
 

@@ -495,6 +504,24 @@
                     locales[i] = Locale.forLanguageTag(currentToken);
             }
         }
         return locales;
     }
+
+    @Override
+    public boolean isSupportedProviderLocale(Locale locale,  Set<String> langtags) {
+        if (Locale.ROOT.equals(locale)) {
+            return true;
+        }
+
+        locale = locale.stripExtensions();
+        if (langtags.contains(locale.toLanguageTag())) {
+            return true;
+        }
+
+        String oldname = locale.toString().replace('_', '-');
+        return langtags.contains(oldname) ||
+                   "ja-JP-JP".equals(oldname) ||
+                   "th-TH-TH".equals(oldname) ||
+                   "no-NO-NY".equals(oldname);
+    }
 }