< prev index next >
make/jdk/src/classes/build/tools/cldrconverter/LDMLParseHandler.java
Print this page
*** 50,59 ****
--- 50,61 ----
private String zoneNameStyle; // "long" or "short" for time zone names
private String zonePrefix;
private final String id;
private String currentContext = ""; // "format"/"stand-alone"
private String currentWidth = ""; // "wide"/"narrow"/"abbreviated"
+ private String currentStyle = ""; // short, long for decimalFormat
+ private String compactCount = ""; // one or other for decimalFormat
LDMLParseHandler(String id) {
this.id = id;
}
*** 501,517 ****
//
// Number format information
//
case "decimalFormatLength":
! if (attributes.getValue("type") == null) {
! // skipping type="short" data
! // for FormatData
! // copy string for later assembly into NumberPatterns
pushStringEntry(qName, attributes, "NumberPatterns/decimal");
} else {
pushIgnoredContainer(qName);
}
break;
case "currencyFormatLength":
if (attributes.getValue("type") == null) {
// skipping type="short" data
--- 503,591 ----
//
// Number format information
//
case "decimalFormatLength":
! String type = attributes.getValue("type");
! if (null == type) {
! // format data for decimal number format
pushStringEntry(qName, attributes, "NumberPatterns/decimal");
+ currentStyle = type;
} else {
+ switch (type) {
+ case "short":
+ case "long":
+ // considering "short" and long for
+ // compact number formatting patterns
+ pushKeyContainer(qName, attributes, type);
+ currentStyle = type;
+ break;
+ default:
pushIgnoredContainer(qName);
+ break;
+ }
+ }
+ break;
+ case "decimalFormat":
+ if(currentStyle == null) {
+ pushContainer(qName, attributes);
+ } else {
+ switch (currentStyle) {
+ case "short":
+ pushStringListEntry(qName, attributes,
+ currentStyle+".CompactNumberPatterns");
+ break;
+ case "long":
+ pushStringListEntry(qName, attributes,
+ currentStyle+".CompactNumberPatterns");
+ break;
+ default:
+ pushIgnoredContainer(qName);
+ break;
+ }
+ }
+ break;
+ case "pattern":
+ String containerName = currentContainer.getqName();
+ if (containerName.equals("decimalFormat")) {
+ if (currentStyle == null) {
+ pushContainer(qName, attributes);
+ } else {
+ // The compact number patterns parsing assumes that the order
+ // of patterns are always in the increasing order of their
+ // type attribute i.e. type = 1000...
+ // Between the inflectional forms for a type (e.g.
+ // count = "one" and count = "other" for type = 1000), it is
+ // assumed that the count = "one" always appears before
+ // count = "other"
+ switch (currentStyle) {
+ case "short":
+ case "long":
+ String count = attributes.getValue("count");
+ // first pattern of count = "one" or count = "other"
+ if ((count.equals("one") || count.equals("other"))
+ && compactCount.equals("")) {
+ compactCount = count;
+ pushStringListElement(qName, attributes,
+ (int) Math.log10(Double.parseDouble(attributes.getValue("type"))));
+ } else if ((count.equals("one") || count.equals("other"))
+ && compactCount.equals(count)) {
+ // extract patterns with similar "count"
+ // attribute value
+ pushStringListElement(qName, attributes,
+ (int) Math.log10(Double.parseDouble(attributes.getValue("type"))));
+ } else {
+ pushIgnoredContainer(qName);
+ }
+ break;
+ default:
+ pushIgnoredContainer(qName);
+ break;
+ }
+ }
+ } else {
+ pushContainer(qName, attributes);
}
break;
case "currencyFormatLength":
if (attributes.getValue("type") == null) {
// skipping type="short" data
*** 674,687 ****
break;
// "alias" for root
case "alias":
{
! if (id.equals("root") &&
! !isIgnored(attributes) &&
! currentCalendarType != null &&
! !currentCalendarType.lname().startsWith("islamic-")) { // ignore Islamic variants
pushAliasEntry(qName, attributes, attributes.getValue("path"));
} else {
pushIgnoredContainer(qName);
}
}
--- 748,760 ----
break;
// "alias" for root
case "alias":
{
! if (id.equals("root") && !isIgnored(attributes)
! && ((currentContainer.getqName().equals("decimalFormatLength"))
! || (currentCalendarType != null && !currentCalendarType.lname().startsWith("islamic-")))) { // ignore islamic variants
pushAliasEntry(qName, attributes, attributes.getValue("path"));
} else {
pushIgnoredContainer(qName);
}
}
*** 829,838 ****
--- 902,914 ----
case "months":
case "quarters":
case "dayPeriods":
case "eras":
break;
+ case "decimalFormatLength": // used for compact number formatting patterns
+ keyName = type + ".CompactNumberPatterns";
+ break;
default:
keyName = "";
break;
}
*** 867,876 ****
--- 943,960 ----
start = path.indexOf(typeKey);
if (start != -1) {
width = path.substring(start+typeKey.length(), path.indexOf("']", start));
}
+ // used for compact number formatting patterns aliases
+ typeKey = "decimalFormatLength[@type='";
+ start = path.indexOf(typeKey);
+ if (start != -1) {
+ String style = path.substring(start + typeKey.length(), path.indexOf("']", start));
+ return toJDKKey(qName, "", style);
+ }
+
return calType + "." + toJDKKey(qName, context, width);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
*** 924,944 ****
case "dayPeriodContext":
case "quarterContext":
currentContext = "";
putIfEntry();
break;
!
default:
putIfEntry();
}
currentContainer = currentContainer.getParent();
}
private void putIfEntry() {
if (currentContainer instanceof AliasEntry) {
Entry<?> entry = (Entry<?>) currentContainer;
String containerqName = entry.getParent().getqName();
Set<String> keyNames = populateAliasKeys(containerqName, currentContext, currentWidth);
if (!keyNames.isEmpty()) {
for (String keyName : keyNames) {
String[] tmp = keyName.split(",", 3);
String calType = currentCalendarType.lname();
--- 1008,1037 ----
case "dayPeriodContext":
case "quarterContext":
currentContext = "";
putIfEntry();
break;
! case "decimalFormatLength":
! currentStyle = "";
! compactCount = "";
! putIfEntry();
! break;
default:
putIfEntry();
}
currentContainer = currentContainer.getParent();
}
private void putIfEntry() {
if (currentContainer instanceof AliasEntry) {
Entry<?> entry = (Entry<?>) currentContainer;
String containerqName = entry.getParent().getqName();
+ if (containerqName.equals("decimalFormatLength")) {
+ String srcKey = toJDKKey(containerqName, "", currentStyle);
+ String targetKey = getTarget(entry.getKey(), "", "", "");
+ CLDRConverter.aliases.put(srcKey, targetKey);
+ } else {
Set<String> keyNames = populateAliasKeys(containerqName, currentContext, currentWidth);
if (!keyNames.isEmpty()) {
for (String keyName : keyNames) {
String[] tmp = keyName.split(",", 3);
String calType = currentCalendarType.lname();
*** 953,962 ****
--- 1046,1056 ----
}
CLDRConverter.aliases.put(src.replaceFirst("^gregorian.", ""),
target.replaceFirst("^gregorian.", ""));
}
}
+ }
} else if (currentContainer instanceof Entry) {
Entry<?> entry = (Entry<?>) currentContainer;
Object value = entry.getValue();
if (value != null) {
String key = entry.getKey();
< prev index next >