src/share/classes/sun/util/locale/provider/TimeZoneNameUtility.java
Print this page
rev 5696 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o packaging changes. by Naoto Sato and Masayoshi Okutsu)
*** 1,7 ****
/*
! * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 21,84 ****
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! package sun.util;
import java.lang.ref.SoftReference;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
- import java.util.MissingResourceException;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.spi.TimeZoneNameProvider;
import sun.util.calendar.ZoneInfo;
- import sun.util.resources.LocaleData;
import sun.util.resources.OpenListResourceBundle;
/**
* Utility class that deals with the localized time zone names
*/
public final class TimeZoneNameUtility {
/**
* cache to hold time zone resource bundles. Keyed by Locale
*/
private static ConcurrentHashMap<Locale, SoftReference<OpenListResourceBundle>> cachedBundles =
! new ConcurrentHashMap<Locale, SoftReference<OpenListResourceBundle>>();
/**
* cache to hold time zone localized strings. Keyed by Locale
*/
private static ConcurrentHashMap<Locale, SoftReference<String[][]>> cachedZoneData =
! new ConcurrentHashMap<Locale, SoftReference<String[][]>>();
/**
* get time zone localized strings. Enumerate all keys.
*/
! public static final String[][] getZoneStrings(Locale locale) {
String[][] zones;
SoftReference<String[][]> data = cachedZoneData.get(locale);
if (data == null || ((zones = data.get()) == null)) {
zones = loadZoneStrings(locale);
! data = new SoftReference<String[][]>(zones);
cachedZoneData.put(locale, data);
}
return zones;
}
! private static final String[][] loadZoneStrings(Locale locale) {
! List<String[]> zones = new LinkedList<String[]>();
OpenListResourceBundle rb = getBundle(locale);
Enumeration<String> keys = rb.getKeys();
! String[] names = null;
while(keys.hasMoreElements()) {
String key = keys.nextElement();
names = retrieveDisplayNames(rb, key, locale);
--- 21,84 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! package sun.util.locale.provider;
import java.lang.ref.SoftReference;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.spi.TimeZoneNameProvider;
import sun.util.calendar.ZoneInfo;
import sun.util.resources.OpenListResourceBundle;
/**
* Utility class that deals with the localized time zone names
+ *
+ * @author Naoto Sato
*/
public final class TimeZoneNameUtility {
/**
* cache to hold time zone resource bundles. Keyed by Locale
*/
private static ConcurrentHashMap<Locale, SoftReference<OpenListResourceBundle>> cachedBundles =
! new ConcurrentHashMap<>();
/**
* cache to hold time zone localized strings. Keyed by Locale
*/
private static ConcurrentHashMap<Locale, SoftReference<String[][]>> cachedZoneData =
! new ConcurrentHashMap<>();
/**
* get time zone localized strings. Enumerate all keys.
*/
! public static String[][] getZoneStrings(Locale locale) {
String[][] zones;
SoftReference<String[][]> data = cachedZoneData.get(locale);
if (data == null || ((zones = data.get()) == null)) {
zones = loadZoneStrings(locale);
! data = new SoftReference<>(zones);
cachedZoneData.put(locale, data);
}
return zones;
}
! private static String[][] loadZoneStrings(Locale locale) {
! List<String[]> zones = new LinkedList<>();
OpenListResourceBundle rb = getBundle(locale);
Enumeration<String> keys = rb.getKeys();
! String[] names;
while(keys.hasMoreElements()) {
String key = keys.nextElement();
names = retrieveDisplayNames(rb, key, locale);
*** 92,138 ****
}
/**
* Retrieve display names for a time zone ID.
*/
! public static final String[] retrieveDisplayNames(String id, Locale locale) {
OpenListResourceBundle rb = getBundle(locale);
return retrieveDisplayNames(rb, id, locale);
}
! private static final String[] retrieveDisplayNames(OpenListResourceBundle rb,
String id, Locale locale) {
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(TimeZoneNameProvider.class);
! String[] names = null;
!
! // Check whether a provider can provide an implementation that's closer
! // to the requested locale than what the Java runtime itself can provide.
! if (pool.hasProviders()) {
! names = pool.getLocalizedObject(
! TimeZoneNameGetter.INSTANCE,
! locale, rb, id);
}
! if (names == null) {
! try {
! names = rb.getStringArray(id);
! } catch (MissingResourceException mre) {
! // fall through
! }
! }
!
! return names;
! }
!
! private static final OpenListResourceBundle getBundle(Locale locale) {
OpenListResourceBundle rb;
SoftReference<OpenListResourceBundle> data = cachedBundles.get(locale);
if (data == null || ((rb = data.get()) == null)) {
! rb = LocaleData.getTimeZoneNames(locale);
! data = new SoftReference<OpenListResourceBundle>(rb);
cachedBundles.put(locale, data);
}
return rb;
}
--- 92,124 ----
}
/**
* Retrieve display names for a time zone ID.
*/
! public static String[] retrieveDisplayNames(String id, Locale locale) {
OpenListResourceBundle rb = getBundle(locale);
return retrieveDisplayNames(rb, id, locale);
}
! private static String[] retrieveDisplayNames(OpenListResourceBundle rb,
String id, Locale locale) {
+ if (id == null || locale == null) {
+ throw new NullPointerException();
+ }
+
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(TimeZoneNameProvider.class);
! return pool.getLocalizedObject(TimeZoneNameGetter.INSTANCE, locale, id);
}
! private static OpenListResourceBundle getBundle(Locale locale) {
OpenListResourceBundle rb;
SoftReference<OpenListResourceBundle> data = cachedBundles.get(locale);
if (data == null || ((rb = data.get()) == null)) {
! rb = LocaleProviderAdapter.forJRE().getLocaleData().getTimeZoneNames(locale);
! data = new SoftReference<>(rb);
cachedBundles.put(locale, data);
}
return rb;
}
*** 145,165 ****
implements LocaleServiceProviderPool.LocalizedObjectGetter<TimeZoneNameProvider,
String[]>{
private static final TimeZoneNameGetter INSTANCE =
new TimeZoneNameGetter();
public String[] getObject(TimeZoneNameProvider timeZoneNameProvider,
Locale locale,
String requestID,
Object... params) {
assert params.length == 0;
- String[] names = null;
String queryID = requestID;
! if (queryID.equals("GMT")) {
! names = buildZoneStrings(timeZoneNameProvider, locale, queryID);
! } else {
Map<String, String> aliases = ZoneInfo.getAliasTable();
if (aliases != null) {
// Check whether this id is an alias, if so,
// look for the standard id.
--- 131,152 ----
implements LocaleServiceProviderPool.LocalizedObjectGetter<TimeZoneNameProvider,
String[]>{
private static final TimeZoneNameGetter INSTANCE =
new TimeZoneNameGetter();
+ @Override
public String[] getObject(TimeZoneNameProvider timeZoneNameProvider,
Locale locale,
String requestID,
Object... params) {
assert params.length == 0;
String queryID = requestID;
! // First, try to get names with the request ID
! String[] names = buildZoneStrings(timeZoneNameProvider, locale, requestID);
!
! if (names == null) {
Map<String, String> aliases = ZoneInfo.getAliasTable();
if (aliases != null) {
// Check whether this id is an alias, if so,
// look for the standard id.
*** 230,235 ****
--- 217,226 ----
}
return names;
}
}
+
+ // No instantiation
+ private TimeZoneNameUtility() {
+ }
}