author | pliden |
Tue, 18 Sep 2018 22:46:35 +0200 | |
changeset 51794 | 4129f43607cb |
parent 49904 | cadca99d52e7 |
child 52869 | c5c0db0b7c2f |
permissions | -rw-r--r-- |
13583 | 1 |
/* |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
13583 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package build.tools.cldrconverter; |
|
27 |
||
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
32015 | 30 |
import java.text.DateFormatSymbols; |
13583 | 31 |
import java.util.ArrayList; |
32 |
import java.util.HashMap; |
|
31263 | 33 |
import java.util.HashSet; |
13583 | 34 |
import java.util.List; |
35 |
import java.util.Locale; |
|
36 |
import java.util.Map; |
|
31263 | 37 |
import java.util.Set; |
13583 | 38 |
import org.xml.sax.Attributes; |
39 |
import org.xml.sax.InputSource; |
|
40 |
import org.xml.sax.SAXException; |
|
41 |
||
42 |
/** |
|
43 |
* Handles parsing of files in Locale Data Markup Language and produces a map |
|
44 |
* that uses the keys and values of JRE locale data. |
|
45 |
*/ |
|
46 |
class LDMLParseHandler extends AbstractLDMLHandler<Object> { |
|
47 |
private String defaultNumberingSystem; |
|
48 |
private String currentNumberingSystem = ""; |
|
49 |
private CalendarType currentCalendarType; |
|
50 |
private String zoneNameStyle; // "long" or "short" for time zone names |
|
51 |
private String zonePrefix; |
|
52 |
private final String id; |
|
31263 | 53 |
private String currentContext = ""; // "format"/"stand-alone" |
54 |
private String currentWidth = ""; // "wide"/"narrow"/"abbreviated" |
|
13583 | 55 |
|
56 |
LDMLParseHandler(String id) { |
|
57 |
this.id = id; |
|
58 |
} |
|
59 |
||
60 |
@Override |
|
61 |
public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException { |
|
62 |
// avoid HTTP traffic to unicode.org |
|
63 |
if (systemID.startsWith(CLDRConverter.LDML_DTD_SYSTEM_ID)) { |
|
64 |
return new InputSource((new File(CLDRConverter.LOCAL_LDML_DTD)).toURI().toString()); |
|
65 |
} |
|
66 |
return null; |
|
67 |
} |
|
68 |
||
69 |
@Override |
|
70 |
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { |
|
71 |
switch (qName) { |
|
72 |
// |
|
73 |
// Generic information |
|
74 |
// |
|
75 |
case "identity": |
|
76 |
// ignore this element - it has language and territory elements that aren't locale data |
|
77 |
pushIgnoredContainer(qName); |
|
78 |
break; |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
79 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
80 |
// for LocaleNames |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
81 |
// copy string |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
82 |
case "localeSeparator": |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
83 |
pushStringEntry(qName, attributes, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
84 |
CLDRConverter.LOCALE_SEPARATOR); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
85 |
break; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
86 |
case "localeKeyTypePattern": |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
87 |
pushStringEntry(qName, attributes, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
88 |
CLDRConverter.LOCALE_KEYTYPE); |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
89 |
break; |
31263 | 90 |
|
13583 | 91 |
case "language": |
31263 | 92 |
case "script": |
93 |
case "territory": |
|
94 |
case "variant": |
|
13583 | 95 |
// for LocaleNames |
96 |
// copy string |
|
31263 | 97 |
pushStringEntry(qName, attributes, |
98 |
CLDRConverter.LOCALE_NAME_PREFIX + |
|
99 |
(qName.equals("variant") ? "%%" : "") + |
|
100 |
attributes.getValue("type")); |
|
13583 | 101 |
break; |
102 |
||
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
103 |
case "key": |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
104 |
// for LocaleNames |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
105 |
// copy string |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
106 |
{ |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
107 |
String key = convertOldKeyName(attributes.getValue("type")); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
108 |
if (key.length() == 2) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
109 |
pushStringEntry(qName, attributes, |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
110 |
CLDRConverter.LOCALE_KEY_PREFIX + key); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
111 |
} else { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
112 |
pushIgnoredContainer(qName); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
113 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
114 |
} |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
115 |
break; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
116 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
117 |
case "type": |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
118 |
// for LocaleNames/CalendarNames |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
119 |
// copy string |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
120 |
{ |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
121 |
String key = convertOldKeyName(attributes.getValue("key")); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
122 |
if (key.length() == 2) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
123 |
pushStringEntry(qName, attributes, |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
124 |
CLDRConverter.LOCALE_TYPE_PREFIX + key + "." + |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
125 |
attributes.getValue("type")); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
126 |
} else { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
127 |
pushIgnoredContainer(qName); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
128 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
129 |
} |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
130 |
break; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
131 |
|
13583 | 132 |
// |
133 |
// Currency information |
|
134 |
// |
|
135 |
case "currency": |
|
136 |
// for CurrencyNames |
|
137 |
// stash away "type" value for nested <symbol> |
|
138 |
pushKeyContainer(qName, attributes, attributes.getValue("type")); |
|
139 |
break; |
|
140 |
case "symbol": |
|
141 |
// for CurrencyNames |
|
142 |
// need to get the key from the containing <currency> element |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
143 |
pushStringEntry(qName, attributes, CLDRConverter.CURRENCY_SYMBOL_PREFIX |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
144 |
+ getContainerKey()); |
13583 | 145 |
break; |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
146 |
|
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
147 |
// Calendar or currency |
13583 | 148 |
case "displayName": |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
149 |
{ |
31263 | 150 |
if (currentContainer.getqName().equals("field")) { |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
151 |
pushStringEntry(qName, attributes, |
31263 | 152 |
(currentCalendarType != null ? currentCalendarType.keyElementName() : "") |
153 |
+ "field." + getContainerKey()); |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
154 |
} else { |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
155 |
// for CurrencyNames |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
156 |
// need to get the key from the containing <currency> element |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
157 |
// ignore if is has "count" attribute |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
158 |
String containerKey = getContainerKey(); |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
159 |
if (containerKey != null && attributes.getValue("count") == null) { |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
160 |
pushStringEntry(qName, attributes, |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
161 |
CLDRConverter.CURRENCY_NAME_PREFIX |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
162 |
+ containerKey.toLowerCase(Locale.ROOT), |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
163 |
attributes.getValue("type")); |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
164 |
} else { |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
165 |
pushIgnoredContainer(qName); |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
166 |
} |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
167 |
} |
13583 | 168 |
} |
169 |
break; |
|
170 |
||
171 |
// |
|
172 |
// Calendar information |
|
173 |
// |
|
174 |
case "calendar": |
|
175 |
{ |
|
176 |
// mostly for FormatData (CalendarData items firstDay and minDays are also nested) |
|
177 |
// use only if it's supported by java.util.Calendar. |
|
178 |
String calendarName = attributes.getValue("type"); |
|
179 |
currentCalendarType = CalendarType.forName(calendarName); |
|
180 |
if (currentCalendarType != null) { |
|
181 |
pushContainer(qName, attributes); |
|
182 |
} else { |
|
183 |
pushIgnoredContainer(qName); |
|
184 |
} |
|
185 |
} |
|
186 |
break; |
|
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
187 |
case "fields": |
31263 | 188 |
{ |
15281
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
189 |
pushContainer(qName, attributes); |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
190 |
} |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
191 |
break; |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
192 |
case "field": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
193 |
{ |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
194 |
String type = attributes.getValue("type"); |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
195 |
switch (type) { |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
196 |
case "era": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
197 |
case "year": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
198 |
case "month": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
199 |
case "week": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
200 |
case "weekday": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
201 |
case "dayperiod": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
202 |
case "hour": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
203 |
case "minute": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
204 |
case "second": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
205 |
case "zone": |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
206 |
pushKeyContainer(qName, attributes, type); |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
207 |
break; |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
208 |
default: |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
209 |
pushIgnoredContainer(qName); |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
210 |
break; |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
211 |
} |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
212 |
} |
dd43cb9be0e1
8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents:
14765
diff
changeset
|
213 |
break; |
13583 | 214 |
case "monthContext": |
215 |
{ |
|
216 |
// for FormatData |
|
217 |
// need to keep stand-alone and format, to allow for inheritance in CLDR |
|
218 |
String type = attributes.getValue("type"); |
|
219 |
if ("stand-alone".equals(type) || "format".equals(type)) { |
|
31263 | 220 |
currentContext = type; |
13583 | 221 |
pushKeyContainer(qName, attributes, type); |
222 |
} else { |
|
223 |
pushIgnoredContainer(qName); |
|
224 |
} |
|
225 |
} |
|
226 |
break; |
|
227 |
case "monthWidth": |
|
228 |
{ |
|
229 |
// for FormatData |
|
230 |
// create string array for the two types that the JRE knows |
|
231 |
// keep info about the context type so we can sort out inheritance later |
|
31263 | 232 |
if (currentCalendarType == null) { |
233 |
pushIgnoredContainer(qName); |
|
234 |
break; |
|
235 |
} |
|
13583 | 236 |
String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName(); |
31263 | 237 |
currentWidth = attributes.getValue("type"); |
238 |
switch (currentWidth) { |
|
13583 | 239 |
case "wide": |
240 |
pushStringArrayEntry(qName, attributes, prefix + "MonthNames/" + getContainerKey(), 13); |
|
241 |
break; |
|
242 |
case "abbreviated": |
|
243 |
pushStringArrayEntry(qName, attributes, prefix + "MonthAbbreviations/" + getContainerKey(), 13); |
|
244 |
break; |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
245 |
case "narrow": |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
246 |
pushStringArrayEntry(qName, attributes, prefix + "MonthNarrows/" + getContainerKey(), 13); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
247 |
break; |
13583 | 248 |
default: |
249 |
pushIgnoredContainer(qName); |
|
250 |
break; |
|
251 |
} |
|
252 |
} |
|
253 |
break; |
|
254 |
case "month": |
|
255 |
// for FormatData |
|
256 |
// add to string array entry of monthWidth element |
|
257 |
pushStringArrayElement(qName, attributes, Integer.parseInt(attributes.getValue("type")) - 1); |
|
258 |
break; |
|
259 |
case "dayContext": |
|
260 |
{ |
|
261 |
// for FormatData |
|
262 |
// need to keep stand-alone and format, to allow for multiple inheritance in CLDR |
|
263 |
String type = attributes.getValue("type"); |
|
264 |
if ("stand-alone".equals(type) || "format".equals(type)) { |
|
31263 | 265 |
currentContext = type; |
13583 | 266 |
pushKeyContainer(qName, attributes, type); |
267 |
} else { |
|
268 |
pushIgnoredContainer(qName); |
|
269 |
} |
|
270 |
} |
|
271 |
break; |
|
272 |
case "dayWidth": |
|
273 |
{ |
|
274 |
// for FormatData |
|
275 |
// create string array for the two types that the JRE knows |
|
276 |
// keep info about the context type so we can sort out inheritance later |
|
277 |
String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName(); |
|
31263 | 278 |
currentWidth = attributes.getValue("type"); |
279 |
switch (currentWidth) { |
|
13583 | 280 |
case "wide": |
281 |
pushStringArrayEntry(qName, attributes, prefix + "DayNames/" + getContainerKey(), 7); |
|
282 |
break; |
|
283 |
case "abbreviated": |
|
284 |
pushStringArrayEntry(qName, attributes, prefix + "DayAbbreviations/" + getContainerKey(), 7); |
|
285 |
break; |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
286 |
case "narrow": |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
287 |
pushStringArrayEntry(qName, attributes, prefix + "DayNarrows/" + getContainerKey(), 7); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
288 |
break; |
13583 | 289 |
default: |
290 |
pushIgnoredContainer(qName); |
|
291 |
break; |
|
292 |
} |
|
293 |
} |
|
294 |
break; |
|
295 |
case "day": |
|
296 |
// for FormatData |
|
297 |
// add to string array entry of monthWidth element |
|
298 |
pushStringArrayElement(qName, attributes, Integer.parseInt(DAY_OF_WEEK_MAP.get(attributes.getValue("type"))) - 1); |
|
299 |
break; |
|
300 |
case "dayPeriodContext": |
|
301 |
// for FormatData |
|
302 |
// need to keep stand-alone and format, to allow for multiple inheritance in CLDR |
|
303 |
// for FormatData |
|
304 |
// need to keep stand-alone and format, to allow for multiple inheritance in CLDR |
|
305 |
{ |
|
306 |
String type = attributes.getValue("type"); |
|
307 |
if ("stand-alone".equals(type) || "format".equals(type)) { |
|
31263 | 308 |
currentContext = type; |
13583 | 309 |
pushKeyContainer(qName, attributes, type); |
310 |
} else { |
|
311 |
pushIgnoredContainer(qName); |
|
312 |
} |
|
313 |
} |
|
314 |
break; |
|
315 |
case "dayPeriodWidth": |
|
316 |
// for FormatData |
|
317 |
// create string array entry for am/pm. only keeping wide |
|
31263 | 318 |
currentWidth = attributes.getValue("type"); |
319 |
switch (currentWidth) { |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
320 |
case "wide": |
13583 | 321 |
pushStringArrayEntry(qName, attributes, "AmPmMarkers/" + getContainerKey(), 2); |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
322 |
break; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
323 |
case "narrow": |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
324 |
pushStringArrayEntry(qName, attributes, "narrow.AmPmMarkers/" + getContainerKey(), 2); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
325 |
break; |
38747 | 326 |
case "abbreviated": |
327 |
pushStringArrayEntry(qName, attributes, "abbreviated.AmPmMarkers/" + getContainerKey(), 2); |
|
328 |
break; |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
329 |
default: |
13583 | 330 |
pushIgnoredContainer(qName); |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
331 |
break; |
13583 | 332 |
} |
333 |
break; |
|
334 |
case "dayPeriod": |
|
335 |
// for FormatData |
|
336 |
// add to string array entry of AmPmMarkers element |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
337 |
if (attributes.getValue("alt") == null) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
338 |
switch (attributes.getValue("type")) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
339 |
case "am": |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
340 |
pushStringArrayElement(qName, attributes, 0); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
341 |
break; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
342 |
case "pm": |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
343 |
pushStringArrayElement(qName, attributes, 1); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
344 |
break; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
345 |
default: |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
346 |
pushIgnoredContainer(qName); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
347 |
break; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
348 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
349 |
} else { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
350 |
// discard alt values |
13583 | 351 |
pushIgnoredContainer(qName); |
352 |
} |
|
353 |
break; |
|
354 |
case "eraNames": |
|
355 |
// CLDR era names are inconsistent in terms of their lengths. For example, |
|
356 |
// the full names of Japanese imperial eras are eraAbbr, while the full names |
|
357 |
// of the Julian eras are eraNames. |
|
358 |
if (currentCalendarType == null) { |
|
359 |
assert currentContainer instanceof IgnoredContainer; |
|
360 |
pushIgnoredContainer(qName); |
|
361 |
} else { |
|
362 |
String key = currentCalendarType.keyElementName() + "long.Eras"; // for now |
|
363 |
pushStringArrayEntry(qName, attributes, key, currentCalendarType.getEraLength(qName)); |
|
364 |
} |
|
365 |
break; |
|
366 |
case "eraAbbr": |
|
367 |
// for FormatData |
|
368 |
// create string array entry |
|
369 |
if (currentCalendarType == null) { |
|
370 |
assert currentContainer instanceof IgnoredContainer; |
|
371 |
pushIgnoredContainer(qName); |
|
372 |
} else { |
|
373 |
String key = currentCalendarType.keyElementName() + "Eras"; |
|
374 |
pushStringArrayEntry(qName, attributes, key, currentCalendarType.getEraLength(qName)); |
|
375 |
} |
|
376 |
break; |
|
377 |
case "eraNarrow": |
|
378 |
// mainly used for the Japanese imperial calendar |
|
379 |
if (currentCalendarType == null) { |
|
380 |
assert currentContainer instanceof IgnoredContainer; |
|
381 |
pushIgnoredContainer(qName); |
|
382 |
} else { |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
383 |
String key = currentCalendarType.keyElementName() + "narrow.Eras"; |
13583 | 384 |
pushStringArrayEntry(qName, attributes, key, currentCalendarType.getEraLength(qName)); |
385 |
} |
|
386 |
break; |
|
387 |
case "era": |
|
388 |
// for FormatData |
|
389 |
// add to string array entry of eraAbbr element |
|
390 |
if (currentCalendarType == null) { |
|
391 |
assert currentContainer instanceof IgnoredContainer; |
|
392 |
pushIgnoredContainer(qName); |
|
393 |
} else { |
|
394 |
int index = Integer.parseInt(attributes.getValue("type")); |
|
395 |
index = currentCalendarType.normalizeEraIndex(index); |
|
396 |
if (index >= 0) { |
|
397 |
pushStringArrayElement(qName, attributes, index); |
|
398 |
} else { |
|
399 |
pushIgnoredContainer(qName); |
|
400 |
} |
|
401 |
if (currentContainer.getParent() == null) { |
|
402 |
throw new InternalError("currentContainer: null parent"); |
|
403 |
} |
|
404 |
} |
|
405 |
break; |
|
16852 | 406 |
case "quarterContext": |
407 |
{ |
|
408 |
// for FormatData |
|
409 |
// need to keep stand-alone and format, to allow for inheritance in CLDR |
|
410 |
String type = attributes.getValue("type"); |
|
411 |
if ("stand-alone".equals(type) || "format".equals(type)) { |
|
31263 | 412 |
currentContext = type; |
16852 | 413 |
pushKeyContainer(qName, attributes, type); |
414 |
} else { |
|
415 |
pushIgnoredContainer(qName); |
|
416 |
} |
|
417 |
} |
|
418 |
break; |
|
419 |
case "quarterWidth": |
|
420 |
{ |
|
421 |
// for FormatData |
|
422 |
// keep info about the context type so we can sort out inheritance later |
|
423 |
String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName(); |
|
31263 | 424 |
currentWidth = attributes.getValue("type"); |
425 |
switch (currentWidth) { |
|
16852 | 426 |
case "wide": |
427 |
pushStringArrayEntry(qName, attributes, prefix + "QuarterNames/" + getContainerKey(), 4); |
|
428 |
break; |
|
429 |
case "abbreviated": |
|
430 |
pushStringArrayEntry(qName, attributes, prefix + "QuarterAbbreviations/" + getContainerKey(), 4); |
|
431 |
break; |
|
432 |
case "narrow": |
|
433 |
pushStringArrayEntry(qName, attributes, prefix + "QuarterNarrows/" + getContainerKey(), 4); |
|
434 |
break; |
|
435 |
default: |
|
436 |
pushIgnoredContainer(qName); |
|
437 |
break; |
|
438 |
} |
|
439 |
} |
|
440 |
break; |
|
441 |
case "quarter": |
|
442 |
// for FormatData |
|
443 |
// add to string array entry of quarterWidth element |
|
444 |
pushStringArrayElement(qName, attributes, Integer.parseInt(attributes.getValue("type")) - 1); |
|
445 |
break; |
|
13583 | 446 |
|
447 |
// |
|
448 |
// Time zone names |
|
449 |
// |
|
450 |
case "timeZoneNames": |
|
451 |
pushContainer(qName, attributes); |
|
452 |
break; |
|
39644 | 453 |
case "hourFormat": |
454 |
pushStringEntry(qName, attributes, "timezone.hourFormat"); |
|
455 |
break; |
|
456 |
case "gmtFormat": |
|
457 |
pushStringEntry(qName, attributes, "timezone.gmtFormat"); |
|
458 |
break; |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
459 |
case "gmtZeroFormat": |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
460 |
pushStringEntry(qName, attributes, "timezone.gmtZeroFormat"); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
461 |
break; |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
462 |
case "regionFormat": |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
463 |
{ |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
464 |
String type = attributes.getValue("type"); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
465 |
pushStringEntry(qName, attributes, "timezone.regionFormat" + |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
466 |
(type == null ? "" : "." + type)); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
467 |
} |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
468 |
break; |
13583 | 469 |
case "zone": |
470 |
{ |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
471 |
String tzid = attributes.getValue("type"); // Olson tz id |
13583 | 472 |
zonePrefix = CLDRConverter.TIMEZONE_ID_PREFIX; |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
473 |
put(zonePrefix + tzid, new HashMap<String, String>()); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
474 |
pushKeyContainer(qName, attributes, tzid); |
13583 | 475 |
} |
476 |
break; |
|
477 |
case "metazone": |
|
478 |
{ |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
479 |
String zone = attributes.getValue("type"); // LDML meta zone id |
13583 | 480 |
zonePrefix = CLDRConverter.METAZONE_ID_PREFIX; |
481 |
put(zonePrefix + zone, new HashMap<String, String>()); |
|
482 |
pushKeyContainer(qName, attributes, zone); |
|
483 |
} |
|
484 |
break; |
|
485 |
case "long": |
|
486 |
zoneNameStyle = "long"; |
|
487 |
pushContainer(qName, attributes); |
|
488 |
break; |
|
489 |
case "short": |
|
490 |
zoneNameStyle = "short"; |
|
491 |
pushContainer(qName, attributes); |
|
492 |
break; |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
493 |
case "generic": // generic name |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
494 |
case "standard": // standard time name |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
495 |
case "daylight": // daylight saving (summer) time name |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
496 |
pushStringEntry(qName, attributes, CLDRConverter.ZONE_NAME_PREFIX + qName + "." + zoneNameStyle); |
13583 | 497 |
break; |
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
498 |
case "exemplarCity": |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
499 |
pushStringEntry(qName, attributes, CLDRConverter.EXEMPLAR_CITY_PREFIX); |
13583 | 500 |
break; |
501 |
||
502 |
// |
|
503 |
// Number format information |
|
504 |
// |
|
505 |
case "decimalFormatLength": |
|
506 |
if (attributes.getValue("type") == null) { |
|
507 |
// skipping type="short" data |
|
508 |
// for FormatData |
|
509 |
// copy string for later assembly into NumberPatterns |
|
510 |
pushStringEntry(qName, attributes, "NumberPatterns/decimal"); |
|
511 |
} else { |
|
512 |
pushIgnoredContainer(qName); |
|
513 |
} |
|
514 |
break; |
|
38747 | 515 |
case "currencyFormatLength": |
516 |
if (attributes.getValue("type") == null) { |
|
517 |
// skipping type="short" data |
|
518 |
// for FormatData |
|
519 |
pushContainer(qName, attributes); |
|
520 |
} else { |
|
521 |
pushIgnoredContainer(qName); |
|
522 |
} |
|
523 |
break; |
|
13583 | 524 |
case "currencyFormat": |
525 |
// for FormatData |
|
526 |
// copy string for later assembly into NumberPatterns |
|
31263 | 527 |
if (attributes.getValue("type").equals("standard")) { |
13583 | 528 |
pushStringEntry(qName, attributes, "NumberPatterns/currency"); |
31263 | 529 |
} else { |
530 |
pushIgnoredContainer(qName); |
|
531 |
} |
|
13583 | 532 |
break; |
533 |
case "percentFormat": |
|
534 |
// for FormatData |
|
535 |
// copy string for later assembly into NumberPatterns |
|
31263 | 536 |
if (attributes.getValue("type").equals("standard")) { |
13583 | 537 |
pushStringEntry(qName, attributes, "NumberPatterns/percent"); |
31263 | 538 |
} else { |
539 |
pushIgnoredContainer(qName); |
|
540 |
} |
|
13583 | 541 |
break; |
542 |
case "defaultNumberingSystem": |
|
543 |
// default numbering system if multiple numbering systems are used. |
|
544 |
pushStringEntry(qName, attributes, "DefaultNumberingSystem"); |
|
545 |
break; |
|
546 |
case "symbols": |
|
547 |
// for FormatData |
|
548 |
// look up numberingSystems |
|
549 |
symbols: { |
|
550 |
String script = attributes.getValue("numberSystem"); |
|
551 |
if (script == null) { |
|
552 |
// Has no script. Just ignore. |
|
553 |
pushIgnoredContainer(qName); |
|
554 |
break; |
|
555 |
} |
|
556 |
||
557 |
// Use keys as <script>."NumberElements/<symbol>" |
|
558 |
currentNumberingSystem = script + "."; |
|
559 |
String digits = CLDRConverter.handlerNumbering.get(script); |
|
560 |
if (digits == null) { |
|
561 |
pushIgnoredContainer(qName); |
|
562 |
break; |
|
563 |
} |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
564 |
|
13583 | 565 |
@SuppressWarnings("unchecked") |
566 |
List<String> numberingScripts = (List<String>) get("numberingScripts"); |
|
567 |
if (numberingScripts == null) { |
|
568 |
numberingScripts = new ArrayList<>(); |
|
569 |
put("numberingScripts", numberingScripts); |
|
570 |
} |
|
571 |
numberingScripts.add(script); |
|
572 |
put(currentNumberingSystem + "NumberElements/zero", digits.substring(0, 1)); |
|
573 |
pushContainer(qName, attributes); |
|
574 |
} |
|
575 |
break; |
|
576 |
case "decimal": |
|
577 |
// for FormatData |
|
578 |
// copy string for later assembly into NumberElements |
|
45461
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
579 |
if (currentContainer.getqName().equals("symbols")) { |
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
580 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/decimal"); |
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
581 |
} else { |
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
582 |
pushIgnoredContainer(qName); |
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
583 |
} |
13583 | 584 |
break; |
585 |
case "group": |
|
586 |
// for FormatData |
|
587 |
// copy string for later assembly into NumberElements |
|
45461
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
588 |
if (currentContainer.getqName().equals("symbols")) { |
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
589 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/group"); |
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
590 |
} else { |
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
591 |
pushIgnoredContainer(qName); |
8b6f0a3850ab
8178872: Decimal form is inconsistent between CLDR and Java in some special locales
rgoel
parents:
39644
diff
changeset
|
592 |
} |
13583 | 593 |
break; |
594 |
case "list": |
|
595 |
// for FormatData |
|
596 |
// copy string for later assembly into NumberElements |
|
597 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/list"); |
|
598 |
break; |
|
599 |
case "percentSign": |
|
600 |
// for FormatData |
|
601 |
// copy string for later assembly into NumberElements |
|
602 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/percent"); |
|
603 |
break; |
|
604 |
case "nativeZeroDigit": |
|
605 |
// for FormatData |
|
606 |
// copy string for later assembly into NumberElements |
|
607 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/zero"); |
|
608 |
break; |
|
609 |
case "patternDigit": |
|
610 |
// for FormatData |
|
611 |
// copy string for later assembly into NumberElements |
|
612 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/pattern"); |
|
613 |
break; |
|
614 |
case "plusSign": |
|
615 |
// TODO: DecimalFormatSymbols doesn't support plusSign |
|
616 |
pushIgnoredContainer(qName); |
|
617 |
break; |
|
618 |
case "minusSign": |
|
619 |
// for FormatData |
|
620 |
// copy string for later assembly into NumberElements |
|
621 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/minus"); |
|
622 |
break; |
|
623 |
case "exponential": |
|
624 |
// for FormatData |
|
625 |
// copy string for later assembly into NumberElements |
|
626 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/exponential"); |
|
627 |
break; |
|
628 |
case "perMille": |
|
629 |
// for FormatData |
|
630 |
// copy string for later assembly into NumberElements |
|
631 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/permille"); |
|
632 |
break; |
|
633 |
case "infinity": |
|
634 |
// for FormatData |
|
635 |
// copy string for later assembly into NumberElements |
|
636 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/infinity"); |
|
637 |
break; |
|
638 |
case "nan": |
|
639 |
// for FormatData |
|
640 |
// copy string for later assembly into NumberElements |
|
641 |
pushStringEntry(qName, attributes, currentNumberingSystem + "NumberElements/nan"); |
|
642 |
break; |
|
643 |
case "timeFormatLength": |
|
644 |
{ |
|
645 |
// for FormatData |
|
646 |
// copy string for later assembly into DateTimePatterns |
|
647 |
String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName(); |
|
648 |
pushStringEntry(qName, attributes, prefix + "DateTimePatterns/" + attributes.getValue("type") + "-time"); |
|
649 |
} |
|
650 |
break; |
|
651 |
case "dateFormatLength": |
|
652 |
{ |
|
653 |
// for FormatData |
|
654 |
// copy string for later assembly into DateTimePatterns |
|
655 |
String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName(); |
|
656 |
pushStringEntry(qName, attributes, prefix + "DateTimePatterns/" + attributes.getValue("type") + "-date"); |
|
657 |
} |
|
658 |
break; |
|
31263 | 659 |
case "dateTimeFormatLength": |
13583 | 660 |
{ |
661 |
// for FormatData |
|
662 |
// copy string for later assembly into DateTimePatterns |
|
663 |
String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName(); |
|
31263 | 664 |
pushStringEntry(qName, attributes, prefix + "DateTimePatterns/" + attributes.getValue("type") + "-dateTime"); |
13583 | 665 |
} |
666 |
break; |
|
667 |
case "localizedPatternChars": |
|
668 |
{ |
|
669 |
// for FormatData |
|
670 |
// copy string for later adaptation to JRE use |
|
671 |
String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName(); |
|
672 |
pushStringEntry(qName, attributes, prefix + "DateTimePatternChars"); |
|
673 |
} |
|
674 |
break; |
|
675 |
||
31263 | 676 |
// "alias" for root |
677 |
case "alias": |
|
678 |
{ |
|
679 |
if (id.equals("root") && |
|
680 |
!isIgnored(attributes) && |
|
681 |
currentCalendarType != null && |
|
682 |
!currentCalendarType.lname().startsWith("islamic-")) { // ignore Islamic variants |
|
683 |
pushAliasEntry(qName, attributes, attributes.getValue("path")); |
|
684 |
} else { |
|
685 |
pushIgnoredContainer(qName); |
|
686 |
} |
|
687 |
} |
|
688 |
break; |
|
689 |
||
13583 | 690 |
default: |
691 |
// treat anything else as a container |
|
692 |
pushContainer(qName, attributes); |
|
693 |
break; |
|
694 |
} |
|
695 |
} |
|
696 |
||
31263 | 697 |
private static final String[] CONTEXTS = {"stand-alone", "format"}; |
698 |
private static final String[] WIDTHS = {"wide", "narrow", "abbreviated"}; |
|
699 |
private static final String[] LENGTHS = {"full", "long", "medium", "short"}; |
|
700 |
||
701 |
private void populateWidthAlias(String type, Set<String> keys) { |
|
702 |
for (String context : CONTEXTS) { |
|
703 |
for (String width : WIDTHS) { |
|
704 |
String keyName = toJDKKey(type+"Width", context, width); |
|
705 |
if (keyName.length() > 0) { |
|
706 |
keys.add(keyName + "," + context + "," + width); |
|
707 |
} |
|
708 |
} |
|
709 |
} |
|
710 |
} |
|
711 |
||
712 |
private void populateFormatLengthAlias(String type, Set<String> keys) { |
|
713 |
for (String length: LENGTHS) { |
|
714 |
String keyName = toJDKKey(type+"FormatLength", currentContext, length); |
|
715 |
if (keyName.length() > 0) { |
|
716 |
keys.add(keyName + "," + currentContext + "," + length); |
|
717 |
} |
|
718 |
} |
|
719 |
} |
|
720 |
||
721 |
private Set<String> populateAliasKeys(String qName, String context, String width) { |
|
722 |
HashSet<String> ret = new HashSet<>(); |
|
723 |
String keyName = qName; |
|
724 |
||
725 |
switch (qName) { |
|
726 |
case "monthWidth": |
|
727 |
case "dayWidth": |
|
728 |
case "quarterWidth": |
|
729 |
case "dayPeriodWidth": |
|
730 |
case "dateFormatLength": |
|
731 |
case "timeFormatLength": |
|
732 |
case "dateTimeFormatLength": |
|
733 |
case "eraNames": |
|
734 |
case "eraAbbr": |
|
735 |
case "eraNarrow": |
|
736 |
ret.add(toJDKKey(qName, context, width) + "," + context + "," + width); |
|
737 |
break; |
|
738 |
case "days": |
|
739 |
populateWidthAlias("day", ret); |
|
740 |
break; |
|
741 |
case "months": |
|
742 |
populateWidthAlias("month", ret); |
|
743 |
break; |
|
744 |
case "quarters": |
|
745 |
populateWidthAlias("quarter", ret); |
|
746 |
break; |
|
747 |
case "dayPeriods": |
|
748 |
populateWidthAlias("dayPeriod", ret); |
|
749 |
break; |
|
750 |
case "eras": |
|
751 |
ret.add(toJDKKey("eraNames", context, width) + "," + context + "," + width); |
|
752 |
ret.add(toJDKKey("eraAbbr", context, width) + "," + context + "," + width); |
|
753 |
ret.add(toJDKKey("eraNarrow", context, width) + "," + context + "," + width); |
|
754 |
break; |
|
755 |
case "dateFormats": |
|
756 |
populateFormatLengthAlias("date", ret); |
|
757 |
break; |
|
758 |
case "timeFormats": |
|
759 |
populateFormatLengthAlias("time", ret); |
|
760 |
break; |
|
761 |
default: |
|
762 |
break; |
|
763 |
} |
|
764 |
return ret; |
|
765 |
} |
|
766 |
||
767 |
private String translateWidthAlias(String qName, String context, String width) { |
|
768 |
String keyName = qName; |
|
769 |
String type = Character.toUpperCase(qName.charAt(0)) + qName.substring(1, qName.indexOf("Width")); |
|
770 |
||
771 |
switch (width) { |
|
772 |
case "wide": |
|
773 |
keyName = type + "Names/" + context; |
|
774 |
break; |
|
775 |
case "abbreviated": |
|
776 |
keyName = type + "Abbreviations/" + context; |
|
777 |
break; |
|
778 |
case "narrow": |
|
779 |
keyName = type + "Narrows/" + context; |
|
780 |
break; |
|
781 |
default: |
|
782 |
assert false; |
|
783 |
} |
|
784 |
||
785 |
return keyName; |
|
786 |
} |
|
787 |
||
788 |
private String toJDKKey(String containerqName, String context, String type) { |
|
789 |
String keyName = containerqName; |
|
790 |
||
791 |
switch (containerqName) { |
|
792 |
case "monthWidth": |
|
793 |
case "dayWidth": |
|
794 |
case "quarterWidth": |
|
795 |
keyName = translateWidthAlias(keyName, context, type); |
|
796 |
break; |
|
797 |
case "dayPeriodWidth": |
|
798 |
switch (type) { |
|
799 |
case "wide": |
|
800 |
keyName = "AmPmMarkers/" + context; |
|
801 |
break; |
|
802 |
case "narrow": |
|
803 |
keyName = "narrow.AmPmMarkers/" + context; |
|
804 |
break; |
|
805 |
case "abbreviated": |
|
38747 | 806 |
keyName = "abbreviated.AmPmMarkers/" + context; |
31263 | 807 |
break; |
808 |
} |
|
809 |
break; |
|
810 |
case "dateFormatLength": |
|
811 |
case "timeFormatLength": |
|
812 |
case "dateTimeFormatLength": |
|
813 |
keyName = "DateTimePatterns/" + |
|
814 |
type + "-" + |
|
815 |
keyName.substring(0, keyName.indexOf("FormatLength")); |
|
816 |
break; |
|
817 |
case "eraNames": |
|
818 |
keyName = "long.Eras"; |
|
819 |
break; |
|
820 |
case "eraAbbr": |
|
821 |
keyName = "Eras"; |
|
822 |
break; |
|
823 |
case "eraNarrow": |
|
824 |
keyName = "narrow.Eras"; |
|
825 |
break; |
|
826 |
case "dateFormats": |
|
827 |
case "timeFormats": |
|
828 |
case "days": |
|
829 |
case "months": |
|
830 |
case "quarters": |
|
831 |
case "dayPeriods": |
|
832 |
case "eras": |
|
833 |
break; |
|
834 |
default: |
|
835 |
keyName = ""; |
|
836 |
break; |
|
837 |
} |
|
838 |
||
839 |
return keyName; |
|
840 |
} |
|
841 |
||
36857
3e52f7c8ad89
8153041: Remove unused redundant parameter in CLDRConverter
naoto
parents:
32015
diff
changeset
|
842 |
private String getTarget(String path, String calType, String context, String width) { |
3e52f7c8ad89
8153041: Remove unused redundant parameter in CLDRConverter
naoto
parents:
32015
diff
changeset
|
843 |
// Target qName |
31263 | 844 |
int lastSlash = path.lastIndexOf('/'); |
36857
3e52f7c8ad89
8153041: Remove unused redundant parameter in CLDRConverter
naoto
parents:
32015
diff
changeset
|
845 |
String qName = path.substring(lastSlash+1); |
31263 | 846 |
int bracket = qName.indexOf('['); |
847 |
if (bracket != -1) { |
|
848 |
qName = qName.substring(0, bracket); |
|
849 |
} |
|
850 |
||
851 |
// calType |
|
852 |
String typeKey = "/calendar[@type='"; |
|
853 |
int start = path.indexOf(typeKey); |
|
854 |
if (start != -1) { |
|
855 |
calType = path.substring(start+typeKey.length(), path.indexOf("']", start)); |
|
856 |
} |
|
857 |
||
858 |
// context |
|
859 |
typeKey = "Context[@type='"; |
|
860 |
start = path.indexOf(typeKey); |
|
861 |
if (start != -1) { |
|
862 |
context = (path.substring(start+typeKey.length(), path.indexOf("']", start))); |
|
863 |
} |
|
864 |
||
865 |
// width |
|
866 |
typeKey = "Width[@type='"; |
|
867 |
start = path.indexOf(typeKey); |
|
868 |
if (start != -1) { |
|
869 |
width = path.substring(start+typeKey.length(), path.indexOf("']", start)); |
|
870 |
} |
|
871 |
||
872 |
return calType + "." + toJDKKey(qName, context, width); |
|
873 |
} |
|
874 |
||
13583 | 875 |
@Override |
876 |
public void endElement(String uri, String localName, String qName) throws SAXException { |
|
877 |
assert qName.equals(currentContainer.getqName()) : "current=" + currentContainer.getqName() + ", param=" + qName; |
|
878 |
switch (qName) { |
|
879 |
case "calendar": |
|
880 |
assert !(currentContainer instanceof Entry); |
|
881 |
currentCalendarType = null; |
|
882 |
break; |
|
883 |
||
884 |
case "defaultNumberingSystem": |
|
885 |
if (currentContainer instanceof StringEntry) { |
|
886 |
defaultNumberingSystem = ((StringEntry) currentContainer).getValue(); |
|
887 |
assert defaultNumberingSystem != null; |
|
888 |
put(((StringEntry) currentContainer).getKey(), defaultNumberingSystem); |
|
889 |
} else { |
|
890 |
defaultNumberingSystem = null; |
|
891 |
} |
|
892 |
break; |
|
893 |
||
894 |
case "timeZoneNames": |
|
895 |
zonePrefix = null; |
|
896 |
break; |
|
31263 | 897 |
|
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
13583
diff
changeset
|
898 |
case "generic": |
13583 | 899 |
case "standard": |
900 |
case "daylight": |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
901 |
case "exemplarCity": |
13583 | 902 |
if (zonePrefix != null && (currentContainer instanceof Entry)) { |
903 |
@SuppressWarnings("unchecked") |
|
904 |
Map<String, String> valmap = (Map<String, String>) get(zonePrefix + getContainerKey()); |
|
905 |
Entry<?> entry = (Entry<?>) currentContainer; |
|
49904
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
906 |
if (qName.equals("exemplarCity")) { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
907 |
put(CLDRConverter.EXEMPLAR_CITY_PREFIX + getContainerKey(), (String) entry.getValue()); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
908 |
} else { |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
909 |
valmap.put(entry.getKey(), (String) entry.getValue()); |
cadca99d52e7
8181157: CLDR Timezone name fallback implementation
naoto
parents:
48251
diff
changeset
|
910 |
} |
13583 | 911 |
} |
912 |
break; |
|
31263 | 913 |
|
914 |
case "monthWidth": |
|
915 |
case "dayWidth": |
|
916 |
case "dayPeriodWidth": |
|
917 |
case "quarterWidth": |
|
918 |
currentWidth = ""; |
|
919 |
putIfEntry(); |
|
920 |
break; |
|
921 |
||
922 |
case "monthContext": |
|
923 |
case "dayContext": |
|
924 |
case "dayPeriodContext": |
|
925 |
case "quarterContext": |
|
926 |
currentContext = ""; |
|
927 |
putIfEntry(); |
|
928 |
break; |
|
929 |
||
13583 | 930 |
default: |
31263 | 931 |
putIfEntry(); |
932 |
} |
|
933 |
currentContainer = currentContainer.getParent(); |
|
934 |
} |
|
935 |
||
936 |
private void putIfEntry() { |
|
937 |
if (currentContainer instanceof AliasEntry) { |
|
938 |
Entry<?> entry = (Entry<?>) currentContainer; |
|
939 |
String containerqName = entry.getParent().getqName(); |
|
940 |
Set<String> keyNames = populateAliasKeys(containerqName, currentContext, currentWidth); |
|
941 |
if (!keyNames.isEmpty()) { |
|
942 |
for (String keyName : keyNames) { |
|
943 |
String[] tmp = keyName.split(",", 3); |
|
944 |
String calType = currentCalendarType.lname(); |
|
945 |
String src = calType+"."+tmp[0]; |
|
36857
3e52f7c8ad89
8153041: Remove unused redundant parameter in CLDRConverter
naoto
parents:
32015
diff
changeset
|
946 |
String target = getTarget( |
31263 | 947 |
entry.getKey(), |
948 |
calType, |
|
949 |
tmp[1].length()>0 ? tmp[1] : currentContext, |
|
950 |
tmp[2].length()>0 ? tmp[2] : currentWidth); |
|
951 |
if (target.substring(target.lastIndexOf('.')+1).equals(containerqName)) { |
|
952 |
target = target.substring(0, target.indexOf('.'))+"."+tmp[0]; |
|
953 |
} |
|
954 |
CLDRConverter.aliases.put(src.replaceFirst("^gregorian.", ""), |
|
955 |
target.replaceFirst("^gregorian.", "")); |
|
956 |
} |
|
957 |
} |
|
958 |
} else if (currentContainer instanceof Entry) { |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
959 |
Entry<?> entry = (Entry<?>) currentContainer; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
960 |
Object value = entry.getValue(); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
961 |
if (value != null) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
962 |
String key = entry.getKey(); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
963 |
// Tweak for MonthNames for the root locale, Needed for |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
964 |
// SimpleDateFormat.format()/parse() roundtrip. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
965 |
if (id.equals("root") && key.startsWith("MonthNames")) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
966 |
value = new DateFormatSymbols(Locale.US).getShortMonths(); |
13583 | 967 |
} |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
968 |
put(entry.getKey(), value); |
13583 | 969 |
} |
970 |
} |
|
971 |
} |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
972 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
973 |
public String convertOldKeyName(String key) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
974 |
// Explicitly obtained from "alias" attribute in each "key" element. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
975 |
switch (key) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
976 |
case "calendar": |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
977 |
return "ca"; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
978 |
case "currency": |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
979 |
return "cu"; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
980 |
case "collation": |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
981 |
return "co"; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
982 |
case "numbers": |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
983 |
return "nu"; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
984 |
case "timezone": |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
985 |
return "tz"; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
986 |
default: |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
987 |
return key; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
988 |
} |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
989 |
} |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
990 |
} |