author | pliden |
Tue, 18 Sep 2018 22:46:35 +0200 | |
changeset 51794 | 4129f43607cb |
parent 49918 | 8b9c78f0a712 |
child 58825 | c3696c94049d |
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 build.tools.cldrconverter; |
|
27 |
||
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
30 |
import java.io.PrintWriter; |
|
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
31 |
import java.util.Arrays; |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
32 |
import java.util.Formatter; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
33 |
import java.util.HashSet; |
31263 | 34 |
import java.util.HashMap; |
35 |
import java.util.LinkedHashMap; |
|
13583 | 36 |
import java.util.Map; |
31263 | 37 |
import java.util.Locale; |
38 |
import java.util.Objects; |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
39 |
import java.util.Set; |
13583 | 40 |
import java.util.SortedSet; |
41 |
||
42 |
class ResourceBundleGenerator implements BundleGenerator { |
|
31263 | 43 |
// preferred timezones - keeping compatibility with JDK1.1 3 letter abbreviations |
44 |
private static final String[] preferredTZIDs = { |
|
45 |
"America/Los_Angeles", |
|
46 |
"America/Denver", |
|
47 |
"America/Phoenix", |
|
48 |
"America/Chicago", |
|
49 |
"America/New_York", |
|
50 |
"America/Indianapolis", |
|
51 |
"Pacific/Honolulu", |
|
52 |
"America/Anchorage", |
|
53 |
"America/Halifax", |
|
54 |
"America/Sitka", |
|
55 |
"America/St_Johns", |
|
56 |
"Europe/Paris", |
|
57 |
// Although CLDR does not support abbreviated zones, handle "GMT" as a |
|
58 |
// special case here, as it is specified in the javadoc. |
|
59 |
"GMT", |
|
60 |
"Africa/Casablanca", |
|
61 |
"Asia/Jerusalem", |
|
62 |
"Asia/Tokyo", |
|
63 |
"Europe/Bucharest", |
|
64 |
"Asia/Shanghai", |
|
34425
0ed6ddfe6a10
8141243: Unexpected timezone returned after parsing a date
okutsu
parents:
33309
diff
changeset
|
65 |
"UTC", |
31263 | 66 |
}; |
67 |
||
68 |
// For duplicated values |
|
69 |
private static final String META_VALUE_PREFIX = "metaValue_"; |
|
70 |
||
13583 | 71 |
@Override |
72 |
public void generateBundle(String packageName, String baseName, String localeID, boolean useJava, |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
73 |
Map<String, ?> map, BundleType type) throws IOException { |
13583 | 74 |
String suffix = useJava ? ".java" : ".properties"; |
75 |
String dirName = CLDRConverter.DESTINATION_DIR + File.separator + "sun" + File.separator |
|
76 |
+ packageName + File.separator + "resources" + File.separator + "cldr"; |
|
36014
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
77 |
packageName = packageName + ".resources.cldr"; |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
78 |
|
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
79 |
if (CLDRConverter.isBaseModule ^ isBaseLocale(localeID)) { |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
80 |
return; |
13583 | 81 |
} |
36014
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
82 |
|
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
83 |
// Assume that non-base resources go into jdk.localedata |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
84 |
if (!CLDRConverter.isBaseModule) { |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
85 |
dirName = dirName + File.separator + "ext"; |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
86 |
packageName = packageName + ".ext"; |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
87 |
} |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
88 |
|
13583 | 89 |
File dir = new File(dirName); |
90 |
if (!dir.exists()) { |
|
91 |
dir.mkdirs(); |
|
92 |
} |
|
93 |
File file = new File(dir, baseName + ("root".equals(localeID) ? "" : "_" + localeID) + suffix); |
|
94 |
if (!file.exists()) { |
|
95 |
file.createNewFile(); |
|
96 |
} |
|
97 |
CLDRConverter.info("\tWriting file " + file); |
|
98 |
||
99 |
String encoding; |
|
100 |
if (useJava) { |
|
101 |
if (CLDRConverter.USE_UTF8) { |
|
102 |
encoding = "utf-8"; |
|
103 |
} else { |
|
104 |
encoding = "us-ascii"; |
|
105 |
} |
|
106 |
} else { |
|
107 |
encoding = "iso-8859-1"; |
|
108 |
} |
|
109 |
||
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
110 |
Formatter fmt = null; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
111 |
if (type == BundleType.TIMEZONE) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
112 |
fmt = new Formatter(); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
113 |
Set<String> metaKeys = new HashSet<>(); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
114 |
for (String key : map.keySet()) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
115 |
if (key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
116 |
String meta = key.substring(CLDRConverter.METAZONE_ID_PREFIX.length()); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
117 |
String[] value; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
118 |
value = (String[]) map.get(key); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
119 |
fmt.format(" final String[] %s = new String[] {\n", meta); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
120 |
for (String s : value) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
121 |
fmt.format(" \"%s\",\n", CLDRConverter.saveConvert(s, useJava)); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
122 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
123 |
fmt.format(" };\n"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
124 |
metaKeys.add(key); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
125 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
126 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
127 |
for (String key : metaKeys) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
128 |
map.remove(key); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
129 |
} |
31263 | 130 |
|
131 |
// Make it preferred ordered |
|
132 |
LinkedHashMap<String, Object> newMap = new LinkedHashMap<>(); |
|
133 |
for (String preferred : preferredTZIDs) { |
|
134 |
if (map.containsKey(preferred)) { |
|
135 |
newMap.put(preferred, map.remove(preferred)); |
|
34425
0ed6ddfe6a10
8141243: Unexpected timezone returned after parsing a date
okutsu
parents:
33309
diff
changeset
|
136 |
} else if (("GMT".equals(preferred) || "UTC".equals(preferred)) && |
31263 | 137 |
metaKeys.contains(CLDRConverter.METAZONE_ID_PREFIX+preferred)) { |
138 |
newMap.put(preferred, preferred); |
|
139 |
} |
|
140 |
} |
|
141 |
newMap.putAll(map); |
|
142 |
map = newMap; |
|
143 |
} else { |
|
144 |
// generic reduction of duplicated values |
|
145 |
Map<String, Object> newMap = null; |
|
146 |
for (String key : map.keySet()) { |
|
147 |
Object val = map.get(key); |
|
148 |
String metaVal = null; |
|
149 |
||
150 |
for (Map.Entry<String, ?> entry : map.entrySet()) { |
|
151 |
String k = entry.getKey(); |
|
152 |
if (!k.equals(key) && |
|
153 |
Objects.deepEquals(val, entry.getValue()) && |
|
154 |
!(Objects.nonNull(newMap) && newMap.containsKey(k))) { |
|
155 |
if (Objects.isNull(newMap)) { |
|
156 |
newMap = new HashMap<>(); |
|
157 |
fmt = new Formatter(); |
|
158 |
} |
|
159 |
||
160 |
if (Objects.isNull(metaVal)) { |
|
161 |
metaVal = META_VALUE_PREFIX + key.replaceAll("\\.", "_"); |
|
162 |
||
163 |
if (val instanceof String[]) { |
|
164 |
fmt.format(" final String[] %s = new String[] {\n", metaVal); |
|
165 |
for (String s : (String[])val) { |
|
166 |
fmt.format(" \"%s\",\n", CLDRConverter.saveConvert(s, useJava)); |
|
167 |
} |
|
168 |
fmt.format(" };\n"); |
|
169 |
} else { |
|
170 |
fmt.format(" final String %s = \"%s\";\n", metaVal, CLDRConverter.saveConvert((String)val, useJava)); |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
newMap.put(k, metaVal); |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
if (Objects.nonNull(metaVal)) { |
|
179 |
newMap.put(key, metaVal); |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
if (Objects.nonNull(newMap)) { |
|
184 |
for (String key : map.keySet()) { |
|
185 |
newMap.putIfAbsent(key, map.get(key)); |
|
186 |
} |
|
187 |
map = newMap; |
|
188 |
} |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
189 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
190 |
|
13583 | 191 |
try (PrintWriter out = new PrintWriter(file, encoding)) { |
192 |
// Output copyright headers |
|
193 |
out.println(CopyrightHeaders.getOpenJDKCopyright()); |
|
194 |
out.println(CopyrightHeaders.getUnicodeCopyright()); |
|
195 |
||
196 |
if (useJava) { |
|
197 |
out.println("package sun." + packageName + ";\n"); |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
198 |
out.printf("import %s;\n\n", type.getPathName()); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
199 |
out.printf("public class %s%s extends %s {\n", baseName, "root".equals(localeID) ? "" : "_" + localeID, type.getClassName()); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
200 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
201 |
out.println(" @Override\n" + |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
202 |
" protected final Object[][] getContents() {"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
203 |
if (fmt != null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
204 |
out.print(fmt.toString()); |
13583 | 205 |
} |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
206 |
out.println(" final Object[][] data = new Object[][] {"); |
13583 | 207 |
} |
208 |
for (String key : map.keySet()) { |
|
209 |
if (useJava) { |
|
210 |
Object value = map.get(key); |
|
211 |
if (value == null) { |
|
212 |
CLDRConverter.warning("null value for " + key); |
|
213 |
} else if (value instanceof String) { |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
214 |
String valStr = (String)value; |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
215 |
if (type == BundleType.TIMEZONE && |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
216 |
!key.startsWith(CLDRConverter.EXEMPLAR_CITY_PREFIX) || |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
217 |
valStr.startsWith(META_VALUE_PREFIX)) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
218 |
out.printf(" { \"%s\", %s },\n", key, CLDRConverter.saveConvert(valStr, useJava)); |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
219 |
} else { |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
220 |
out.printf(" { \"%s\", \"%s\" },\n", key, CLDRConverter.saveConvert(valStr, useJava)); |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
221 |
} |
13583 | 222 |
} else if (value instanceof String[]) { |
223 |
String[] values = (String[]) value; |
|
224 |
out.println(" { \"" + key + "\",\n new String[] {"); |
|
225 |
for (String s : values) { |
|
226 |
out.println(" \"" + CLDRConverter.saveConvert(s, useJava) + "\","); |
|
227 |
} |
|
228 |
out.println(" }\n },"); |
|
229 |
} else { |
|
230 |
throw new RuntimeException("unknown value type: " + value.getClass().getName()); |
|
231 |
} |
|
232 |
} else { |
|
233 |
out.println(key + "=" + CLDRConverter.saveConvert((String) map.get(key), useJava)); |
|
234 |
} |
|
235 |
} |
|
236 |
if (useJava) { |
|
237 |
out.println(" };\n return data;\n }\n}"); |
|
238 |
} |
|
239 |
} |
|
240 |
} |
|
241 |
||
242 |
@Override |
|
243 |
public void generateMetaInfo(Map<String, SortedSet<String>> metaInfo) throws IOException { |
|
26632
f87ab7e0bf39
8058509: CLDRLocaleDataMetaInfo should be in jdk.localedata
naoto
parents:
26360
diff
changeset
|
244 |
String dirName = CLDRConverter.DESTINATION_DIR + File.separator + "sun" + File.separator + "util" + |
31263 | 245 |
File.separator + |
246 |
(CLDRConverter.isBaseModule ? "cldr" + File.separator + File.separator : |
|
247 |
"resources" + File.separator + "cldr" + File.separator + "provider" + File.separator); |
|
13583 | 248 |
File dir = new File(dirName); |
249 |
if (!dir.exists()) { |
|
250 |
dir.mkdirs(); |
|
251 |
} |
|
31263 | 252 |
String className = |
36116
b386aa77e834
8150434: Remove redundant "jdk_localedata" from the CLDR locale data meta info class name
naoto
parents:
36014
diff
changeset
|
253 |
(CLDRConverter.isBaseModule ? "CLDRBaseLocaleDataMetaInfo" : "CLDRLocaleDataMetaInfo"); |
31263 | 254 |
File file = new File(dir, className + ".java"); |
13583 | 255 |
if (!file.exists()) { |
256 |
file.createNewFile(); |
|
257 |
} |
|
258 |
CLDRConverter.info("Generating file " + file); |
|
259 |
||
260 |
try (PrintWriter out = new PrintWriter(file, "us-ascii")) { |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
261 |
out.printf(CopyrightHeaders.getOpenJDKCopyright()); |
13583 | 262 |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
263 |
out.printf((CLDRConverter.isBaseModule ? "package sun.util.cldr;\n\n" : |
31263 | 264 |
"package sun.util.resources.cldr.provider;\n\n") |
265 |
+ "import java.util.HashMap;\n" |
|
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
266 |
+ "import java.util.Locale;\n" |
31263 | 267 |
+ "import java.util.Map;\n" |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
268 |
+ "import sun.util.locale.provider.LocaleDataMetaInfo;\n" |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
269 |
+ "import sun.util.locale.provider.LocaleProviderAdapter;\n\n"); |
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
270 |
out.printf("public class %s implements LocaleDataMetaInfo {\n", className); |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
271 |
out.printf(" private static final Map<String, String> resourceNameToLocales = new HashMap<>();\n" + |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
272 |
(CLDRConverter.isBaseModule ? |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
273 |
" private static final Map<Locale, String[]> parentLocalesMap = new HashMap<>();\n" + |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
274 |
" private static final Map<String, String> languageAliasMap = new HashMap<>();\n\n" : |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
275 |
"\n") + |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
276 |
" static {\n"); |
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
277 |
|
13583 | 278 |
for (String key : metaInfo.keySet()) { |
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
279 |
if (key.startsWith(CLDRConverter.PARENT_LOCALE_PREFIX)) { |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
280 |
String parentTag = key.substring(CLDRConverter.PARENT_LOCALE_PREFIX.length()); |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
281 |
if ("root".equals(parentTag)) { |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
282 |
out.printf(" parentLocalesMap.put(Locale.ROOT,\n"); |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
283 |
} else { |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
284 |
out.printf(" parentLocalesMap.put(Locale.forLanguageTag(\"%s\"),\n", |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
285 |
parentTag); |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
286 |
} |
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
287 |
String[] children = toLocaleList(metaInfo.get(key), true).split(" "); |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
288 |
Arrays.sort(children); |
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
289 |
out.printf(" new String[] {\n" + |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
290 |
" "); |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
291 |
int count = 0; |
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
292 |
for (int i = 0; i < children.length; i++) { |
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
293 |
String child = children[i]; |
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
294 |
out.printf("\"%s\", ", child); |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
295 |
count += child.length() + 4; |
33309
3aecb54196d9
8136668: Default locale provider adapter incorrectly set to JRE
naoto
parents:
32514
diff
changeset
|
296 |
if (i != children.length - 1 && count > 64) { |
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
297 |
out.printf("\n "); |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
298 |
count = 0; |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
299 |
} |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
300 |
} |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
301 |
out.printf("\n });\n"); |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
302 |
} else { |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
303 |
if ("AvailableLocales".equals(key)) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
304 |
out.printf(" resourceNameToLocales.put(\"%s\",\n", key); |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
305 |
out.printf(" \"%s\");\n", toLocaleList(applyLanguageAliases(metaInfo.get(key)), false)); |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
306 |
} |
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
307 |
} |
13583 | 308 |
} |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
309 |
// for languageAliasMap |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
310 |
if (CLDRConverter.isBaseModule) { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
311 |
CLDRConverter.handlerSupplMeta.getLanguageAliasData().forEach((key, value) -> { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
312 |
out.printf(" languageAliasMap.put(\"%s\", \"%s\");\n", key, value); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
313 |
}); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
314 |
} |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
315 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
316 |
out.printf(" }\n\n"); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
317 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
318 |
// end of static initializer block. |
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
23010
diff
changeset
|
319 |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
320 |
// Canonical TZ names for delayed initialization |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
321 |
if (CLDRConverter.isBaseModule) { |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
322 |
out.printf(" private static class TZCanonicalIDMapHolder {\n"); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
323 |
out.printf(" static final Map<String, String> tzCanonicalIDMap = new HashMap<>(600);\n"); |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
324 |
out.printf(" static {\n"); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
325 |
CLDRConverter.handlerTimeZone.getData().entrySet().stream() |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
326 |
.forEach(e -> { |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
327 |
String[] ids = ((String)e.getValue()).split("\\s"); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
328 |
out.printf(" tzCanonicalIDMap.put(\"%s\", \"%s\");\n", e.getKey(), |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
329 |
ids[0]); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
330 |
for (int i = 1; i < ids.length; i++) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
331 |
out.printf(" tzCanonicalIDMap.put(\"%s\", \"%s\");\n", ids[i], |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
332 |
ids[0]); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
333 |
} |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
334 |
}); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
335 |
out.printf(" }\n }\n\n"); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
336 |
} |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
337 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
338 |
out.printf(" @Override\n" + |
31263 | 339 |
" public LocaleProviderAdapter.Type getType() {\n" + |
26360
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
23010
diff
changeset
|
340 |
" return LocaleProviderAdapter.Type.CLDR;\n" + |
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
23010
diff
changeset
|
341 |
" }\n\n"); |
697f70835528
8038436: Re-examine the mechanism to determine available localedata and cldrdata
naoto
parents:
23010
diff
changeset
|
342 |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
343 |
out.printf(" @Override\n" + |
31263 | 344 |
" public String availableLanguageTags(String category) {\n" + |
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
345 |
" return resourceNameToLocales.getOrDefault(category, \"\");\n" + |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
346 |
" }\n\n"); |
31263 | 347 |
|
348 |
if (CLDRConverter.isBaseModule) { |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
349 |
out.printf(" @Override\n" + |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
350 |
" public Map<String, String> getLanguageAliasMap() {\n" + |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
351 |
" return languageAliasMap;\n" + |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
352 |
" }\n\n"); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
353 |
out.printf(" @Override\n" + |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
354 |
" public Map<String, String> tzCanonicalIDs() {\n" + |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
355 |
" return TZCanonicalIDMapHolder.tzCanonicalIDMap;\n" + |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
356 |
" }\n\n"); |
32514
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
357 |
out.printf(" public Map<Locale, String[]> parentLocales() {\n" + |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
358 |
" return parentLocalesMap;\n" + |
ca8c1ed31e0d
8134915: Improve performance of CLDRLocaleProviderAdapter.getCandidateLocales
naoto
parents:
31263
diff
changeset
|
359 |
" }\n}"); |
31263 | 360 |
} else { |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
361 |
out.printf("}"); |
31263 | 362 |
} |
13583 | 363 |
} |
364 |
} |
|
365 |
||
31263 | 366 |
private static final Locale.Builder LOCALE_BUILDER = new Locale.Builder(); |
367 |
private static boolean isBaseLocale(String localeID) { |
|
368 |
localeID = localeID.replaceAll("-", "_"); |
|
369 |
// ignore script here |
|
370 |
Locale locale = LOCALE_BUILDER |
|
371 |
.clear() |
|
372 |
.setLanguage(CLDRConverter.getLanguageCode(localeID)) |
|
36014
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
34425
diff
changeset
|
373 |
.setRegion(CLDRConverter.getRegionCode(localeID)) |
31263 | 374 |
.build(); |
375 |
return CLDRConverter.BASE_LOCALES.contains(locale); |
|
376 |
} |
|
377 |
||
378 |
private static String toLocaleList(SortedSet<String> set, boolean all) { |
|
13583 | 379 |
StringBuilder sb = new StringBuilder(set.size() * 6); |
380 |
for (String id : set) { |
|
381 |
if (!"root".equals(id)) { |
|
31263 | 382 |
if (!all && CLDRConverter.isBaseModule ^ isBaseLocale(id)) { |
383 |
continue; |
|
384 |
} |
|
36511 | 385 |
sb.append(' '); |
13583 | 386 |
sb.append(id); |
387 |
} |
|
388 |
} |
|
389 |
return sb.toString(); |
|
390 |
} |
|
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
391 |
|
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
392 |
private static SortedSet<String> applyLanguageAliases(SortedSet<String> tags) { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
393 |
CLDRConverter.handlerSupplMeta.getLanguageAliasData().forEach((key, value) -> { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
394 |
if (tags.remove(key)) { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
395 |
tags.add(value); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
396 |
} |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
397 |
}); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
398 |
return tags; |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49904
diff
changeset
|
399 |
} |
13583 | 400 |
} |