< prev index next >

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

Print this page




  27  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  28  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  29  *
  30  * The original version of this source code and documentation
  31  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  32  * subsidiary of IBM. These materials are provided under terms
  33  * of a License Agreement between Taligent and Sun. This technology
  34  * is protected by multiple US and International patents.
  35  *
  36  * This notice and attribution to Taligent may not be removed.
  37  * Taligent is a registered trademark of Taligent, Inc.
  38  *
  39  */
  40 
  41 package sun.util.locale.provider;
  42 
  43 import java.lang.ref.ReferenceQueue;
  44 import java.lang.ref.SoftReference;
  45 import java.text.MessageFormat;
  46 import java.util.Calendar;

  47 import java.util.LinkedHashSet;
  48 import java.util.Locale;
  49 import java.util.Map;
  50 import java.util.Objects;
  51 import java.util.ResourceBundle;
  52 import java.util.Set;

  53 import java.util.concurrent.ConcurrentHashMap;
  54 import java.util.concurrent.ConcurrentMap;
  55 import sun.security.action.GetPropertyAction;
  56 import sun.util.calendar.ZoneInfo;
  57 import sun.util.resources.LocaleData;
  58 import sun.util.resources.OpenListResourceBundle;
  59 import sun.util.resources.ParallelListResourceBundle;
  60 import sun.util.resources.TimeZoneNamesBundle;
  61 
  62 /**
  63  * Central accessor to locale-dependent resources for JRE/CLDR provider adapters.
  64  *
  65  * @author Masayoshi Okutsu
  66  * @author Naoto Sato
  67  */
  68 public class LocaleResources {
  69 
  70     private final Locale locale;
  71     private final LocaleData localeData;
  72     private final LocaleProviderAdapter.Type type;


 291         Set<String> zoneIDs = null;
 292 
 293         removeEmptyReferences();
 294         ResourceReference data = cache.get(ZONE_IDS_CACHEKEY);
 295         if (data == null || ((zoneIDs = (Set<String>) data.get()) == null)) {
 296             TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
 297             zoneIDs = rb.keySet();
 298             cache.put(ZONE_IDS_CACHEKEY,
 299                       new ResourceReference(ZONE_IDS_CACHEKEY, (Object) zoneIDs, referenceQueue));
 300         }
 301 
 302         return zoneIDs;
 303     }
 304 
 305     // zoneStrings are cached separately in TimeZoneNameUtility.
 306     String[][] getZoneStrings() {
 307         TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
 308         Set<String> keyset = getZoneIDs();
 309         // Use a LinkedHashSet to preseve the order
 310         Set<String[]> value = new LinkedHashSet<>();

 311         for (String key : keyset) {
 312             if (!key.startsWith(TZNB_EXCITY_PREFIX)) {
 313                 value.add(rb.getStringArray(key));

 314             }
 315         }
 316 
 317         // Add aliases data for CLDR
 318         if (type == LocaleProviderAdapter.Type.CLDR) {
 319             // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
 320             Map<String, String> aliases = ZoneInfo.getAliasTable();
 321             for (String alias : aliases.keySet()) {
 322                 if (!keyset.contains(alias)) {
 323                     String tzid = aliases.get(alias);






 324                     if (keyset.contains(tzid)) {
 325                         String[] val = rb.getStringArray(tzid);
 326                         val[0] = alias;
 327                         value.add(val);
 328                     }

 329                 }
 330             }



 331         }
 332         return value.toArray(new String[0][]);
 333     }
 334 
 335     String[] getCalendarNames(String key) {
 336         String[] names = null;
 337         String cacheKey = CALENDAR_NAMES + key;
 338 
 339         removeEmptyReferences();
 340         ResourceReference data = cache.get(cacheKey);
 341 
 342         if (data == null || ((names = (String[]) data.get()) == null)) {
 343             ResourceBundle rb = localeData.getDateFormatData(locale);
 344             if (rb.containsKey(key)) {
 345                 names = rb.getStringArray(key);
 346                 cache.put(cacheKey,
 347                           new ResourceReference(cacheKey, (Object) names, referenceQueue));
 348             }
 349         }
 350 




  27  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  28  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  29  *
  30  * The original version of this source code and documentation
  31  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  32  * subsidiary of IBM. These materials are provided under terms
  33  * of a License Agreement between Taligent and Sun. This technology
  34  * is protected by multiple US and International patents.
  35  *
  36  * This notice and attribution to Taligent may not be removed.
  37  * Taligent is a registered trademark of Taligent, Inc.
  38  *
  39  */
  40 
  41 package sun.util.locale.provider;
  42 
  43 import java.lang.ref.ReferenceQueue;
  44 import java.lang.ref.SoftReference;
  45 import java.text.MessageFormat;
  46 import java.util.Calendar;
  47 import java.util.HashSet;
  48 import java.util.LinkedHashSet;
  49 import java.util.Locale;
  50 import java.util.Map;
  51 import java.util.Objects;
  52 import java.util.ResourceBundle;
  53 import java.util.Set;
  54 import java.util.TimeZone;
  55 import java.util.concurrent.ConcurrentHashMap;
  56 import java.util.concurrent.ConcurrentMap;
  57 import sun.security.action.GetPropertyAction;
  58 import sun.util.calendar.ZoneInfo;
  59 import sun.util.resources.LocaleData;
  60 import sun.util.resources.OpenListResourceBundle;
  61 import sun.util.resources.ParallelListResourceBundle;
  62 import sun.util.resources.TimeZoneNamesBundle;
  63 
  64 /**
  65  * Central accessor to locale-dependent resources for JRE/CLDR provider adapters.
  66  *
  67  * @author Masayoshi Okutsu
  68  * @author Naoto Sato
  69  */
  70 public class LocaleResources {
  71 
  72     private final Locale locale;
  73     private final LocaleData localeData;
  74     private final LocaleProviderAdapter.Type type;


 293         Set<String> zoneIDs = null;
 294 
 295         removeEmptyReferences();
 296         ResourceReference data = cache.get(ZONE_IDS_CACHEKEY);
 297         if (data == null || ((zoneIDs = (Set<String>) data.get()) == null)) {
 298             TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
 299             zoneIDs = rb.keySet();
 300             cache.put(ZONE_IDS_CACHEKEY,
 301                       new ResourceReference(ZONE_IDS_CACHEKEY, (Object) zoneIDs, referenceQueue));
 302         }
 303 
 304         return zoneIDs;
 305     }
 306 
 307     // zoneStrings are cached separately in TimeZoneNameUtility.
 308     String[][] getZoneStrings() {
 309         TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
 310         Set<String> keyset = getZoneIDs();
 311         // Use a LinkedHashSet to preseve the order
 312         Set<String[]> value = new LinkedHashSet<>();
 313         Set<String> tzIds = new HashSet<>(Set.of(TimeZone.getAvailableIDs()));
 314         for (String key : keyset) {
 315             if (!key.startsWith(TZNB_EXCITY_PREFIX)) {
 316                 value.add(rb.getStringArray(key));
 317                 tzIds.remove(key);
 318             }
 319         }
 320 

 321         if (type == LocaleProviderAdapter.Type.CLDR) {
 322             // Add aliases data for CLDR
 323             Map<String, String> aliases = ZoneInfo.getAliasTable();
 324             // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
 325 
 326             // Add timezones which are not present in this keyset,
 327             // so that their fallback names will be generated at runtime.
 328             tzIds.stream().filter(i -> (!i.startsWith("Etc/GMT")
 329                     && !i.startsWith("GMT")
 330                     && !i.startsWith("SystemV")))
 331                     .forEach(tzid -> {
 332                         String[] val = new String[7];
 333                         if (keyset.contains(tzid)) {
 334                             val = rb.getStringArray(tzid);
 335                         } else {
 336                             String tz = aliases.get(tzid);
 337                             if (keyset.contains(tz)) {
 338                                 val = rb.getStringArray(tz);
 339                             }
 340                         }
 341                         val[0] = tzid;
 342                         value.add(val);
 343                     });
 344         }
 345         return value.toArray(new String[0][]);
 346     }
 347 
 348     String[] getCalendarNames(String key) {
 349         String[] names = null;
 350         String cacheKey = CALENDAR_NAMES + key;
 351 
 352         removeEmptyReferences();
 353         ResourceReference data = cache.get(cacheKey);
 354 
 355         if (data == null || ((names = (String[]) data.get()) == null)) {
 356             ResourceBundle rb = localeData.getDateFormatData(locale);
 357             if (rb.containsKey(key)) {
 358                 names = rb.getStringArray(key);
 359                 cache.put(cacheKey,
 360                           new ResourceReference(cacheKey, (Object) names, referenceQueue));
 361             }
 362         }
 363 


< prev index next >