make/tools/src/build/tools/cldrconverter/LDMLParseHandler.java

Print this page




 138                 if ("stand-alone".equals(type) || "format".equals(type)) {
 139                     pushKeyContainer(qName, attributes, type);
 140                 } else {
 141                     pushIgnoredContainer(qName);
 142                 }
 143             }
 144             break;
 145         case "monthWidth":
 146             {
 147                 // for FormatData
 148                 // create string array for the two types that the JRE knows
 149                 // keep info about the context type so we can sort out inheritance later
 150                 String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName();
 151                 switch (attributes.getValue("type")) {
 152                 case "wide":
 153                     pushStringArrayEntry(qName, attributes, prefix + "MonthNames/" + getContainerKey(), 13);
 154                     break;
 155                 case "abbreviated":
 156                     pushStringArrayEntry(qName, attributes, prefix + "MonthAbbreviations/" + getContainerKey(), 13);
 157                     break;



 158                 default:
 159                     pushIgnoredContainer(qName);
 160                     break;
 161                 }
 162             }
 163             break;
 164         case "month":
 165             // for FormatData
 166             // add to string array entry of monthWidth element
 167             pushStringArrayElement(qName, attributes, Integer.parseInt(attributes.getValue("type")) - 1);
 168             break;
 169         case "dayContext":
 170             {
 171                 // for FormatData
 172                 // need to keep stand-alone and format, to allow for multiple inheritance in CLDR
 173                 String type = attributes.getValue("type");
 174                 if ("stand-alone".equals(type) || "format".equals(type)) {
 175                     pushKeyContainer(qName, attributes, type);
 176                 } else {
 177                     pushIgnoredContainer(qName);
 178                 }
 179             }
 180             break;
 181         case "dayWidth":
 182             {
 183                 // for FormatData
 184                 // create string array for the two types that the JRE knows
 185                 // keep info about the context type so we can sort out inheritance later
 186                 String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName();
 187                 switch (attributes.getValue("type")) {
 188                 case "wide":
 189                     pushStringArrayEntry(qName, attributes, prefix + "DayNames/" + getContainerKey(), 7);
 190                     break;
 191                 case "abbreviated":
 192                     pushStringArrayEntry(qName, attributes, prefix + "DayAbbreviations/" + getContainerKey(), 7);
 193                     break;



 194                 default:
 195                     pushIgnoredContainer(qName);
 196                     break;
 197                 }
 198             }
 199             break;
 200         case "day":
 201             // for FormatData
 202             // add to string array entry of monthWidth element
 203             pushStringArrayElement(qName, attributes, Integer.parseInt(DAY_OF_WEEK_MAP.get(attributes.getValue("type"))) - 1);
 204             break;
 205         case "dayPeriodContext":
 206             // for FormatData
 207             // need to keep stand-alone and format, to allow for multiple inheritance in CLDR
 208             // for FormatData
 209             // need to keep stand-alone and format, to allow for multiple inheritance in CLDR
 210             {
 211                 String type = attributes.getValue("type");
 212                 if ("stand-alone".equals(type) || "format".equals(type)) {
 213                     pushKeyContainer(qName, attributes, type);
 214                 } else {
 215                     pushIgnoredContainer(qName);
 216                 }
 217             }
 218             break;
 219         case "dayPeriodWidth":
 220             // for FormatData
 221             // create string array entry for am/pm. only keeping wide
 222             if ("wide".equals(attributes.getValue("type"))) {

 223                 pushStringArrayEntry(qName, attributes, "AmPmMarkers/" + getContainerKey(), 2);
 224             } else {




 225                 pushIgnoredContainer(qName);

 226             }
 227             break;
 228         case "dayPeriod":
 229             // for FormatData
 230             // add to string array entry of AmPmMarkers element

 231             switch (attributes.getValue("type")) {
 232             case "am":
 233                 pushStringArrayElement(qName, attributes, 0);
 234                 break;
 235             case "pm":
 236                 pushStringArrayElement(qName, attributes, 1);
 237                 break;
 238             default:
 239                 pushIgnoredContainer(qName);
 240                 break;
 241             }




 242             break;
 243         case "eraNames":
 244             // CLDR era names are inconsistent in terms of their lengths. For example,
 245             // the full names of Japanese imperial eras are eraAbbr, while the full names
 246             // of the Julian eras are eraNames.
 247             if (currentCalendarType == null) {
 248                 assert currentContainer instanceof IgnoredContainer;
 249                 pushIgnoredContainer(qName);
 250             } else {
 251                 String key = currentCalendarType.keyElementName() + "long.Eras"; // for now
 252                 pushStringArrayEntry(qName, attributes, key, currentCalendarType.getEraLength(qName));
 253             }
 254             break;
 255         case "eraAbbr":
 256             // for FormatData
 257             // create string array entry
 258             if (currentCalendarType == null) {
 259                 assert currentContainer instanceof IgnoredContainer;
 260                 pushIgnoredContainer(qName);
 261             } else {
 262                 String key = currentCalendarType.keyElementName() + "Eras";
 263                 pushStringArrayEntry(qName, attributes, key, currentCalendarType.getEraLength(qName));
 264             }
 265             break;
 266         case "eraNarrow":
 267             // mainly used for the Japanese imperial calendar
 268             if (currentCalendarType == null) {
 269                 assert currentContainer instanceof IgnoredContainer;
 270                 pushIgnoredContainer(qName);
 271             } else {
 272                 String key = currentCalendarType.keyElementName() + "short.Eras";
 273                 pushStringArrayEntry(qName, attributes, key, currentCalendarType.getEraLength(qName));
 274             }
 275             break;
 276         case "era":
 277             // for FormatData
 278             // add to string array entry of eraAbbr element
 279             if (currentCalendarType == null) {
 280                 assert currentContainer instanceof IgnoredContainer;
 281                 pushIgnoredContainer(qName);
 282             } else {
 283                 int index = Integer.parseInt(attributes.getValue("type"));
 284                 index = currentCalendarType.normalizeEraIndex(index);
 285                 if (index >= 0) {
 286                     pushStringArrayElement(qName, attributes, index);
 287                 } else {
 288                     pushIgnoredContainer(qName);
 289                 }
 290                 if (currentContainer.getParent() == null) {
 291                     throw new InternalError("currentContainer: null parent");
 292                 }
 293             }
 294             break;
 295 
 296         //
 297         // Time zone names
 298         //
 299         case "timeZoneNames":
 300             pushContainer(qName, attributes);
 301             break;
 302         case "zone":
 303             {
 304                 String zone = attributes.getValue("type");
 305                 zonePrefix = CLDRConverter.TIMEZONE_ID_PREFIX;
 306                 put(zonePrefix + zone, new HashMap<String, String>());
 307                 pushKeyContainer(qName, attributes, zone);
 308             }
 309             break;
 310         case "metazone":
 311             {
 312                 String zone = attributes.getValue("type");
 313                 zonePrefix = CLDRConverter.METAZONE_ID_PREFIX;
 314                 put(zonePrefix + zone, new HashMap<String, String>());
 315                 pushKeyContainer(qName, attributes, zone);
 316             }
 317             break;
 318         case "long":
 319             zoneNameStyle = "long";
 320             pushContainer(qName, attributes);
 321             break;
 322         case "short":
 323             zoneNameStyle = "short";
 324             pushContainer(qName, attributes);
 325             break;
 326         case "generic": // not used in JDK
 327             pushIgnoredContainer(qName);
 328             break;
 329         case "standard": // standard time
 330             pushStringEntry(qName, attributes, CLDRConverter.TIMEZONE_NAME_PREFIX + "standard." + zoneNameStyle);
 331             break;
 332         case "daylight":
 333             pushStringEntry(qName, attributes, CLDRConverter.TIMEZONE_NAME_PREFIX + "daylight." + zoneNameStyle);
 334             break;
 335         case "exemplarCity":
 336             pushIgnoredContainer(qName);
 337             break;
 338 
 339         //
 340         // Number format information
 341         //
 342         case "decimalFormatLength":
 343             if (attributes.getValue("type") == null) {
 344                 // skipping type="short" data
 345                 // for FormatData
 346                 // copy string for later assembly into NumberPatterns
 347                 pushStringEntry(qName, attributes, "NumberPatterns/decimal");
 348             } else {
 349                 pushIgnoredContainer(qName);
 350             }
 351             break;
 352         case "currencyFormat":
 353             // for FormatData
 354             // copy string for later assembly into NumberPatterns
 355             pushStringEntry(qName, attributes, "NumberPatterns/currency");


 513         assert qName.equals(currentContainer.getqName()) : "current=" + currentContainer.getqName() + ", param=" + qName;
 514         switch (qName) {
 515         case "calendar":
 516             assert !(currentContainer instanceof Entry);
 517             currentCalendarType = null;
 518             break;
 519 
 520         case "defaultNumberingSystem":
 521             if (currentContainer instanceof StringEntry) {
 522                 defaultNumberingSystem = ((StringEntry) currentContainer).getValue();
 523                 assert defaultNumberingSystem != null;
 524                 put(((StringEntry) currentContainer).getKey(), defaultNumberingSystem);
 525             } else {
 526                 defaultNumberingSystem = null;
 527             }
 528             break;
 529 
 530         case "timeZoneNames":
 531             zonePrefix = null;
 532             break;

 533         case "standard":
 534         case "daylight":
 535             if (zonePrefix != null && (currentContainer instanceof Entry)) {
 536                 @SuppressWarnings("unchecked")
 537                 Map<String, String> valmap = (Map<String, String>) get(zonePrefix + getContainerKey());
 538                 Entry<?> entry = (Entry<?>) currentContainer;
 539                 valmap.put(entry.getKey(), (String) entry.getValue());
 540             }
 541             break;
 542         default:
 543             if (currentContainer instanceof Entry) {
 544                 Entry<?> entry = (Entry<?>) currentContainer;
 545                 Object value = entry.getValue();
 546                 if (value != null) {
 547                     put(entry.getKey(), value);
 548                 }
 549             }
 550         }
 551         currentContainer = currentContainer.getParent();
 552     }


 138                 if ("stand-alone".equals(type) || "format".equals(type)) {
 139                     pushKeyContainer(qName, attributes, type);
 140                 } else {
 141                     pushIgnoredContainer(qName);
 142                 }
 143             }
 144             break;
 145         case "monthWidth":
 146             {
 147                 // for FormatData
 148                 // create string array for the two types that the JRE knows
 149                 // keep info about the context type so we can sort out inheritance later
 150                 String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName();
 151                 switch (attributes.getValue("type")) {
 152                 case "wide":
 153                     pushStringArrayEntry(qName, attributes, prefix + "MonthNames/" + getContainerKey(), 13);
 154                     break;
 155                 case "abbreviated":
 156                     pushStringArrayEntry(qName, attributes, prefix + "MonthAbbreviations/" + getContainerKey(), 13);
 157                     break;
 158                 case "narrow":
 159                     pushStringArrayEntry(qName, attributes, prefix + "MonthNarrows/" + getContainerKey(), 13);
 160                     break;
 161                 default:
 162                     pushIgnoredContainer(qName);
 163                     break;
 164                 }
 165             }
 166             break;
 167         case "month":
 168             // for FormatData
 169             // add to string array entry of monthWidth element
 170             pushStringArrayElement(qName, attributes, Integer.parseInt(attributes.getValue("type")) - 1);
 171             break;
 172         case "dayContext":
 173             {
 174                 // for FormatData
 175                 // need to keep stand-alone and format, to allow for multiple inheritance in CLDR
 176                 String type = attributes.getValue("type");
 177                 if ("stand-alone".equals(type) || "format".equals(type)) {
 178                     pushKeyContainer(qName, attributes, type);
 179                 } else {
 180                     pushIgnoredContainer(qName);
 181                 }
 182             }
 183             break;
 184         case "dayWidth":
 185             {
 186                 // for FormatData
 187                 // create string array for the two types that the JRE knows
 188                 // keep info about the context type so we can sort out inheritance later
 189                 String prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName();
 190                 switch (attributes.getValue("type")) {
 191                 case "wide":
 192                     pushStringArrayEntry(qName, attributes, prefix + "DayNames/" + getContainerKey(), 7);
 193                     break;
 194                 case "abbreviated":
 195                     pushStringArrayEntry(qName, attributes, prefix + "DayAbbreviations/" + getContainerKey(), 7);
 196                     break;
 197                 case "narrow":
 198                     pushStringArrayEntry(qName, attributes, prefix + "DayNarrows/" + getContainerKey(), 7);
 199                     break;
 200                 default:
 201                     pushIgnoredContainer(qName);
 202                     break;
 203                 }
 204             }
 205             break;
 206         case "day":
 207             // for FormatData
 208             // add to string array entry of monthWidth element
 209             pushStringArrayElement(qName, attributes, Integer.parseInt(DAY_OF_WEEK_MAP.get(attributes.getValue("type"))) - 1);
 210             break;
 211         case "dayPeriodContext":
 212             // for FormatData
 213             // need to keep stand-alone and format, to allow for multiple inheritance in CLDR
 214             // for FormatData
 215             // need to keep stand-alone and format, to allow for multiple inheritance in CLDR
 216             {
 217                 String type = attributes.getValue("type");
 218                 if ("stand-alone".equals(type) || "format".equals(type)) {
 219                     pushKeyContainer(qName, attributes, type);
 220                 } else {
 221                     pushIgnoredContainer(qName);
 222                 }
 223             }
 224             break;
 225         case "dayPeriodWidth":
 226             // for FormatData
 227             // create string array entry for am/pm. only keeping wide
 228             switch (attributes.getValue("type")) {
 229             case "wide":
 230                 pushStringArrayEntry(qName, attributes, "AmPmMarkers/" + getContainerKey(), 2);
 231                 break;
 232             case "narrow":
 233                 pushStringArrayEntry(qName, attributes, "narrow.AmPmMarkers/" + getContainerKey(), 2);
 234                 break;
 235             default:
 236                 pushIgnoredContainer(qName);
 237                 break;
 238             }
 239             break;
 240         case "dayPeriod":
 241             // for FormatData
 242             // add to string array entry of AmPmMarkers element
 243             if (attributes.getValue("alt") == null) {
 244                 switch (attributes.getValue("type")) {
 245                 case "am":
 246                     pushStringArrayElement(qName, attributes, 0);
 247                     break;
 248                 case "pm":
 249                     pushStringArrayElement(qName, attributes, 1);
 250                     break;
 251                 default:
 252                     pushIgnoredContainer(qName);
 253                     break;
 254                 }
 255             } else {
 256                 // discard alt values
 257                 pushIgnoredContainer(qName);
 258             }
 259             break;
 260         case "eraNames":
 261             // CLDR era names are inconsistent in terms of their lengths. For example,
 262             // the full names of Japanese imperial eras are eraAbbr, while the full names
 263             // of the Julian eras are eraNames.
 264             if (currentCalendarType == null) {
 265                 assert currentContainer instanceof IgnoredContainer;
 266                 pushIgnoredContainer(qName);
 267             } else {
 268                 String key = currentCalendarType.keyElementName() + "long.Eras"; // for now
 269                 pushStringArrayEntry(qName, attributes, key, currentCalendarType.getEraLength(qName));
 270             }
 271             break;
 272         case "eraAbbr":
 273             // for FormatData
 274             // create string array entry
 275             if (currentCalendarType == null) {
 276                 assert currentContainer instanceof IgnoredContainer;
 277                 pushIgnoredContainer(qName);
 278             } else {
 279                 String key = currentCalendarType.keyElementName() + "Eras";
 280                 pushStringArrayEntry(qName, attributes, key, currentCalendarType.getEraLength(qName));
 281             }
 282             break;
 283         case "eraNarrow":
 284             // mainly used for the Japanese imperial calendar
 285             if (currentCalendarType == null) {
 286                 assert currentContainer instanceof IgnoredContainer;
 287                 pushIgnoredContainer(qName);
 288             } else {
 289                 String key = currentCalendarType.keyElementName() + "narrow.Eras";
 290                 pushStringArrayEntry(qName, attributes, key, currentCalendarType.getEraLength(qName));
 291             }
 292             break;
 293         case "era":
 294             // for FormatData
 295             // add to string array entry of eraAbbr element
 296             if (currentCalendarType == null) {
 297                 assert currentContainer instanceof IgnoredContainer;
 298                 pushIgnoredContainer(qName);
 299             } else {
 300                 int index = Integer.parseInt(attributes.getValue("type"));
 301                 index = currentCalendarType.normalizeEraIndex(index);
 302                 if (index >= 0) {
 303                     pushStringArrayElement(qName, attributes, index);
 304                 } else {
 305                     pushIgnoredContainer(qName);
 306                 }
 307                 if (currentContainer.getParent() == null) {
 308                     throw new InternalError("currentContainer: null parent");
 309                 }
 310             }
 311             break;
 312 
 313         //
 314         // Time zone names
 315         //
 316         case "timeZoneNames":
 317             pushContainer(qName, attributes);
 318             break;
 319         case "zone":
 320             {
 321                 String tzid = attributes.getValue("type"); // Olson tz id
 322                 zonePrefix = CLDRConverter.TIMEZONE_ID_PREFIX;
 323                 put(zonePrefix + tzid, new HashMap<String, String>());
 324                 pushKeyContainer(qName, attributes, tzid);
 325             }
 326             break;
 327         case "metazone":
 328             {
 329                 String zone = attributes.getValue("type"); // LDML meta zone id
 330                 zonePrefix = CLDRConverter.METAZONE_ID_PREFIX;
 331                 put(zonePrefix + zone, new HashMap<String, String>());
 332                 pushKeyContainer(qName, attributes, zone);
 333             }
 334             break;
 335         case "long":
 336             zoneNameStyle = "long";
 337             pushContainer(qName, attributes);
 338             break;
 339         case "short":
 340             zoneNameStyle = "short";
 341             pushContainer(qName, attributes);
 342             break;
 343         case "generic":  // generic name
 344         case "standard": // standard time name
 345         case "daylight": // daylight saving (summer) time name
 346             pushStringEntry(qName, attributes, CLDRConverter.ZONE_NAME_PREFIX + qName + "." + zoneNameStyle);




 347             break;
 348         case "exemplarCity":  // not used in JDK
 349             pushIgnoredContainer(qName);
 350             break;
 351 
 352         //
 353         // Number format information
 354         //
 355         case "decimalFormatLength":
 356             if (attributes.getValue("type") == null) {
 357                 // skipping type="short" data
 358                 // for FormatData
 359                 // copy string for later assembly into NumberPatterns
 360                 pushStringEntry(qName, attributes, "NumberPatterns/decimal");
 361             } else {
 362                 pushIgnoredContainer(qName);
 363             }
 364             break;
 365         case "currencyFormat":
 366             // for FormatData
 367             // copy string for later assembly into NumberPatterns
 368             pushStringEntry(qName, attributes, "NumberPatterns/currency");


 526         assert qName.equals(currentContainer.getqName()) : "current=" + currentContainer.getqName() + ", param=" + qName;
 527         switch (qName) {
 528         case "calendar":
 529             assert !(currentContainer instanceof Entry);
 530             currentCalendarType = null;
 531             break;
 532 
 533         case "defaultNumberingSystem":
 534             if (currentContainer instanceof StringEntry) {
 535                 defaultNumberingSystem = ((StringEntry) currentContainer).getValue();
 536                 assert defaultNumberingSystem != null;
 537                 put(((StringEntry) currentContainer).getKey(), defaultNumberingSystem);
 538             } else {
 539                 defaultNumberingSystem = null;
 540             }
 541             break;
 542 
 543         case "timeZoneNames":
 544             zonePrefix = null;
 545             break;
 546         case "generic":
 547         case "standard":
 548         case "daylight":
 549             if (zonePrefix != null && (currentContainer instanceof Entry)) {
 550                 @SuppressWarnings("unchecked")
 551                 Map<String, String> valmap = (Map<String, String>) get(zonePrefix + getContainerKey());
 552                 Entry<?> entry = (Entry<?>) currentContainer;
 553                 valmap.put(entry.getKey(), (String) entry.getValue());
 554             }
 555             break;
 556         default:
 557             if (currentContainer instanceof Entry) {
 558                 Entry<?> entry = (Entry<?>) currentContainer;
 559                 Object value = entry.getValue();
 560                 if (value != null) {
 561                     put(entry.getKey(), value);
 562                 }
 563             }
 564         }
 565         currentContainer = currentContainer.getParent();
 566     }