< prev index next >

src/java.base/share/classes/sun/util/resources/LocaleData.java

Print this page
rev 49854 : 8181157: CLDR Timezone name fallback implementation
Reviewed-by: sherman
   1 /*
   2  * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 258             String key = baseName + '-' + locale.toLanguageTag();
 259             List<Locale> candidates = CANDIDATES_MAP.get(key);
 260             if (candidates == null) {
 261                 LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
 262                 LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
 263                 candidates = adapter instanceof ResourceBundleBasedAdapter ?
 264                     ((ResourceBundleBasedAdapter)adapter).getCandidateLocales(baseName, locale) :
 265                     defaultControl.getCandidateLocales(baseName, locale);
 266 
 267                 // Weed out Locales which are known to have no resource bundles
 268                 int lastDot = baseName.lastIndexOf('.');
 269                 String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
 270                 Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
 271                 if (!langtags.isEmpty()) {
 272                     for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
 273                         if (!adapter.isSupportedProviderLocale(itr.next(), langtags)) {
 274                             itr.remove();
 275                         }
 276                     }
 277                 }
 278                 // Force fallback to Locale.ENGLISH for CLDR time zone names support
 279                 if (locale.getLanguage() != "en"
 280                         && type == CLDR && category.equals("TimeZoneNames")) {
 281                     candidates.add(candidates.size() - 1, Locale.ENGLISH);
 282                 }
 283                 CANDIDATES_MAP.putIfAbsent(key, candidates);
 284             }
 285             return candidates;
 286         }
 287 
 288         boolean inJavaBaseModule(String baseName, Locale locale) {
 289             return JAVA_BASE_LOCALES.contains(locale);
 290         }
 291 
 292         @Override
 293         public String toBundleName(String baseName, Locale locale) {
 294             String newBaseName = baseName;
 295             if (!inJavaBaseModule(baseName, locale)) {
 296                 if (baseName.startsWith(JRE.getUtilResourcesPackage())
 297                         || baseName.startsWith(JRE.getTextResourcesPackage())) {
 298                     // Assume the lengths are the same.
 299                     assert JRE.getUtilResourcesPackage().length()
 300                         == JRE.getTextResourcesPackage().length();
 301                     int index = JRE.getUtilResourcesPackage().length();
 302                     if (baseName.indexOf(DOTCLDR, index) > 0) {


   1 /*
   2  * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 258             String key = baseName + '-' + locale.toLanguageTag();
 259             List<Locale> candidates = CANDIDATES_MAP.get(key);
 260             if (candidates == null) {
 261                 LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
 262                 LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
 263                 candidates = adapter instanceof ResourceBundleBasedAdapter ?
 264                     ((ResourceBundleBasedAdapter)adapter).getCandidateLocales(baseName, locale) :
 265                     defaultControl.getCandidateLocales(baseName, locale);
 266 
 267                 // Weed out Locales which are known to have no resource bundles
 268                 int lastDot = baseName.lastIndexOf('.');
 269                 String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
 270                 Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
 271                 if (!langtags.isEmpty()) {
 272                     for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
 273                         if (!adapter.isSupportedProviderLocale(itr.next(), langtags)) {
 274                             itr.remove();
 275                         }
 276                     }
 277                 }





 278                 CANDIDATES_MAP.putIfAbsent(key, candidates);
 279             }
 280             return candidates;
 281         }
 282 
 283         boolean inJavaBaseModule(String baseName, Locale locale) {
 284             return JAVA_BASE_LOCALES.contains(locale);
 285         }
 286 
 287         @Override
 288         public String toBundleName(String baseName, Locale locale) {
 289             String newBaseName = baseName;
 290             if (!inJavaBaseModule(baseName, locale)) {
 291                 if (baseName.startsWith(JRE.getUtilResourcesPackage())
 292                         || baseName.startsWith(JRE.getTextResourcesPackage())) {
 293                     // Assume the lengths are the same.
 294                     assert JRE.getUtilResourcesPackage().length()
 295                         == JRE.getTextResourcesPackage().length();
 296                     int index = JRE.getUtilResourcesPackage().length();
 297                     if (baseName.indexOf(DOTCLDR, index) > 0) {


< prev index next >