author | naoto |
Thu, 26 Apr 2018 12:39:15 -0700 | |
changeset 49904 | cadca99d52e7 |
parent 49699 | 5c2cddff67b6 |
child 49918 | 8b9c78f0a712 |
permissions | -rw-r--r-- |
13583 | 1 |
/* |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
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 |
||
32510
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
28 |
import static build.tools.cldrconverter.Bundle.jreTimeZoneNames; |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
29 |
import build.tools.cldrconverter.BundleGenerator.BundleType; |
13583 | 30 |
import java.io.File; |
49699
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
31 |
import java.io.IOException; |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
32 |
import java.io.UncheckedIOException; |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
33 |
import java.nio.file.*; |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
34 |
import java.text.MessageFormat; |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
35 |
import java.time.*; |
13583 | 36 |
import java.util.*; |
31263 | 37 |
import java.util.ResourceBundle.Control; |
38 |
import java.util.logging.Level; |
|
39 |
import java.util.logging.Logger; |
|
47473
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
40 |
import java.util.stream.Collectors; |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
41 |
import java.util.stream.IntStream; |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
42 |
import java.util.stream.Stream; |
13583 | 43 |
import javax.xml.parsers.SAXParser; |
44 |
import javax.xml.parsers.SAXParserFactory; |
|
17466
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
45 |
import org.xml.sax.SAXNotRecognizedException; |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
46 |
import org.xml.sax.SAXNotSupportedException; |
13583 | 47 |
|
48 |
||
49 |
/** |
|
50 |
* Converts locale data from "Locale Data Markup Language" format to |
|
51 |
* JRE resource bundle format. LDML is the format used by the Common |
|
52 |
* Locale Data Repository maintained by the Unicode Consortium. |
|
53 |
*/ |
|
54 |
public class CLDRConverter { |
|
55 |
||
56 |
static final String LDML_DTD_SYSTEM_ID = "http://www.unicode.org/cldr/dtd/2.0/ldml.dtd"; |
|
57 |
static final String SPPL_LDML_DTD_SYSTEM_ID = "http://www.unicode.org/cldr/dtd/2.0/ldmlSupplemental.dtd"; |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
58 |
static final String BCP47_LDML_DTD_SYSTEM_ID = "http://www.unicode.org/cldr/dtd/2.0/ldmlBCP47.dtd"; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
59 |
|
13583 | 60 |
|
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
61 |
private static String CLDR_BASE; |
13583 | 62 |
static String LOCAL_LDML_DTD; |
63 |
static String LOCAL_SPPL_LDML_DTD; |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
64 |
static String LOCAL_BCP47_LDML_DTD; |
13583 | 65 |
private static String SOURCE_FILE_DIR; |
66 |
private static String SPPL_SOURCE_FILE; |
|
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
67 |
private static String SPPL_META_SOURCE_FILE; |
13583 | 68 |
private static String NUMBERING_SOURCE_FILE; |
69 |
private static String METAZONES_SOURCE_FILE; |
|
38747 | 70 |
private static String LIKELYSUBTAGS_SOURCE_FILE; |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
71 |
private static String TIMEZONE_SOURCE_FILE; |
13583 | 72 |
static String DESTINATION_DIR = "build/gensrc"; |
73 |
||
74 |
static final String LOCALE_NAME_PREFIX = "locale.displayname."; |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
75 |
static final String LOCALE_SEPARATOR = LOCALE_NAME_PREFIX + "separator"; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
76 |
static final String LOCALE_KEYTYPE = LOCALE_NAME_PREFIX + "keytype"; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
77 |
static final String LOCALE_KEY_PREFIX = LOCALE_NAME_PREFIX + "key."; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
78 |
static final String LOCALE_TYPE_PREFIX = LOCALE_NAME_PREFIX + "type."; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
79 |
static final String LOCALE_TYPE_PREFIX_CA = LOCALE_TYPE_PREFIX + "ca."; |
13583 | 80 |
static final String CURRENCY_SYMBOL_PREFIX = "currency.symbol."; |
81 |
static final String CURRENCY_NAME_PREFIX = "currency.displayname."; |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
82 |
static final String CALENDAR_NAME_PREFIX = "calendarname."; |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
83 |
static final String CALENDAR_FIRSTDAY_PREFIX = "firstDay."; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
84 |
static final String CALENDAR_MINDAYS_PREFIX = "minDays."; |
13583 | 85 |
static final String TIMEZONE_ID_PREFIX = "timezone.id."; |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
86 |
static final String EXEMPLAR_CITY_PREFIX = "timezone.excity."; |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
87 |
static final String ZONE_NAME_PREFIX = "timezone.displayname."; |
13583 | 88 |
static final String METAZONE_ID_PREFIX = "metazone.id."; |
31263 | 89 |
static final String PARENT_LOCALE_PREFIX = "parentLocale."; |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
90 |
static final String[] EMPTY_ZONE = {"", "", "", "", "", ""}; |
13583 | 91 |
|
92 |
private static SupplementDataParseHandler handlerSuppl; |
|
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
93 |
private static SupplementalMetadataParseHandler handlerSupplMeta; |
38747 | 94 |
private static LikelySubtagsParseHandler handlerLikelySubtags; |
13583 | 95 |
static NumberingSystemsParseHandler handlerNumbering; |
96 |
static MetaZonesParseHandler handlerMetaZones; |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
97 |
static TimeZoneParseHandler handlerTimeZone; |
13583 | 98 |
private static BundleGenerator bundleGenerator; |
99 |
||
31263 | 100 |
// java.base module related |
101 |
static boolean isBaseModule = false; |
|
102 |
static final Set<Locale> BASE_LOCALES = new HashSet<>(); |
|
103 |
||
104 |
// "parentLocales" map |
|
105 |
private static final Map<String, SortedSet<String>> parentLocalesMap = new HashMap<>(); |
|
106 |
private static final ResourceBundle.Control defCon = |
|
107 |
ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT); |
|
108 |
||
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
109 |
private static final String[] AVAILABLE_TZIDS = TimeZone.getAvailableIDs(); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
110 |
private static String zoneNameTempFile; |
49699
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
111 |
private static String tzDataDir; |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
112 |
|
16852 | 113 |
static enum DraftType { |
114 |
UNCONFIRMED, |
|
115 |
PROVISIONAL, |
|
116 |
CONTRIBUTED, |
|
117 |
APPROVED; |
|
118 |
||
119 |
private static final Map<String, DraftType> map = new HashMap<>(); |
|
120 |
static { |
|
121 |
for (DraftType dt : values()) { |
|
122 |
map.put(dt.getKeyword(), dt); |
|
123 |
} |
|
124 |
} |
|
125 |
static private DraftType defaultType = CONTRIBUTED; |
|
126 |
||
127 |
private final String keyword; |
|
128 |
||
129 |
private DraftType() { |
|
130 |
keyword = this.name().toLowerCase(Locale.ROOT); |
|
13583 | 131 |
|
16852 | 132 |
} |
133 |
||
134 |
static DraftType forKeyword(String keyword) { |
|
135 |
return map.get(keyword); |
|
136 |
} |
|
137 |
||
138 |
static DraftType getDefault() { |
|
139 |
return defaultType; |
|
140 |
} |
|
141 |
||
142 |
static void setDefault(String keyword) { |
|
143 |
defaultType = Objects.requireNonNull(forKeyword(keyword)); |
|
144 |
} |
|
145 |
||
146 |
String getKeyword() { |
|
147 |
return keyword; |
|
148 |
} |
|
149 |
} |
|
13583 | 150 |
|
151 |
static boolean USE_UTF8 = false; |
|
152 |
private static boolean verbose; |
|
153 |
||
154 |
private CLDRConverter() { |
|
155 |
// no instantiation |
|
156 |
} |
|
157 |
||
158 |
@SuppressWarnings("AssignmentToForLoopParameter") |
|
159 |
public static void main(String[] args) throws Exception { |
|
160 |
if (args.length != 0) { |
|
161 |
String currentArg = null; |
|
162 |
try { |
|
163 |
for (int i = 0; i < args.length; i++) { |
|
164 |
currentArg = args[i]; |
|
165 |
switch (currentArg) { |
|
166 |
case "-draft": |
|
167 |
String draftDataType = args[++i]; |
|
168 |
try { |
|
16852 | 169 |
DraftType.setDefault(draftDataType); |
13583 | 170 |
} catch (NullPointerException e) { |
171 |
severe("Error: incorrect draft value: %s%n", draftDataType); |
|
172 |
System.exit(1); |
|
173 |
} |
|
174 |
info("Using the specified data type: %s%n", draftDataType); |
|
175 |
break; |
|
176 |
||
177 |
case "-base": |
|
178 |
// base directory for input files |
|
179 |
CLDR_BASE = args[++i]; |
|
180 |
if (!CLDR_BASE.endsWith("/")) { |
|
181 |
CLDR_BASE += "/"; |
|
182 |
} |
|
183 |
break; |
|
184 |
||
31263 | 185 |
case "-baselocales": |
186 |
// base locales |
|
187 |
setupBaseLocales(args[++i]); |
|
188 |
break; |
|
189 |
||
190 |
case "-basemodule": |
|
191 |
// indicates java.base module resource generation |
|
192 |
isBaseModule = true; |
|
193 |
break; |
|
194 |
||
13583 | 195 |
case "-o": |
196 |
// output directory |
|
197 |
DESTINATION_DIR = args[++i]; |
|
198 |
break; |
|
199 |
||
200 |
case "-utf8": |
|
201 |
USE_UTF8 = true; |
|
202 |
break; |
|
203 |
||
204 |
case "-verbose": |
|
205 |
verbose = true; |
|
206 |
break; |
|
207 |
||
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
208 |
case "-zntempfile": |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
209 |
zoneNameTempFile = args[++i]; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
210 |
break; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
211 |
|
49699
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
212 |
case "-tzdatadir": |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
213 |
tzDataDir = args[++i]; |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
214 |
break; |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
215 |
|
13583 | 216 |
case "-help": |
217 |
usage(); |
|
218 |
System.exit(0); |
|
219 |
break; |
|
220 |
||
221 |
default: |
|
222 |
throw new RuntimeException(); |
|
223 |
} |
|
224 |
} |
|
225 |
} catch (RuntimeException e) { |
|
226 |
severe("unknown or imcomplete arg(s): " + currentArg); |
|
227 |
usage(); |
|
228 |
System.exit(1); |
|
229 |
} |
|
230 |
} |
|
231 |
||
232 |
// Set up path names |
|
38747 | 233 |
LOCAL_LDML_DTD = CLDR_BASE + "/dtd/ldml.dtd"; |
234 |
LOCAL_SPPL_LDML_DTD = CLDR_BASE + "/dtd/ldmlSupplemental.dtd"; |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
235 |
LOCAL_BCP47_LDML_DTD = CLDR_BASE + "/dtd/ldmlBCP47.dtd"; |
38747 | 236 |
SOURCE_FILE_DIR = CLDR_BASE + "/main"; |
237 |
SPPL_SOURCE_FILE = CLDR_BASE + "/supplemental/supplementalData.xml"; |
|
238 |
LIKELYSUBTAGS_SOURCE_FILE = CLDR_BASE + "/supplemental/likelySubtags.xml"; |
|
239 |
NUMBERING_SOURCE_FILE = CLDR_BASE + "/supplemental/numberingSystems.xml"; |
|
240 |
METAZONES_SOURCE_FILE = CLDR_BASE + "/supplemental/metaZones.xml"; |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
241 |
TIMEZONE_SOURCE_FILE = CLDR_BASE + "/bcp47/timezone.xml"; |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
242 |
SPPL_META_SOURCE_FILE = CLDR_BASE + "/supplemental/supplementalMetadata.xml"; |
13583 | 243 |
|
31263 | 244 |
if (BASE_LOCALES.isEmpty()) { |
245 |
setupBaseLocales("en-US"); |
|
246 |
} |
|
247 |
||
13583 | 248 |
bundleGenerator = new ResourceBundleGenerator(); |
249 |
||
31263 | 250 |
// Parse data independent of locales |
251 |
parseSupplemental(); |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
252 |
parseBCP47(); |
31263 | 253 |
|
13583 | 254 |
List<Bundle> bundles = readBundleList(); |
255 |
convertBundles(bundles); |
|
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
256 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
257 |
// Generate java.time.format.ZoneName.java |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
258 |
if (isBaseModule) { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
259 |
generateZoneName(); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
260 |
} |
13583 | 261 |
} |
262 |
||
263 |
private static void usage() { |
|
264 |
errout("Usage: java CLDRConverter [options]%n" |
|
265 |
+ "\t-help output this usage message and exit%n" |
|
266 |
+ "\t-verbose output information%n" |
|
38747 | 267 |
+ "\t-draft [contributed | approved | provisional | unconfirmed]%n" |
268 |
+ "\t\t draft level for using data (default: contributed)%n" |
|
13583 | 269 |
+ "\t-base dir base directory for CLDR input files%n" |
31263 | 270 |
+ "\t-basemodule generates bundles that go into java.base module%n" |
271 |
+ "\t-baselocales loc(,loc)* locales that go into the base module%n" |
|
272 |
+ "\t-o dir output directory (default: ./build/gensrc)%n" |
|
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
273 |
+ "\t-zntempfile template file for java.time.format.ZoneName.java%n" |
49699
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
274 |
+ "\t-tzdatadir tzdata directory for java.time.format.ZoneName.java%n" |
13583 | 275 |
+ "\t-utf8 use UTF-8 rather than \\uxxxx (for debug)%n"); |
276 |
} |
|
277 |
||
278 |
static void info(String fmt, Object... args) { |
|
279 |
if (verbose) { |
|
280 |
System.out.printf(fmt, args); |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
static void info(String msg) { |
|
285 |
if (verbose) { |
|
286 |
System.out.println(msg); |
|
287 |
} |
|
288 |
} |
|
289 |
||
290 |
static void warning(String fmt, Object... args) { |
|
291 |
System.err.print("Warning: "); |
|
292 |
System.err.printf(fmt, args); |
|
293 |
} |
|
294 |
||
295 |
static void warning(String msg) { |
|
296 |
System.err.print("Warning: "); |
|
297 |
errout(msg); |
|
298 |
} |
|
299 |
||
300 |
static void severe(String fmt, Object... args) { |
|
301 |
System.err.print("Error: "); |
|
302 |
System.err.printf(fmt, args); |
|
303 |
} |
|
304 |
||
305 |
static void severe(String msg) { |
|
306 |
System.err.print("Error: "); |
|
307 |
errout(msg); |
|
308 |
} |
|
309 |
||
310 |
private static void errout(String msg) { |
|
311 |
if (msg.contains("%n")) { |
|
312 |
System.err.printf(msg); |
|
313 |
} else { |
|
314 |
System.err.println(msg); |
|
315 |
} |
|
316 |
} |
|
317 |
||
17466
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
318 |
/** |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
319 |
* Configure the parser to allow access to DTDs on the file system. |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
320 |
*/ |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
321 |
private static void enableFileAccess(SAXParser parser) throws SAXNotSupportedException { |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
322 |
try { |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
323 |
parser.setProperty("http://javax.xml.XMLConstants/property/accessExternalDTD", "file"); |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
324 |
} catch (SAXNotRecognizedException ignore) { |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
325 |
// property requires >= JAXP 1.5 |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
326 |
} |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
327 |
} |
e2c55878b26a
8014500: bootcycle-images fails after upgrade to JAXP 1.5
alanb
parents:
16852
diff
changeset
|
328 |
|
13583 | 329 |
private static List<Bundle> readBundleList() throws Exception { |
330 |
List<Bundle> retList = new ArrayList<>(); |
|
331 |
Path path = FileSystems.getDefault().getPath(SOURCE_FILE_DIR); |
|
332 |
try (DirectoryStream<Path> dirStr = Files.newDirectoryStream(path)) { |
|
333 |
for (Path entry : dirStr) { |
|
334 |
String fileName = entry.getFileName().toString(); |
|
335 |
if (fileName.endsWith(".xml")) { |
|
336 |
String id = fileName.substring(0, fileName.indexOf('.')); |
|
337 |
Locale cldrLoc = Locale.forLanguageTag(toLanguageTag(id)); |
|
47473
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
338 |
StringBuilder sb = getCandLocales(cldrLoc); |
13583 | 339 |
if (sb.indexOf("root") == -1) { |
340 |
sb.append("root"); |
|
341 |
} |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
342 |
Bundle b = new Bundle(id, sb.toString(), null, null); |
31263 | 343 |
// Insert the bundle for root at the top so that it will get |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
344 |
// processed first. |
31263 | 345 |
if ("root".equals(id)) { |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
346 |
retList.add(0, b); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
347 |
} else { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
348 |
retList.add(b); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
349 |
} |
13583 | 350 |
} |
351 |
} |
|
352 |
} |
|
353 |
return retList; |
|
354 |
} |
|
355 |
||
31263 | 356 |
private static final Map<String, Map<String, Object>> cldrBundles = new HashMap<>(); |
47473
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
357 |
|
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
358 |
private static Map<String, SortedSet<String>> metaInfo = new HashMap<>(); |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
359 |
|
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
360 |
static { |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
361 |
// For generating information on supported locales. |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
362 |
metaInfo.put("AvailableLocales", new TreeSet<>()); |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
363 |
} |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
364 |
|
13583 | 365 |
static Map<String, Object> getCLDRBundle(String id) throws Exception { |
366 |
Map<String, Object> bundle = cldrBundles.get(id); |
|
367 |
if (bundle != null) { |
|
368 |
return bundle; |
|
369 |
} |
|
370 |
File file = new File(SOURCE_FILE_DIR + File.separator + id + ".xml"); |
|
371 |
if (!file.exists()) { |
|
372 |
// Skip if the file doesn't exist. |
|
373 |
return Collections.emptyMap(); |
|
374 |
} |
|
375 |
||
376 |
info("..... main directory ....."); |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
377 |
LDMLParseHandler handler = new LDMLParseHandler(id); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
378 |
parseLDMLFile(file, handler); |
13583 | 379 |
|
380 |
bundle = handler.getData(); |
|
381 |
cldrBundles.put(id, bundle); |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
382 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
383 |
if (id.equals("root")) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
384 |
// Calendar data (firstDayOfWeek & minDaysInFirstWeek) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
385 |
bundle = handlerSuppl.getData("root"); |
13583 | 386 |
if (bundle != null) { |
387 |
//merge two maps into one map |
|
388 |
Map<String, Object> temp = cldrBundles.remove(id); |
|
389 |
bundle.putAll(temp); |
|
390 |
cldrBundles.put(id, bundle); |
|
391 |
} |
|
392 |
} |
|
393 |
return bundle; |
|
394 |
} |
|
395 |
||
31263 | 396 |
// Parsers for data in "supplemental" directory |
397 |
// |
|
398 |
private static void parseSupplemental() throws Exception { |
|
13583 | 399 |
// Parse SupplementalData file and store the information in the HashMap |
400 |
// Calendar information such as firstDay and minDay are stored in |
|
401 |
// supplementalData.xml as of CLDR1.4. Individual territory is listed |
|
402 |
// with its ISO 3166 country code while default is listed using UNM49 |
|
403 |
// region and composition numerical code (001 for World.) |
|
31263 | 404 |
// |
405 |
// SupplementalData file also provides the "parent" locales which |
|
406 |
// are othrwise not to be fallen back. Process them here as well. |
|
407 |
// |
|
13583 | 408 |
handlerSuppl = new SupplementDataParseHandler(); |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
409 |
parseLDMLFile(new File(SPPL_SOURCE_FILE), handlerSuppl); |
31263 | 410 |
Map<String, Object> parentData = handlerSuppl.getData("root"); |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
411 |
parentData.keySet().stream() |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
412 |
.filter(key -> key.startsWith(PARENT_LOCALE_PREFIX)) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
413 |
.forEach(key -> { |
31263 | 414 |
parentLocalesMap.put(key, new TreeSet( |
415 |
Arrays.asList(((String)parentData.get(key)).split(" ")))); |
|
416 |
}); |
|
13583 | 417 |
|
418 |
// Parse numberingSystems to get digit zero character information. |
|
419 |
handlerNumbering = new NumberingSystemsParseHandler(); |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
420 |
parseLDMLFile(new File(NUMBERING_SOURCE_FILE), handlerNumbering); |
13583 | 421 |
|
422 |
// Parse metaZones to create mappings between Olson tzids and CLDR meta zone names |
|
423 |
handlerMetaZones = new MetaZonesParseHandler(); |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
424 |
parseLDMLFile(new File(METAZONES_SOURCE_FILE), handlerMetaZones); |
38747 | 425 |
|
426 |
// Parse likelySubtags |
|
427 |
handlerLikelySubtags = new LikelySubtagsParseHandler(); |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
428 |
parseLDMLFile(new File(LIKELYSUBTAGS_SOURCE_FILE), handlerLikelySubtags); |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
429 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
430 |
// Parse supplementalMetadata |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
431 |
// Currently only interested in deprecated time zone ids. |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
432 |
handlerSupplMeta = new SupplementalMetadataParseHandler(); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
433 |
parseLDMLFile(new File(SPPL_META_SOURCE_FILE), handlerSupplMeta); |
31263 | 434 |
} |
13583 | 435 |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
436 |
// Parsers for data in "bcp47" directory |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
437 |
// |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
438 |
private static void parseBCP47() throws Exception { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
439 |
// Parse timezone |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
440 |
handlerTimeZone = new TimeZoneParseHandler(); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
441 |
parseLDMLFile(new File(TIMEZONE_SOURCE_FILE), handlerTimeZone); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
442 |
} |
47473
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
443 |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
444 |
private static void parseLDMLFile(File srcfile, AbstractLDMLHandler handler) throws Exception { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
445 |
info("..... Parsing " + srcfile.getName() + " ....."); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
446 |
SAXParserFactory pf = SAXParserFactory.newInstance(); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
447 |
pf.setValidating(true); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
448 |
SAXParser parser = pf.newSAXParser(); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
449 |
enableFileAccess(parser); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
450 |
parser.parse(srcfile, handler); |
47473
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
451 |
} |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
452 |
|
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
453 |
private static StringBuilder getCandLocales(Locale cldrLoc) { |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
454 |
List<Locale> candList = getCandidateLocales(cldrLoc); |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
455 |
StringBuilder sb = new StringBuilder(); |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
456 |
for (Locale loc : candList) { |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
457 |
if (!loc.equals(Locale.ROOT)) { |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
458 |
sb.append(toLocaleName(loc.toLanguageTag())); |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
459 |
sb.append(","); |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
460 |
} |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
461 |
} |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
462 |
return sb; |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
463 |
} |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
464 |
|
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
465 |
private static List<Locale> getCandidateLocales(Locale cldrLoc) { |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
466 |
List<Locale> candList = new ArrayList<>(); |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
467 |
candList = applyParentLocales("", defCon.getCandidateLocales("", cldrLoc)); |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
468 |
return candList; |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
469 |
} |
5d798d729fec
8185841: Values from getFirstDayOfWeek() are inconsistent with CLDR
rgoel
parents:
47216
diff
changeset
|
470 |
|
31263 | 471 |
private static void convertBundles(List<Bundle> bundles) throws Exception { |
472 |
// parent locales map. The mappings are put in base metaInfo file |
|
473 |
// for now. |
|
474 |
if (isBaseModule) { |
|
475 |
metaInfo.putAll(parentLocalesMap); |
|
476 |
} |
|
13583 | 477 |
|
478 |
for (Bundle bundle : bundles) { |
|
479 |
// Get the target map, which contains all the data that should be |
|
480 |
// visible for the bundle's locale |
|
481 |
||
482 |
Map<String, Object> targetMap = bundle.getTargetMap(); |
|
483 |
||
484 |
EnumSet<Bundle.Type> bundleTypes = bundle.getBundleTypes(); |
|
485 |
||
486 |
if (bundle.isRoot()) { |
|
487 |
// Add DateTimePatternChars because CLDR no longer supports localized patterns. |
|
488 |
targetMap.put("DateTimePatternChars", "GyMdkHmsSEDFwWahKzZ"); |
|
489 |
} |
|
490 |
||
491 |
// Now the map contains just the entries that need to be in the resources bundles. |
|
492 |
// Go ahead and generate them. |
|
493 |
if (bundleTypes.contains(Bundle.Type.LOCALENAMES)) { |
|
494 |
Map<String, Object> localeNamesMap = extractLocaleNames(targetMap, bundle.getID()); |
|
495 |
if (!localeNamesMap.isEmpty() || bundle.isRoot()) { |
|
32030
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
31263
diff
changeset
|
496 |
bundleGenerator.generateBundle("util", "LocaleNames", bundle.getJavaID(), true, localeNamesMap, BundleType.OPEN); |
13583 | 497 |
} |
498 |
} |
|
499 |
if (bundleTypes.contains(Bundle.Type.CURRENCYNAMES)) { |
|
500 |
Map<String, Object> currencyNamesMap = extractCurrencyNames(targetMap, bundle.getID(), bundle.getCurrencies()); |
|
501 |
if (!currencyNamesMap.isEmpty() || bundle.isRoot()) { |
|
32030
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
31263
diff
changeset
|
502 |
bundleGenerator.generateBundle("util", "CurrencyNames", bundle.getJavaID(), true, currencyNamesMap, BundleType.OPEN); |
13583 | 503 |
} |
504 |
} |
|
505 |
if (bundleTypes.contains(Bundle.Type.TIMEZONENAMES)) { |
|
506 |
Map<String, Object> zoneNamesMap = extractZoneNames(targetMap, bundle.getID()); |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
507 |
if (!zoneNamesMap.isEmpty() || bundle.isRoot()) { |
32030
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
31263
diff
changeset
|
508 |
bundleGenerator.generateBundle("util", "TimeZoneNames", bundle.getJavaID(), true, zoneNamesMap, BundleType.TIMEZONE); |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
509 |
} |
13583 | 510 |
} |
511 |
if (bundleTypes.contains(Bundle.Type.CALENDARDATA)) { |
|
512 |
Map<String, Object> calendarDataMap = extractCalendarData(targetMap, bundle.getID()); |
|
513 |
if (!calendarDataMap.isEmpty() || bundle.isRoot()) { |
|
32030
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
31263
diff
changeset
|
514 |
bundleGenerator.generateBundle("util", "CalendarData", bundle.getJavaID(), true, calendarDataMap, BundleType.PLAIN); |
13583 | 515 |
} |
516 |
} |
|
517 |
if (bundleTypes.contains(Bundle.Type.FORMATDATA)) { |
|
518 |
Map<String, Object> formatDataMap = extractFormatData(targetMap, bundle.getID()); |
|
519 |
if (!formatDataMap.isEmpty() || bundle.isRoot()) { |
|
32030
f2c22ba89d0f
8132494: Wrong CLDR resource bundle names for legacy ISO language codes
naoto
parents:
31263
diff
changeset
|
520 |
bundleGenerator.generateBundle("text", "FormatData", bundle.getJavaID(), true, formatDataMap, BundleType.PLAIN); |
13583 | 521 |
} |
522 |
} |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
523 |
|
31263 | 524 |
// For AvailableLocales |
525 |
metaInfo.get("AvailableLocales").add(toLanguageTag(bundle.getID())); |
|
38747 | 526 |
addLikelySubtags(metaInfo, "AvailableLocales", bundle.getID()); |
13583 | 527 |
} |
528 |
bundleGenerator.generateMetaInfo(metaInfo); |
|
529 |
} |
|
530 |
||
31263 | 531 |
static final Map<String, String> aliases = new HashMap<>(); |
532 |
||
533 |
/** |
|
534 |
* Translate the aliases into the real entries in the bundle map. |
|
535 |
*/ |
|
536 |
static void handleAliases(Map<String, Object> bundleMap) { |
|
537 |
Set bundleKeys = bundleMap.keySet(); |
|
538 |
try { |
|
539 |
for (String key : aliases.keySet()) { |
|
540 |
String targetKey = aliases.get(key); |
|
541 |
if (bundleKeys.contains(targetKey)) { |
|
542 |
bundleMap.putIfAbsent(key, bundleMap.get(targetKey)); |
|
543 |
} |
|
544 |
} |
|
545 |
} catch (Exception ex) { |
|
546 |
Logger.getLogger(CLDRConverter.class.getName()).log(Level.SEVERE, null, ex); |
|
547 |
} |
|
548 |
} |
|
549 |
||
13583 | 550 |
/* |
551 |
* Returns the language portion of the given id. |
|
552 |
* If id is "root", "" is returned. |
|
553 |
*/ |
|
554 |
static String getLanguageCode(String id) { |
|
31263 | 555 |
return "root".equals(id) ? "" : Locale.forLanguageTag(id.replaceAll("_", "-")).getLanguage(); |
13583 | 556 |
} |
557 |
||
558 |
/** |
|
559 |
* Examine if the id includes the country (territory) code. If it does, it returns |
|
560 |
* the country code. |
|
561 |
* Otherwise, it returns null. eg. when the id is "zh_Hans_SG", it return "SG". |
|
36014
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
562 |
* It does NOT return UN M.49 code, e.g., '001', as those three digit numbers cannot |
31263 | 563 |
* be translated into package names. |
13583 | 564 |
*/ |
31263 | 565 |
static String getCountryCode(String id) { |
36014
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
566 |
String rgn = getRegionCode(id); |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
567 |
return rgn.length() == 2 ? rgn: null; |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
568 |
} |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
569 |
|
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
570 |
/** |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
571 |
* Examine if the id includes the region code. If it does, it returns |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
572 |
* the region code. |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
573 |
* Otherwise, it returns null. eg. when the id is "zh_Hans_SG", it return "SG". |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
574 |
* It DOES return UN M.49 code, e.g., '001', as well as ISO 3166 two letter country codes. |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
575 |
*/ |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
576 |
static String getRegionCode(String id) { |
3d50784f2dc2
8148346: Reduce number of packages in jdk.localedata module
naoto
parents:
32510
diff
changeset
|
577 |
return Locale.forLanguageTag(id.replaceAll("_", "-")).getCountry(); |
13583 | 578 |
} |
579 |
||
580 |
private static class KeyComparator implements Comparator<String> { |
|
581 |
static KeyComparator INSTANCE = new KeyComparator(); |
|
582 |
||
583 |
private KeyComparator() { |
|
584 |
} |
|
585 |
||
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
586 |
@Override |
13583 | 587 |
public int compare(String o1, String o2) { |
588 |
int len1 = o1.length(); |
|
589 |
int len2 = o2.length(); |
|
590 |
if (!isDigit(o1.charAt(0)) && !isDigit(o2.charAt(0))) { |
|
591 |
// Shorter string comes first unless either starts with a digit. |
|
592 |
if (len1 < len2) { |
|
593 |
return -1; |
|
594 |
} |
|
595 |
if (len1 > len2) { |
|
596 |
return 1; |
|
597 |
} |
|
598 |
} |
|
599 |
return o1.compareTo(o2); |
|
600 |
} |
|
601 |
||
602 |
private boolean isDigit(char c) { |
|
603 |
return c >= '0' && c <= '9'; |
|
604 |
} |
|
605 |
} |
|
606 |
||
607 |
private static Map<String, Object> extractLocaleNames(Map<String, Object> map, String id) { |
|
608 |
Map<String, Object> localeNames = new TreeMap<>(KeyComparator.INSTANCE); |
|
609 |
for (String key : map.keySet()) { |
|
610 |
if (key.startsWith(LOCALE_NAME_PREFIX)) { |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
611 |
switch (key) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
612 |
case LOCALE_SEPARATOR: |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
613 |
localeNames.put("ListCompositionPattern", map.get(key)); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
614 |
break; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
615 |
case LOCALE_KEYTYPE: |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
616 |
localeNames.put("ListKeyTypePattern", map.get(key)); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
617 |
break; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
618 |
default: |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
619 |
localeNames.put(key.substring(LOCALE_NAME_PREFIX.length()), map.get(key)); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
620 |
break; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
621 |
} |
13583 | 622 |
} |
623 |
} |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
624 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
625 |
if (id.equals("root")) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
626 |
// Add display name pattern, which is not in CLDR |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
627 |
localeNames.put("DisplayNamePattern", "{0,choice,0#|1#{1}|2#{1} ({2})}"); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
628 |
} |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
629 |
|
13583 | 630 |
return localeNames; |
631 |
} |
|
632 |
||
633 |
@SuppressWarnings("AssignmentToForLoopParameter") |
|
634 |
private static Map<String, Object> extractCurrencyNames(Map<String, Object> map, String id, String names) |
|
635 |
throws Exception { |
|
636 |
Map<String, Object> currencyNames = new TreeMap<>(KeyComparator.INSTANCE); |
|
637 |
for (String key : map.keySet()) { |
|
638 |
if (key.startsWith(CURRENCY_NAME_PREFIX)) { |
|
639 |
currencyNames.put(key.substring(CURRENCY_NAME_PREFIX.length()), map.get(key)); |
|
640 |
} else if (key.startsWith(CURRENCY_SYMBOL_PREFIX)) { |
|
641 |
currencyNames.put(key.substring(CURRENCY_SYMBOL_PREFIX.length()), map.get(key)); |
|
642 |
} |
|
643 |
} |
|
644 |
return currencyNames; |
|
645 |
} |
|
646 |
||
647 |
private static Map<String, Object> extractZoneNames(Map<String, Object> map, String id) { |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
648 |
Map<String, Object> names = new HashMap<>(); |
32510
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
649 |
|
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
650 |
// Copy over missing time zone ids from JRE for English locale |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
651 |
if (id.equals("en")) { |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
652 |
Map<String[], String> jreMetaMap = new HashMap<>(); |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
653 |
jreTimeZoneNames.stream().forEach(e -> { |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
654 |
String tzid = (String)e[0]; |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
655 |
String[] data = (String[])e[1]; |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
656 |
|
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
657 |
if (map.get(TIMEZONE_ID_PREFIX + tzid) == null && |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
36014
diff
changeset
|
658 |
handlerMetaZones.get(tzid) == null || |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
36014
diff
changeset
|
659 |
handlerMetaZones.get(tzid) != null && |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
36014
diff
changeset
|
660 |
map.get(METAZONE_ID_PREFIX + handlerMetaZones.get(tzid)) == null) { |
32510
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
661 |
// First, check the CLDR meta key |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
662 |
Optional<Map.Entry<String, String>> cldrMeta = |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
663 |
handlerMetaZones.getData().entrySet().stream() |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
664 |
.filter(me -> |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
665 |
Arrays.deepEquals(data, |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
666 |
(String[])map.get(METAZONE_ID_PREFIX + me.getValue()))) |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
667 |
.findAny(); |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
668 |
cldrMeta.ifPresentOrElse(meta -> names.put(tzid, meta.getValue()), () -> { |
32510
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
669 |
// check the JRE meta key, add if there is not. |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
670 |
Optional<Map.Entry<String[], String>> jreMeta = |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
671 |
jreMetaMap.entrySet().stream() |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
672 |
.filter(jm -> Arrays.deepEquals(data, jm.getKey())) |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
673 |
.findAny(); |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
674 |
jreMeta.ifPresentOrElse(meta -> names.put(tzid, meta.getValue()), () -> { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
675 |
String metaName = "JRE_" + tzid.replaceAll("[/-]", "_"); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
676 |
names.put(METAZONE_ID_PREFIX + metaName, data); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
677 |
names.put(tzid, metaName); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
678 |
}); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
679 |
}); |
32510
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
680 |
} |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
681 |
}); |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
682 |
} |
7530a468314c
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
naoto
parents:
32030
diff
changeset
|
683 |
|
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
684 |
Arrays.stream(AVAILABLE_TZIDS).forEach(tzid -> { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
685 |
// If the tzid is deprecated, get the data for the replacement id |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
686 |
String tzKey = Optional.ofNullable((String)handlerSupplMeta.get(tzid)) |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
687 |
.orElse(tzid); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
688 |
Object data = map.get(TIMEZONE_ID_PREFIX + tzKey); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
689 |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
690 |
if (data instanceof String[]) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
691 |
names.put(tzid, data); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
692 |
} else { |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
693 |
String meta = handlerMetaZones.get(tzKey); |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
694 |
if (meta != null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
695 |
String metaKey = METAZONE_ID_PREFIX + meta; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
696 |
data = map.get(metaKey); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
697 |
if (data instanceof String[]) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
698 |
// Keep the metazone prefix here. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
699 |
names.put(metaKey, data); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
700 |
names.put(tzid, meta); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
701 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
702 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
703 |
} |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
704 |
}); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
705 |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
706 |
// exemplar cities. |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
707 |
Map<String, Object> exCities = map.entrySet().stream() |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
708 |
.filter(e -> e.getKey().startsWith(CLDRConverter.EXEMPLAR_CITY_PREFIX)) |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
709 |
.collect(Collectors |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
710 |
.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
711 |
names.putAll(exCities); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
712 |
|
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
713 |
if (!id.equals("en") && |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
714 |
!names.isEmpty()) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
715 |
// CLDR does not have UTC entry, so add it here. |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
716 |
names.put("UTC", EMPTY_ZONE); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
717 |
|
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
718 |
// no metazone zones |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
719 |
Arrays.asList(handlerMetaZones.get(MetaZonesParseHandler.NO_METAZONE_KEY) |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
720 |
.split("\\s")).stream() |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
721 |
.forEach(tz -> { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
722 |
names.put(tz, EMPTY_ZONE); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
723 |
}); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
724 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
725 |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
726 |
return names; |
13583 | 727 |
} |
728 |
||
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
729 |
/** |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
730 |
* Extracts the language independent calendar data. Each of the two keys, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
731 |
* "firstDayOfWeek" and "minimalDaysInFirstWeek" has a string value consists of |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
732 |
* one or multiple occurrences of: |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
733 |
* i: rg1 rg2 ... rgn; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
734 |
* where "i" is the data for the following regions (delimited by a space) after |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
735 |
* ":", and ends with a ";". |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
736 |
*/ |
13583 | 737 |
private static Map<String, Object> extractCalendarData(Map<String, Object> map, String id) { |
738 |
Map<String, Object> calendarData = new LinkedHashMap<>(); |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
739 |
if (id.equals("root")) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
740 |
calendarData.put("firstDayOfWeek", |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
741 |
IntStream.range(1, 8) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
742 |
.mapToObj(String::valueOf) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
743 |
.filter(d -> map.keySet().contains(CALENDAR_FIRSTDAY_PREFIX + d)) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
744 |
.map(d -> d + ": " + map.get(CALENDAR_FIRSTDAY_PREFIX + d)) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
745 |
.collect(Collectors.joining(";"))); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
746 |
calendarData.put("minimalDaysInFirstWeek", |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
747 |
IntStream.range(0, 7) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
748 |
.mapToObj(String::valueOf) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
749 |
.filter(d -> map.keySet().contains(CALENDAR_MINDAYS_PREFIX + d)) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
750 |
.map(d -> d + ": " + map.get(CALENDAR_MINDAYS_PREFIX + d)) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
751 |
.collect(Collectors.joining(";"))); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
752 |
} |
13583 | 753 |
return calendarData; |
754 |
} |
|
755 |
||
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
756 |
static final String[] FORMAT_DATA_ELEMENTS = { |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
757 |
"MonthNames", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
758 |
"standalone.MonthNames", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
759 |
"MonthAbbreviations", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
760 |
"standalone.MonthAbbreviations", |
16852 | 761 |
"MonthNarrows", |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
762 |
"standalone.MonthNarrows", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
763 |
"DayNames", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
764 |
"standalone.DayNames", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
765 |
"DayAbbreviations", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
766 |
"standalone.DayAbbreviations", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
767 |
"DayNarrows", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
768 |
"standalone.DayNarrows", |
16852 | 769 |
"QuarterNames", |
770 |
"standalone.QuarterNames", |
|
771 |
"QuarterAbbreviations", |
|
772 |
"standalone.QuarterAbbreviations", |
|
773 |
"QuarterNarrows", |
|
774 |
"standalone.QuarterNarrows", |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
775 |
"AmPmMarkers", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
776 |
"narrow.AmPmMarkers", |
38747 | 777 |
"abbreviated.AmPmMarkers", |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
778 |
"long.Eras", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
779 |
"Eras", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
780 |
"narrow.Eras", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
781 |
"field.era", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
782 |
"field.year", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
783 |
"field.month", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
784 |
"field.week", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
785 |
"field.weekday", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
786 |
"field.dayperiod", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
787 |
"field.hour", |
39644 | 788 |
"timezone.hourFormat", |
789 |
"timezone.gmtFormat", |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
790 |
"timezone.gmtZeroFormat", |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
791 |
"timezone.regionFormat", |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
792 |
"timezone.regionFormat.daylight", |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
49699
diff
changeset
|
793 |
"timezone.regionFormat.standard", |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
794 |
"field.minute", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
795 |
"field.second", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
796 |
"field.zone", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
797 |
"TimePatterns", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
798 |
"DatePatterns", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
799 |
"DateTimePatterns", |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
800 |
"DateTimePatternChars" |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
801 |
}; |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
802 |
|
13583 | 803 |
private static Map<String, Object> extractFormatData(Map<String, Object> map, String id) { |
804 |
Map<String, Object> formatData = new LinkedHashMap<>(); |
|
805 |
for (CalendarType calendarType : CalendarType.values()) { |
|
31263 | 806 |
if (calendarType == CalendarType.GENERIC) { |
807 |
continue; |
|
808 |
} |
|
13583 | 809 |
String prefix = calendarType.keyElementName(); |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
810 |
for (String element : FORMAT_DATA_ELEMENTS) { |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
811 |
String key = prefix + element; |
16852 | 812 |
copyIfPresent(map, "java.time." + key, formatData); |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
813 |
copyIfPresent(map, key, formatData); |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
814 |
} |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
815 |
} |
31263 | 816 |
|
817 |
for (String key : map.keySet()) { |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
818 |
// Copy available calendar names |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
819 |
if (key.startsWith(CLDRConverter.LOCALE_TYPE_PREFIX_CA)) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
820 |
String type = key.substring(CLDRConverter.LOCALE_TYPE_PREFIX_CA.length()); |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
821 |
for (CalendarType calendarType : CalendarType.values()) { |
31263 | 822 |
if (calendarType == CalendarType.GENERIC) { |
823 |
continue; |
|
824 |
} |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
825 |
if (type.equals(calendarType.lname())) { |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
826 |
Object value = map.get(key); |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
827 |
String dataKey = key.replace(LOCALE_TYPE_PREFIX_CA, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
828 |
CALENDAR_NAME_PREFIX); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
829 |
formatData.put(dataKey, value); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
830 |
String ukey = CALENDAR_NAME_PREFIX + calendarType.uname(); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
831 |
if (!dataKey.equals(ukey)) { |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
832 |
formatData.put(ukey, value); |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
833 |
} |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
834 |
} |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
835 |
} |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
836 |
} |
13583 | 837 |
} |
838 |
||
839 |
copyIfPresent(map, "DefaultNumberingSystem", formatData); |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
840 |
|
13583 | 841 |
@SuppressWarnings("unchecked") |
842 |
List<String> numberingScripts = (List<String>) map.remove("numberingScripts"); |
|
843 |
if (numberingScripts != null) { |
|
844 |
for (String script : numberingScripts) { |
|
845 |
copyIfPresent(map, script + "." + "NumberElements", formatData); |
|
846 |
} |
|
847 |
} else { |
|
848 |
copyIfPresent(map, "NumberElements", formatData); |
|
849 |
} |
|
850 |
copyIfPresent(map, "NumberPatterns", formatData); |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
851 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
852 |
// put extra number elements for available scripts into formatData, if it is "root" |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
853 |
if (id.equals("root")) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
854 |
handlerNumbering.keySet().stream() |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
855 |
.filter(k -> !numberingScripts.contains(k)) |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
856 |
.forEach(k -> { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
857 |
String[] ne = (String[])map.get("latn.NumberElements"); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
858 |
String[] neNew = Arrays.copyOf(ne, ne.length); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
859 |
neNew[4] = handlerNumbering.get(k).substring(0, 1); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
860 |
formatData.put(k + ".NumberElements", neNew); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
861 |
}); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47473
diff
changeset
|
862 |
} |
13583 | 863 |
return formatData; |
864 |
} |
|
865 |
||
866 |
private static void copyIfPresent(Map<String, Object> src, String key, Map<String, Object> dest) { |
|
867 |
Object value = src.get(key); |
|
868 |
if (value != null) { |
|
869 |
dest.put(key, value); |
|
870 |
} |
|
871 |
} |
|
872 |
||
873 |
// --- code below here is adapted from java.util.Properties --- |
|
874 |
private static final String specialSaveCharsJava = "\""; |
|
875 |
private static final String specialSaveCharsProperties = "=: \t\r\n\f#!"; |
|
876 |
||
877 |
/* |
|
878 |
* Converts unicodes to encoded \uxxxx |
|
879 |
* and writes out any of the characters in specialSaveChars |
|
880 |
* with a preceding slash |
|
881 |
*/ |
|
882 |
static String saveConvert(String theString, boolean useJava) { |
|
883 |
if (theString == null) { |
|
884 |
return ""; |
|
885 |
} |
|
886 |
||
887 |
String specialSaveChars; |
|
888 |
if (useJava) { |
|
889 |
specialSaveChars = specialSaveCharsJava; |
|
890 |
} else { |
|
891 |
specialSaveChars = specialSaveCharsProperties; |
|
892 |
} |
|
893 |
boolean escapeSpace = false; |
|
894 |
||
895 |
int len = theString.length(); |
|
896 |
StringBuilder outBuffer = new StringBuilder(len * 2); |
|
897 |
Formatter formatter = new Formatter(outBuffer, Locale.ROOT); |
|
898 |
||
899 |
for (int x = 0; x < len; x++) { |
|
900 |
char aChar = theString.charAt(x); |
|
901 |
switch (aChar) { |
|
902 |
case ' ': |
|
903 |
if (x == 0 || escapeSpace) { |
|
904 |
outBuffer.append('\\'); |
|
905 |
} |
|
906 |
outBuffer.append(' '); |
|
907 |
break; |
|
908 |
case '\\': |
|
909 |
outBuffer.append('\\'); |
|
910 |
outBuffer.append('\\'); |
|
911 |
break; |
|
912 |
case '\t': |
|
913 |
outBuffer.append('\\'); |
|
914 |
outBuffer.append('t'); |
|
915 |
break; |
|
916 |
case '\n': |
|
917 |
outBuffer.append('\\'); |
|
918 |
outBuffer.append('n'); |
|
919 |
break; |
|
920 |
case '\r': |
|
921 |
outBuffer.append('\\'); |
|
922 |
outBuffer.append('r'); |
|
923 |
break; |
|
924 |
case '\f': |
|
925 |
outBuffer.append('\\'); |
|
926 |
outBuffer.append('f'); |
|
927 |
break; |
|
928 |
default: |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
929 |
if (aChar < 0x0020 || (!USE_UTF8 && aChar > 0x007e)) { |
13583 | 930 |
formatter.format("\\u%04x", (int)aChar); |
931 |
} else { |
|
932 |
if (specialSaveChars.indexOf(aChar) != -1) { |
|
933 |
outBuffer.append('\\'); |
|
934 |
} |
|
935 |
outBuffer.append(aChar); |
|
936 |
} |
|
937 |
} |
|
938 |
} |
|
939 |
return outBuffer.toString(); |
|
940 |
} |
|
941 |
||
942 |
private static String toLanguageTag(String locName) { |
|
943 |
if (locName.indexOf('_') == -1) { |
|
944 |
return locName; |
|
945 |
} |
|
946 |
String tag = locName.replaceAll("_", "-"); |
|
947 |
Locale loc = Locale.forLanguageTag(tag); |
|
948 |
return loc.toLanguageTag(); |
|
949 |
} |
|
950 |
||
38747 | 951 |
private static void addLikelySubtags(Map<String, SortedSet<String>> metaInfo, String category, String id) { |
952 |
String likelySubtag = handlerLikelySubtags.get(id); |
|
953 |
if (likelySubtag != null) { |
|
954 |
// Remove Script for now |
|
955 |
metaInfo.get(category).add(toLanguageTag(likelySubtag).replaceFirst("-[A-Z][a-z]{3}", "")); |
|
956 |
} |
|
957 |
} |
|
958 |
||
13583 | 959 |
private static String toLocaleName(String tag) { |
960 |
if (tag.indexOf('-') == -1) { |
|
961 |
return tag; |
|
962 |
} |
|
963 |
return tag.replaceAll("-", "_"); |
|
964 |
} |
|
31263 | 965 |
|
966 |
private static void setupBaseLocales(String localeList) { |
|
967 |
Arrays.stream(localeList.split(",")) |
|
968 |
.map(Locale::forLanguageTag) |
|
969 |
.map(l -> Control.getControl(Control.FORMAT_DEFAULT) |
|
970 |
.getCandidateLocales("", l)) |
|
971 |
.forEach(BASE_LOCALES::addAll); |
|
38747 | 972 |
} |
31263 | 973 |
|
974 |
// applying parent locale rules to the passed candidates list |
|
975 |
// This has to match with the one in sun.util.cldr.CLDRLocaleProviderAdapter |
|
976 |
private static Map<Locale, Locale> childToParentLocaleMap = null; |
|
977 |
private static List<Locale> applyParentLocales(String baseName, List<Locale> candidates) { |
|
978 |
if (Objects.isNull(childToParentLocaleMap)) { |
|
979 |
childToParentLocaleMap = new HashMap<>(); |
|
980 |
parentLocalesMap.keySet().forEach(key -> { |
|
981 |
String parent = key.substring(PARENT_LOCALE_PREFIX.length()).replaceAll("_", "-"); |
|
982 |
parentLocalesMap.get(key).stream().forEach(child -> { |
|
983 |
childToParentLocaleMap.put(Locale.forLanguageTag(child), |
|
984 |
"root".equals(parent) ? Locale.ROOT : Locale.forLanguageTag(parent)); |
|
985 |
}); |
|
986 |
}); |
|
987 |
} |
|
988 |
||
989 |
// check irregular parents |
|
990 |
for (int i = 0; i < candidates.size(); i++) { |
|
991 |
Locale l = candidates.get(i); |
|
992 |
Locale p = childToParentLocaleMap.get(l); |
|
993 |
if (!l.equals(Locale.ROOT) && |
|
994 |
Objects.nonNull(p) && |
|
995 |
!candidates.get(i+1).equals(p)) { |
|
996 |
List<Locale> applied = candidates.subList(0, i+1); |
|
997 |
applied.addAll(applyParentLocales(baseName, defCon.getCandidateLocales(baseName, p))); |
|
998 |
return applied; |
|
999 |
} |
|
1000 |
} |
|
1001 |
||
1002 |
return candidates; |
|
1003 |
} |
|
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1004 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1005 |
private static void generateZoneName() throws Exception { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1006 |
Files.createDirectories(Paths.get(DESTINATION_DIR, "java", "time", "format")); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1007 |
Files.write(Paths.get(DESTINATION_DIR, "java", "time", "format", "ZoneName.java"), |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1008 |
Files.lines(Paths.get(zoneNameTempFile)) |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1009 |
.flatMap(l -> { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1010 |
if (l.equals("%%%%ZIDMAP%%%%")) { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1011 |
return zidMapEntry(); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1012 |
} else if (l.equals("%%%%MZONEMAP%%%%")) { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1013 |
return handlerMetaZones.mzoneMapEntry(); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1014 |
} else if (l.equals("%%%%DEPRECATED%%%%")) { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1015 |
return handlerSupplMeta.deprecatedMap(); |
49699
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1016 |
} else if (l.equals("%%%%TZDATALINK%%%%")) { |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1017 |
return tzDataLinkEntry(); |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1018 |
} else { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1019 |
return Stream.of(l); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1020 |
} |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1021 |
}) |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1022 |
.collect(Collectors.toList()), |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1023 |
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1024 |
} |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1025 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1026 |
private static Stream<String> zidMapEntry() { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1027 |
Map<String, String> canonMap = new HashMap<>(); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1028 |
handlerTimeZone.getData().entrySet().stream() |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1029 |
.forEach(e -> { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1030 |
String[] ids = ((String)e.getValue()).split("\\s"); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1031 |
for (int i = 1; i < ids.length; i++) { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1032 |
canonMap.put(ids[i], ids[0]); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1033 |
}}); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1034 |
return ZoneId.getAvailableZoneIds().stream() |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1035 |
.map(id -> { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1036 |
String canonId = canonMap.getOrDefault(id, id); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1037 |
String meta = handlerMetaZones.get(canonId); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1038 |
String zone001 = handlerMetaZones.zidMap().get(meta); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1039 |
return zone001 == null ? "" : |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1040 |
String.format(" \"%s\", \"%s\", \"%s\",", |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1041 |
id, meta, zone001); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1042 |
}) |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1043 |
.filter(s -> !s.isEmpty()) |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1044 |
.sorted(); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
48251
diff
changeset
|
1045 |
} |
49699
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1046 |
|
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1047 |
private static Stream<String> tzDataLinkEntry() { |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1048 |
try { |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1049 |
return Files.walk(Paths.get(tzDataDir), 1) |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1050 |
.filter(p -> !Files.isDirectory(p)) |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1051 |
.flatMap(CLDRConverter::extractLinks) |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1052 |
.sorted(); |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1053 |
} catch (IOException e) { |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1054 |
throw new UncheckedIOException(e); |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1055 |
} |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1056 |
} |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1057 |
|
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1058 |
private static Stream<String> extractLinks(Path tzFile) { |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1059 |
try { |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1060 |
return Files.lines(tzFile) |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1061 |
.filter(l -> l.startsWith("Link")) |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1062 |
.map(l -> l.replaceFirst("^Link[\\s]+(\\S+)\\s+(\\S+).*", |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1063 |
" \"$2\", \"$1\",")); |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1064 |
} catch (IOException e) { |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1065 |
throw new UncheckedIOException(e); |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1066 |
} |
5c2cddff67b6
8201507: Generate alias entries in j.t.f.ZoneName from tzdb at build time
naoto
parents:
49574
diff
changeset
|
1067 |
} |
31263 | 1068 |
} |