author | rgoel |
Mon, 30 Apr 2018 11:59:42 +0530 | |
changeset 49918 | 8b9c78f0a712 |
parent 49904 | cadca99d52e7 |
child 50974 | 24bf1bd23725 |
permissions | -rw-r--r-- |
13583 | 1 |
/* |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
13583 | 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 |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.util.cldr; |
|
27 |
||
28 |
import java.security.AccessController; |
|
47345
0a1fc9f3779c
8189264: (sl) ServiceLoader does not wrap Errors thrown by provider classes when running with a security manager
alanb
parents:
47216
diff
changeset
|
29 |
import java.security.AccessControlException; |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
30 |
import java.security.PrivilegedAction; |
47442
560ee83bfce5
8189272: CLDR and JRE LocaleProviderAdapters silently swallow exceptions
naoto
parents:
47345
diff
changeset
|
31 |
import java.security.PrivilegedActionException; |
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
32 |
import java.security.PrivilegedExceptionAction; |
13583 | 33 |
import java.text.spi.BreakIteratorProvider; |
34 |
import java.text.spi.CollatorProvider; |
|
31263 | 35 |
import java.util.Arrays; |
25996
4aa9eb909760
8055088: Optimization for locale resources loading isn't working
okutsu
parents:
25859
diff
changeset
|
36 |
import java.util.Collections; |
13583 | 37 |
import java.util.HashSet; |
31263 | 38 |
import java.util.List; |
13583 | 39 |
import java.util.Locale; |
31263 | 40 |
import java.util.Map; |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
41 |
import java.util.Optional; |
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
42 |
import java.util.ServiceLoader; |
47345
0a1fc9f3779c
8189264: (sl) ServiceLoader does not wrap Errors thrown by provider classes when running with a security manager
alanb
parents:
47216
diff
changeset
|
43 |
import java.util.ServiceConfigurationError; |
13583 | 44 |
import java.util.Set; |
45 |
import java.util.StringTokenizer; |
|
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
46 |
import java.util.concurrent.ConcurrentHashMap; |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
47 |
import java.util.spi.CalendarDataProvider; |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
48 |
import java.util.spi.TimeZoneNameProvider; |
13583 | 49 |
import sun.util.locale.provider.JRELocaleProviderAdapter; |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
50 |
import sun.util.locale.provider.LocaleDataMetaInfo; |
13583 | 51 |
import sun.util.locale.provider.LocaleProviderAdapter; |
52 |
||
53 |
/** |
|
54 |
* LocaleProviderAdapter implementation for the CLDR locale data. |
|
55 |
* |
|
56 |
* @author Masayoshi Okutsu |
|
57 |
* @author Naoto Sato |
|
58 |
*/ |
|
59 |
public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter { |
|
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
60 |
|
31263 | 61 |
private static final CLDRBaseLocaleDataMetaInfo baseMetaInfo = new CLDRBaseLocaleDataMetaInfo(); |
62 |
// Assumption: CLDR has only one non-Base module. |
|
63 |
private final LocaleDataMetaInfo nonBaseMetaInfo; |
|
64 |
||
65 |
// parent locales map |
|
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
66 |
private static volatile Map<Locale, Locale> parentLocalesMap; |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
67 |
// language aliases map |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
68 |
private static volatile Map<String,String> langAliasesMap; |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
69 |
// cache to hold locale to locale mapping for language aliases. |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
70 |
private static final Map<Locale, Locale> langAliasesCache; |
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
71 |
static { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
72 |
parentLocalesMap = new ConcurrentHashMap<>(); |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
73 |
langAliasesMap = new ConcurrentHashMap<>(); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
74 |
langAliasesCache = new ConcurrentHashMap<>(); |
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
75 |
// Assuming these locales do NOT have irregular parent locales. |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
76 |
parentLocalesMap.put(Locale.ROOT, Locale.ROOT); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
77 |
parentLocalesMap.put(Locale.ENGLISH, Locale.ENGLISH); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
78 |
parentLocalesMap.put(Locale.US, Locale.US); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
79 |
} |
13583 | 80 |
|
81 |
public CLDRLocaleProviderAdapter() { |
|
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
82 |
LocaleDataMetaInfo nbmi = null; |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
83 |
|
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
84 |
try { |
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
85 |
nbmi = AccessController.doPrivileged(new PrivilegedExceptionAction<LocaleDataMetaInfo>() { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
86 |
@Override |
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
87 |
public LocaleDataMetaInfo run() { |
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
88 |
for (LocaleDataMetaInfo ldmi : ServiceLoader.loadInstalled(LocaleDataMetaInfo.class)) { |
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
89 |
if (ldmi.getType() == LocaleProviderAdapter.Type.CLDR) { |
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
90 |
return ldmi; |
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
91 |
} |
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
92 |
} |
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
93 |
return null; |
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
94 |
} |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
95 |
}); |
47442
560ee83bfce5
8189272: CLDR and JRE LocaleProviderAdapters silently swallow exceptions
naoto
parents:
47345
diff
changeset
|
96 |
} catch (PrivilegedActionException pae) { |
560ee83bfce5
8189272: CLDR and JRE LocaleProviderAdapters silently swallow exceptions
naoto
parents:
47345
diff
changeset
|
97 |
throw new InternalError(pae.getCause()); |
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
98 |
} |
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
99 |
|
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
100 |
nonBaseMetaInfo = nbmi; |
13583 | 101 |
} |
102 |
||
103 |
/** |
|
104 |
* Returns the type of this LocaleProviderAdapter |
|
105 |
* @return the type of this |
|
106 |
*/ |
|
107 |
@Override |
|
108 |
public LocaleProviderAdapter.Type getAdapterType() { |
|
109 |
return LocaleProviderAdapter.Type.CLDR; |
|
110 |
} |
|
111 |
||
112 |
@Override |
|
113 |
public BreakIteratorProvider getBreakIteratorProvider() { |
|
114 |
return null; |
|
115 |
} |
|
116 |
||
117 |
@Override |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
118 |
public CalendarDataProvider getCalendarDataProvider() { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
119 |
if (calendarDataProvider == null) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
120 |
CalendarDataProvider provider = AccessController.doPrivileged( |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
121 |
(PrivilegedAction<CalendarDataProvider>) () -> |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
122 |
new CLDRCalendarDataProviderImpl( |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
123 |
getAdapterType(), |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
124 |
getLanguageTagSet("CalendarData"))); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
125 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
126 |
synchronized (this) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
127 |
if (calendarDataProvider == null) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
128 |
calendarDataProvider = provider; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
129 |
} |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
130 |
} |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
131 |
} |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
132 |
return calendarDataProvider; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
133 |
} |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
134 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
135 |
@Override |
13583 | 136 |
public CollatorProvider getCollatorProvider() { |
137 |
return null; |
|
138 |
} |
|
139 |
||
140 |
@Override |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
141 |
public TimeZoneNameProvider getTimeZoneNameProvider() { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
142 |
if (timeZoneNameProvider == null) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
143 |
TimeZoneNameProvider provider = AccessController.doPrivileged( |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
144 |
(PrivilegedAction<TimeZoneNameProvider>) () -> |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
145 |
new CLDRTimeZoneNameProviderImpl( |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
146 |
getAdapterType(), |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
147 |
getLanguageTagSet("TimeZoneNames"))); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
148 |
|
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
149 |
synchronized (this) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
150 |
if (timeZoneNameProvider == null) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
151 |
timeZoneNameProvider = provider; |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
152 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
153 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
154 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
155 |
return timeZoneNameProvider; |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
156 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
157 |
|
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
158 |
@Override |
13583 | 159 |
public Locale[] getAvailableLocales() { |
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
160 |
Set<String> all = createLanguageTagSet("AvailableLocales"); |
13583 | 161 |
Locale[] locs = new Locale[all.size()]; |
162 |
int index = 0; |
|
163 |
for (String tag : all) { |
|
164 |
locs[index++] = Locale.forLanguageTag(tag); |
|
165 |
} |
|
166 |
return locs; |
|
167 |
} |
|
168 |
||
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
169 |
private Locale applyAliases(Locale loc) { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
170 |
if (langAliasesMap.isEmpty()) { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
171 |
langAliasesMap = baseMetaInfo.getLanguageAliasMap(); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
172 |
} |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
173 |
Locale locale = langAliasesCache.get(loc); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
174 |
if (locale == null) { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
175 |
String locTag = loc.toLanguageTag(); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
176 |
Locale aliasLocale = langAliasesMap.containsKey(locTag) |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
177 |
? Locale.forLanguageTag(langAliasesMap.get(locTag)) : loc; |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
178 |
langAliasesCache.putIfAbsent(loc, aliasLocale); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
179 |
return aliasLocale; |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
180 |
} else { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
181 |
return locale; |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
182 |
} |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
183 |
} |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
184 |
|
13583 | 185 |
@Override |
186 |
protected Set<String> createLanguageTagSet(String category) { |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
187 |
// Assume all categories support the same set as AvailableLocales |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
188 |
// in CLDR adapter. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
189 |
category = "AvailableLocales"; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
190 |
|
31263 | 191 |
// Directly call Base tags, as we know it's in the base module. |
192 |
String supportedLocaleString = baseMetaInfo.availableLanguageTags(category); |
|
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
193 |
String nonBaseTags = null; |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
194 |
|
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
195 |
if (nonBaseMetaInfo != null) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
196 |
nonBaseTags = nonBaseMetaInfo.availableLanguageTags(category); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
197 |
} |
31263 | 198 |
if (nonBaseTags != null) { |
199 |
if (supportedLocaleString != null) { |
|
200 |
supportedLocaleString += " " + nonBaseTags; |
|
201 |
} else { |
|
202 |
supportedLocaleString = nonBaseTags; |
|
203 |
} |
|
204 |
} |
|
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
25996
diff
changeset
|
205 |
if (supportedLocaleString == null) { |
25996
4aa9eb909760
8055088: Optimization for locale resources loading isn't working
okutsu
parents:
25859
diff
changeset
|
206 |
return Collections.emptySet(); |
4aa9eb909760
8055088: Optimization for locale resources loading isn't working
okutsu
parents:
25859
diff
changeset
|
207 |
} |
13583 | 208 |
Set<String> tagset = new HashSet<>(); |
209 |
StringTokenizer tokens = new StringTokenizer(supportedLocaleString); |
|
210 |
while (tokens.hasMoreTokens()) { |
|
211 |
tagset.add(tokens.nextToken()); |
|
212 |
} |
|
213 |
return tagset; |
|
214 |
} |
|
31263 | 215 |
|
216 |
// Implementation of ResourceBundleBasedAdapter |
|
217 |
@Override |
|
218 |
public List<Locale> getCandidateLocales(String baseName, Locale locale) { |
|
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
219 |
List<Locale> candidates = super.getCandidateLocales(baseName, applyAliases(locale)); |
31263 | 220 |
return applyParentLocales(baseName, candidates); |
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
221 |
} |
31263 | 222 |
|
223 |
private List<Locale> applyParentLocales(String baseName, List<Locale> candidates) { |
|
224 |
// check irregular parents |
|
225 |
for (int i = 0; i < candidates.size(); i++) { |
|
226 |
Locale l = candidates.get(i); |
|
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
227 |
if (!l.equals(Locale.ROOT)) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
228 |
Locale p = getParentLocale(l); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
229 |
if (p != null && |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
230 |
!candidates.get(i+1).equals(p)) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
231 |
List<Locale> applied = candidates.subList(0, i+1); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
232 |
applied.addAll(applyParentLocales(baseName, super.getCandidateLocales(baseName, p))); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
233 |
return applied; |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
234 |
} |
31263 | 235 |
} |
236 |
} |
|
237 |
||
238 |
return candidates; |
|
239 |
} |
|
240 |
||
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
241 |
private static Locale getParentLocale(Locale locale) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
242 |
Locale parent = parentLocalesMap.get(locale); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
243 |
|
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
244 |
if (parent == null) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
245 |
String tag = locale.toLanguageTag(); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
246 |
for (Map.Entry<Locale, String[]> entry : baseMetaInfo.parentLocales().entrySet()) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
247 |
if (Arrays.binarySearch(entry.getValue(), tag) >= 0) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
248 |
parent = entry.getKey(); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
249 |
break; |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
250 |
} |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
251 |
} |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
252 |
if (parent == null) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
253 |
parent = locale; // non existent marker |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
254 |
} |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
255 |
parentLocalesMap.putIfAbsent(locale, parent); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
256 |
} |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
257 |
|
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
258 |
if (locale.equals(parent)) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
259 |
// means no irregular parent. |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
260 |
parent = null; |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
261 |
} |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
262 |
|
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
263 |
return parent; |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
264 |
} |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
265 |
|
43295
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
266 |
/** |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
267 |
* This method returns equivalent CLDR supported locale for zh-HK, |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
268 |
* no, no-NO locales so that COMPAT locales do not precede |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
269 |
* those locales during ResourceBundle search path. |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
270 |
*/ |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
271 |
private static Locale getEquivalentLoc(Locale locale) { |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
272 |
switch (locale.toString()) { |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
273 |
case "zh_HK": |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
274 |
return Locale.forLanguageTag("zh-Hant-HK"); |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
275 |
case "no": |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
276 |
case "no_NO": |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
277 |
return Locale.forLanguageTag("nb"); |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
278 |
} |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
279 |
return locale; |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
280 |
} |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
281 |
|
31263 | 282 |
@Override |
283 |
public boolean isSupportedProviderLocale(Locale locale, Set<String> langtags) { |
|
43295
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
284 |
return Locale.ROOT.equals(locale) |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
285 |
|| langtags.contains(locale.stripExtensions().toLanguageTag()) |
58870c7a62e0
8167273: Calendar.getDisplayNames inconsistent with DateFormatSymbols
rgoel
parents:
33309
diff
changeset
|
286 |
|| langtags.contains(getEquivalentLoc(locale).toLanguageTag()); |
31263 | 287 |
} |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
288 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
289 |
/** |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
290 |
* Returns the canonical ID for the given ID |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
291 |
*/ |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
292 |
public Optional<String> canonicalTZID(String id) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
293 |
return Optional.ofNullable(baseMetaInfo.tzCanonicalIDs().get(id)); |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47442
diff
changeset
|
294 |
} |
31263 | 295 |
} |