Print this page
rev 5957 : imported patch 8000245.8000273.8000615
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/sun/util/locale/provider/TimeZoneNameProviderImpl.java
+++ new/src/share/classes/sun/util/locale/provider/TimeZoneNameProviderImpl.java
1 1 /*
2 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 package sun.util.locale.provider;
27 27
28 28 import java.util.Locale;
29 29 import java.util.MissingResourceException;
30 +import java.util.ResourceBundle;
30 31 import java.util.Set;
31 32 import java.util.TimeZone;
32 33 import java.util.spi.TimeZoneNameProvider;
33 -import sun.util.resources.OpenListResourceBundle;
34 34
35 35 /**
36 36 * Concrete implementation of the
37 37 * {@link java.util.spi.TimeZoneNameProvider TimeZoneNameProvider} class
38 38 * for the JRE LocaleProviderAdapter.
39 39 *
40 40 * @author Naoto Sato
41 41 * @author Masayoshi Okutsu
42 42 */
43 43 public class TimeZoneNameProviderImpl extends TimeZoneNameProvider {
44 44 private final LocaleProviderAdapter.Type type;
45 45 private final Set<String> langtags;
46 46
47 47 TimeZoneNameProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
48 48 this.type = type;
49 49 this.langtags = langtags;
50 50 }
51 51
52 52 /**
53 53 * Returns an array of all locales for which this locale service provider
54 54 * can provide localized objects or names.
55 55 *
56 56 * @return An array of all locales for which this locale service provider
57 57 * can provide localized objects or names.
58 58 */
59 59 @Override
60 60 public Locale[] getAvailableLocales() {
61 61 return LocaleProviderAdapter.toLocaleArray(langtags);
62 62 }
63 63
64 64 @Override
65 65 public boolean isSupportedLocale(Locale locale) {
66 66 return LocaleProviderAdapter.isSupportedLocale(locale, type, langtags);
67 67 }
68 68
69 69 /**
70 70 * Returns a name for the given time zone ID that's suitable for
71 71 * presentation to the user in the specified locale. The given time
72 72 * zone ID is "GMT" or one of the names defined using "Zone" entries
73 73 * in the "tz database", a public domain time zone database at
74 74 * <a href="ftp://elsie.nci.nih.gov/pub/">ftp://elsie.nci.nih.gov/pub/</a>.
75 75 * The data of this database is contained in a file whose name starts with
76 76 * "tzdata", and the specification of the data format is part of the zic.8
77 77 * man page, which is contained in a file whose name starts with "tzcode".
78 78 * <p>
79 79 * If <code>daylight</code> is true, the method should return a name
80 80 * appropriate for daylight saving time even if the specified time zone
81 81 * has not observed daylight saving time in the past.
82 82 *
83 83 * @param ID a time zone ID string
84 84 * @param daylight if true, return the daylight saving name.
85 85 * @param style either {@link java.util.TimeZone#LONG TimeZone.LONG} or
86 86 * {@link java.util.TimeZone#SHORT TimeZone.SHORT}
87 87 * @param locale the desired locale
88 88 * @return the human-readable name of the given time zone in the
89 89 * given locale, or null if it's not available.
90 90 * @exception IllegalArgumentException if <code>style</code> is invalid,
91 91 * or <code>locale</code> isn't one of the locales returned from
92 92 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
93 93 * getAvailableLocales()}.
94 94 * @exception NullPointerException if <code>ID</code> or <code>locale</code>
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
95 95 * is null
96 96 * @see java.util.TimeZone#getDisplayName(boolean, int, java.util.Locale)
97 97 */
98 98 @Override
99 99 public String getDisplayName(String id, boolean daylight, int style, Locale locale) {
100 100 if (id == null || locale == null) {
101 101 throw new NullPointerException();
102 102 }
103 103
104 104 LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
105 - OpenListResourceBundle rb = adapter.getLocaleResources(locale).getTimeZoneNames();
106 - LocaleServiceProviderPool pool =
107 - LocaleServiceProviderPool.getPool(TimeZoneNameProvider.class);
105 + ResourceBundle rb = adapter.getLocaleResources(locale).getTimeZoneNames();
108 106 try {
109 - if (!pool.hasProviders() ||
110 - (rb.getLocale().equals(locale) && rb.handleGetKeys().contains(id))) {
107 + if (rb.containsKey(id)) {
111 108 String[] names = rb.getStringArray(id);
112 109 int index = daylight ? 3 : 1;
113 110 if (style == TimeZone.SHORT) {
114 111 index++;
115 112 }
116 113 return names[index];
117 114 }
118 115 } catch (MissingResourceException mre) {
119 116 }
120 117
121 118 return null;
122 119 }
123 120 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX