author | pliden |
Tue, 18 Sep 2018 22:46:35 +0200 | |
changeset 51794 | 4129f43607cb |
parent 49918 | 8b9c78f0a712 |
permissions | -rw-r--r-- |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
1 |
/* |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
4 |
* |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
10 |
* |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
15 |
* accompanied this code). |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
16 |
* |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
20 |
* |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
23 |
* questions. |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
24 |
*/ |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
25 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
26 |
package build.tools.cldrconverter; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
27 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
28 |
import java.io.File; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
29 |
import java.io.IOException; |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
30 |
import java.util.HashMap; |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
31 |
import java.util.Map; |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
32 |
import java.util.stream.Stream; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
33 |
import org.xml.sax.Attributes; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
34 |
import org.xml.sax.InputSource; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
35 |
import org.xml.sax.SAXException; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
36 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
37 |
/** |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
38 |
* Handles parsing of files in Locale Data Markup Language for |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
39 |
* SupplementalMetadata.xml |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
40 |
*/ |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
41 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
42 |
class SupplementalMetadataParseHandler extends AbstractLDMLHandler<Object> { |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
43 |
private final Map<String, String> languageAliasMap; |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
44 |
|
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
45 |
SupplementalMetadataParseHandler() { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
46 |
languageAliasMap = new HashMap<>(); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
47 |
} |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
48 |
|
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
49 |
@Override |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
50 |
public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
51 |
// avoid HTTP traffic to unicode.org |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
52 |
if (systemID.startsWith(CLDRConverter.SPPL_LDML_DTD_SYSTEM_ID)) { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
53 |
return new InputSource((new File(CLDRConverter.LOCAL_SPPL_LDML_DTD)).toURI().toString()); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
54 |
} |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
55 |
return null; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
56 |
} |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
57 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
58 |
@Override |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
59 |
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
60 |
switch (qName) { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
61 |
case "zoneAlias": |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
62 |
String reason = attributes.getValue("reason"); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
63 |
if ("deprecated".equals(reason)) { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
64 |
put(attributes.getValue("type"), attributes.getValue("replacement")); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
65 |
} |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
66 |
pushIgnoredContainer(qName); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
67 |
break; |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
68 |
case "languageAlias": |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
69 |
String aliasReason = attributes.getValue("reason"); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
70 |
if ("deprecated".equals(aliasReason) || "legacy".equals(aliasReason)) { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
71 |
String tag = attributes.getValue("type"); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
72 |
if (!checkLegacyLocales(tag)) { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
73 |
languageAliasMap.put(tag.replaceAll("_", "-"), |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
74 |
attributes.getValue("replacement").replaceAll("_", "-")); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
75 |
} |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
76 |
} |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
77 |
pushIgnoredContainer(qName); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
78 |
break; |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
79 |
default: |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
80 |
// treat anything else as a container |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
81 |
pushContainer(qName, attributes); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
82 |
break; |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
83 |
} |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
84 |
} |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
85 |
|
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
86 |
public Stream<String> deprecatedMap() { |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
87 |
return keySet().stream() |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
88 |
.map(k -> String.format(" \"%s\", \"%s\",", k, get(k))) |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
89 |
.sorted(); |
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
90 |
} |
49918
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
91 |
Map<String, String> getLanguageAliasData() { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
92 |
return languageAliasMap; |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
93 |
} |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
94 |
|
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
95 |
// skip language aliases for JDK legacy locales for ISO compatibility |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
96 |
private boolean checkLegacyLocales(String tag) { |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
97 |
return (tag.startsWith("no") || tag.startsWith("in") |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
98 |
|| tag.startsWith("iw") || tag.startsWith("ji")); |
8b9c78f0a712
8179071: Month value is inconsistent between CLDR and Java in some locales
rgoel
parents:
49574
diff
changeset
|
99 |
} |
49574
6a6ee36037ac
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff
changeset
|
100 |
} |