290
291 handleDateTimeFormatPatterns(TIME_PATTERN_KEYS, myMap, parentsMap, calendarType, "TimePatterns");
292 handleDateTimeFormatPatterns(DATE_PATTERN_KEYS, myMap, parentsMap, calendarType, "DatePatterns");
293 handleDateTimeFormatPatterns(DATETIME_PATTERN_KEYS, myMap, parentsMap, calendarType, "DateTimePatterns");
294 }
295
296 // First, weed out any empty timezone or metazone names from myMap.
297 // Fill in any missing abbreviations if locale is "en".
298 for (Iterator<String> it = myMap.keySet().iterator(); it.hasNext();) {
299 String key = it.next();
300 if (key.startsWith(CLDRConverter.TIMEZONE_ID_PREFIX)
301 || key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) {
302 @SuppressWarnings("unchecked")
303 Map<String, String> nameMap = (Map<String, String>) myMap.get(key);
304 if (nameMap.isEmpty()) {
305 // Some zones have only exemplarCity, which become empty.
306 // Remove those from the map.
307 it.remove();
308 continue;
309 }
310
311 if (id.equals("en")) {
312 fillInJREs(key, nameMap);
313 }
314 }
315 }
316 for (Iterator<String> it = myMap.keySet().iterator(); it.hasNext();) {
317 String key = it.next();
318 if (key.startsWith(CLDRConverter.TIMEZONE_ID_PREFIX)
319 || key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) {
320 @SuppressWarnings("unchecked")
321 Map<String, String> nameMap = (Map<String, String>) myMap.get(key);
322
323 // Convert key/value pairs to an array.
324 String[] names = new String[ZONE_NAME_KEYS.length];
325 int ix = 0;
326 for (String nameKey : ZONE_NAME_KEYS) {
327 String name = nameMap.get(nameKey);
328 if (name == null && parentsMap != null) {
329 @SuppressWarnings("unchecked")
330 Map<String, String> parentNames = (Map<String, String>) parentsMap.get(key);
331 if (parentNames != null) {
332 name = parentNames.get(nameKey);
333 }
619 if (count != 0) {
620 converter.convert(calendarType, lastLetter, count, jrePattern);
621 }
622 if (cldrFormat.contentEquals(jrePattern)) {
623 return cldrFormat;
624 }
625 return jrePattern.toString();
626 }
627
628 private String toMetaZoneKey(String tzKey) {
629 if (tzKey.startsWith(CLDRConverter.TIMEZONE_ID_PREFIX)) {
630 String tz = tzKey.substring(CLDRConverter.TIMEZONE_ID_PREFIX.length());
631 String meta = CLDRConverter.handlerMetaZones.get(tz);
632 if (meta != null) {
633 return CLDRConverter.METAZONE_ID_PREFIX + meta;
634 }
635 }
636 return null;
637 }
638
639 static List<Object[]> jreTimeZoneNames = Arrays.asList(TimeZoneNames.getContents());
640 private void fillInJREs(String key, Map<String, String> map) {
641 String tzid = null;
642
643 if (key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) {
644 // Look for tzid
645 String meta = key.substring(CLDRConverter.METAZONE_ID_PREFIX.length());
646 if (meta.equals("GMT")) {
647 tzid = meta;
648 } else {
649 for (String tz : CLDRConverter.handlerMetaZones.keySet()) {
650 if (CLDRConverter.handlerMetaZones.get(tz).equals(meta)) {
651 tzid = tz;
652 break;
653 }
654 }
655 }
656 } else {
657 tzid = key.substring(CLDRConverter.TIMEZONE_ID_PREFIX.length());
658 }
659
660 if (tzid != null) {
661 for (Object[] jreZone : jreTimeZoneNames) {
662 if (jreZone[0].equals(tzid)) {
663 for (int i = 0; i < ZONE_NAME_KEYS.length; i++) {
664 if (map.get(ZONE_NAME_KEYS[i]) == null) {
665 String[] jreNames = (String[])jreZone[1];
666 map.put(ZONE_NAME_KEYS[i], jreNames[i]);
667 }
668 }
669 break;
670 }
671 }
672 }
673 }
674
675 /**
676 * Perform a generic conversion of CLDR date-time format pattern letter based
677 * on the support given by the SimpleDateFormat and the j.t.f.DateTimeFormatter
678 * for date-time formatting.
679 */
680 private void convertDateTimePatternLetter(CalendarType calendarType, char cldrLetter, int count, StringBuilder sb) {
681 switch (cldrLetter) {
682 case 'u':
683 // Change cldr letter 'u' to 'y', as 'u' is interpreted as
684 // "Extended year (numeric)" in CLDR/LDML,
685 // which is not supported in SimpleDateFormat and
686 // j.t.f.DateTimeFormatter, so it is replaced with 'y'
687 // as the best approximation
688 appendN('y', count, sb);
689 break;
690 case 'B':
691 // 'B' character (day period) is not supported by
692 // SimpleDateFormat and j.t.f.DateTimeFormatter,
693 // this is a workaround in which 'B' character
694 // appearing in CLDR date-time pattern is replaced
|
290
291 handleDateTimeFormatPatterns(TIME_PATTERN_KEYS, myMap, parentsMap, calendarType, "TimePatterns");
292 handleDateTimeFormatPatterns(DATE_PATTERN_KEYS, myMap, parentsMap, calendarType, "DatePatterns");
293 handleDateTimeFormatPatterns(DATETIME_PATTERN_KEYS, myMap, parentsMap, calendarType, "DateTimePatterns");
294 }
295
296 // First, weed out any empty timezone or metazone names from myMap.
297 // Fill in any missing abbreviations if locale is "en".
298 for (Iterator<String> it = myMap.keySet().iterator(); it.hasNext();) {
299 String key = it.next();
300 if (key.startsWith(CLDRConverter.TIMEZONE_ID_PREFIX)
301 || key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) {
302 @SuppressWarnings("unchecked")
303 Map<String, String> nameMap = (Map<String, String>) myMap.get(key);
304 if (nameMap.isEmpty()) {
305 // Some zones have only exemplarCity, which become empty.
306 // Remove those from the map.
307 it.remove();
308 continue;
309 }
310 }
311 }
312 for (Iterator<String> it = myMap.keySet().iterator(); it.hasNext();) {
313 String key = it.next();
314 if (key.startsWith(CLDRConverter.TIMEZONE_ID_PREFIX)
315 || key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) {
316 @SuppressWarnings("unchecked")
317 Map<String, String> nameMap = (Map<String, String>) myMap.get(key);
318
319 // Convert key/value pairs to an array.
320 String[] names = new String[ZONE_NAME_KEYS.length];
321 int ix = 0;
322 for (String nameKey : ZONE_NAME_KEYS) {
323 String name = nameMap.get(nameKey);
324 if (name == null && parentsMap != null) {
325 @SuppressWarnings("unchecked")
326 Map<String, String> parentNames = (Map<String, String>) parentsMap.get(key);
327 if (parentNames != null) {
328 name = parentNames.get(nameKey);
329 }
615 if (count != 0) {
616 converter.convert(calendarType, lastLetter, count, jrePattern);
617 }
618 if (cldrFormat.contentEquals(jrePattern)) {
619 return cldrFormat;
620 }
621 return jrePattern.toString();
622 }
623
624 private String toMetaZoneKey(String tzKey) {
625 if (tzKey.startsWith(CLDRConverter.TIMEZONE_ID_PREFIX)) {
626 String tz = tzKey.substring(CLDRConverter.TIMEZONE_ID_PREFIX.length());
627 String meta = CLDRConverter.handlerMetaZones.get(tz);
628 if (meta != null) {
629 return CLDRConverter.METAZONE_ID_PREFIX + meta;
630 }
631 }
632 return null;
633 }
634
635 /**
636 * Perform a generic conversion of CLDR date-time format pattern letter based
637 * on the support given by the SimpleDateFormat and the j.t.f.DateTimeFormatter
638 * for date-time formatting.
639 */
640 private void convertDateTimePatternLetter(CalendarType calendarType, char cldrLetter, int count, StringBuilder sb) {
641 switch (cldrLetter) {
642 case 'u':
643 // Change cldr letter 'u' to 'y', as 'u' is interpreted as
644 // "Extended year (numeric)" in CLDR/LDML,
645 // which is not supported in SimpleDateFormat and
646 // j.t.f.DateTimeFormatter, so it is replaced with 'y'
647 // as the best approximation
648 appendN('y', count, sb);
649 break;
650 case 'B':
651 // 'B' character (day period) is not supported by
652 // SimpleDateFormat and j.t.f.DateTimeFormatter,
653 // this is a workaround in which 'B' character
654 // appearing in CLDR date-time pattern is replaced
|