< prev index next >

make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java

Print this page




  91     static final String[] EMPTY_ZONE = {"", "", "", "", "", ""};
  92 
  93     private static SupplementDataParseHandler handlerSuppl;
  94     private static LikelySubtagsParseHandler handlerLikelySubtags;
  95     private static WinZonesParseHandler handlerWinZones;
  96     static SupplementalMetadataParseHandler handlerSupplMeta;
  97     static NumberingSystemsParseHandler handlerNumbering;
  98     static MetaZonesParseHandler handlerMetaZones;
  99     static TimeZoneParseHandler handlerTimeZone;
 100     private static BundleGenerator bundleGenerator;
 101 
 102     // java.base module related
 103     static boolean isBaseModule = false;
 104     static final Set<Locale> BASE_LOCALES = new HashSet<>();
 105 
 106     // "parentLocales" map
 107     private static final Map<String, SortedSet<String>> parentLocalesMap = new HashMap<>();
 108     private static final ResourceBundle.Control defCon =
 109         ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT);
 110 
 111     private static final String[] AVAILABLE_TZIDS = TimeZone.getAvailableIDs();
 112     private static String zoneNameTempFile;
 113     private static String tzDataDir;
 114     private static final Map<String, String> canonicalTZMap = new HashMap<>();
 115 
 116     static enum DraftType {
 117         UNCONFIRMED,
 118         PROVISIONAL,
 119         CONTRIBUTED,
 120         APPROVED;
 121 
 122         private static final Map<String, DraftType> map = new HashMap<>();
 123         static {
 124             for (DraftType dt : values()) {
 125                 map.put(dt.getKeyword(), dt);
 126             }
 127         }
 128         static private DraftType defaultType = CONTRIBUTED;
 129 
 130         private final String keyword;
 131 


 713                             .filter(me ->
 714                                 Arrays.deepEquals(data,
 715                                     (String[])map.get(METAZONE_ID_PREFIX + me.getValue())))
 716                             .findAny();
 717                     cldrMeta.ifPresentOrElse(meta -> names.put(tzid, meta.getValue()), () -> {
 718                         // Check the JRE meta key, add if there is not.
 719                         Optional<Map.Entry<String[], String>> jreMeta =
 720                             jreMetaMap.entrySet().stream()
 721                                 .filter(jm -> Arrays.deepEquals(data, jm.getKey()))
 722                                 .findAny();
 723                         jreMeta.ifPresentOrElse(meta -> names.put(tzid, meta.getValue()), () -> {
 724                                 String metaName = "JRE_" + tzid.replaceAll("[/-]", "_");
 725                                 names.put(METAZONE_ID_PREFIX + metaName, data);
 726                                 names.put(tzid, metaName);
 727                         });
 728                     });
 729                 }
 730             });
 731         }
 732 
 733         Arrays.stream(AVAILABLE_TZIDS).forEach(tzid -> {
 734             // If the tzid is deprecated, get the data for the replacement id
 735             String tzKey = Optional.ofNullable((String)handlerSupplMeta.get(tzid))
 736                                    .orElse(tzid);
 737             Object data = map.get(TIMEZONE_ID_PREFIX + tzKey);
 738 
 739             if (data instanceof String[]) {
 740                 names.put(tzid, data);
 741             } else {
 742                 String meta = handlerMetaZones.get(tzKey);
 743                 if (meta != null) {
 744                     String metaKey = METAZONE_ID_PREFIX + meta;
 745                     data = map.get(metaKey);
 746                     if (data instanceof String[]) {
 747                         // Keep the metazone prefix here.
 748                         names.put(metaKey, data);
 749                         names.put(tzid, meta);
 750                     }
 751                 }
 752             }
 753         });


1057         Files.createDirectories(Paths.get(DESTINATION_DIR, "java", "time", "format"));
1058         Files.write(Paths.get(DESTINATION_DIR, "java", "time", "format", "ZoneName.java"),
1059             Files.lines(Paths.get(zoneNameTempFile))
1060                 .flatMap(l -> {
1061                     if (l.equals("%%%%ZIDMAP%%%%")) {
1062                         return zidMapEntry();
1063                     } else if (l.equals("%%%%MZONEMAP%%%%")) {
1064                         return handlerMetaZones.mzoneMapEntry();
1065                     } else if (l.equals("%%%%DEPRECATED%%%%")) {
1066                         return handlerSupplMeta.deprecatedMap();
1067                     } else if (l.equals("%%%%TZDATALINK%%%%")) {
1068                         return tzDataLinkEntry();
1069                     } else {
1070                         return Stream.of(l);
1071                     }
1072                 })
1073                 .collect(Collectors.toList()),
1074             StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
1075     }
1076 












1077     private static Stream<String> zidMapEntry() {
1078         return ZoneId.getAvailableZoneIds().stream()
1079                 .map(id -> {
1080                     String canonId = canonicalTZMap.getOrDefault(id, id);
1081                     String meta = handlerMetaZones.get(canonId);
1082                     String zone001 = handlerMetaZones.zidMap().get(meta);
1083                     return zone001 == null ? "" :
1084                             String.format("        \"%s\", \"%s\", \"%s\",",
1085                                             id, meta, zone001);
1086                 })
1087                 .filter(s -> !s.isEmpty())
1088                 .sorted();
1089     }
1090 
1091     private static Stream<String> tzDataLinkEntry() {
1092         try {
1093             return Files.walk(Paths.get(tzDataDir), 1)
1094                 .filter(p -> !Files.isDirectory(p))
1095                 .flatMap(CLDRConverter::extractLinks)
1096                 .sorted();
1097         } catch (IOException e) {
1098             throw new UncheckedIOException(e);




  91     static final String[] EMPTY_ZONE = {"", "", "", "", "", ""};
  92 
  93     private static SupplementDataParseHandler handlerSuppl;
  94     private static LikelySubtagsParseHandler handlerLikelySubtags;
  95     private static WinZonesParseHandler handlerWinZones;
  96     static SupplementalMetadataParseHandler handlerSupplMeta;
  97     static NumberingSystemsParseHandler handlerNumbering;
  98     static MetaZonesParseHandler handlerMetaZones;
  99     static TimeZoneParseHandler handlerTimeZone;
 100     private static BundleGenerator bundleGenerator;
 101 
 102     // java.base module related
 103     static boolean isBaseModule = false;
 104     static final Set<Locale> BASE_LOCALES = new HashSet<>();
 105 
 106     // "parentLocales" map
 107     private static final Map<String, SortedSet<String>> parentLocalesMap = new HashMap<>();
 108     private static final ResourceBundle.Control defCon =
 109         ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT);
 110 
 111     private static Set<String> AVAILABLE_TZIDS;
 112     private static String zoneNameTempFile;
 113     private static String tzDataDir;
 114     private static final Map<String, String> canonicalTZMap = new HashMap<>();
 115 
 116     static enum DraftType {
 117         UNCONFIRMED,
 118         PROVISIONAL,
 119         CONTRIBUTED,
 120         APPROVED;
 121 
 122         private static final Map<String, DraftType> map = new HashMap<>();
 123         static {
 124             for (DraftType dt : values()) {
 125                 map.put(dt.getKeyword(), dt);
 126             }
 127         }
 128         static private DraftType defaultType = CONTRIBUTED;
 129 
 130         private final String keyword;
 131 


 713                             .filter(me ->
 714                                 Arrays.deepEquals(data,
 715                                     (String[])map.get(METAZONE_ID_PREFIX + me.getValue())))
 716                             .findAny();
 717                     cldrMeta.ifPresentOrElse(meta -> names.put(tzid, meta.getValue()), () -> {
 718                         // Check the JRE meta key, add if there is not.
 719                         Optional<Map.Entry<String[], String>> jreMeta =
 720                             jreMetaMap.entrySet().stream()
 721                                 .filter(jm -> Arrays.deepEquals(data, jm.getKey()))
 722                                 .findAny();
 723                         jreMeta.ifPresentOrElse(meta -> names.put(tzid, meta.getValue()), () -> {
 724                                 String metaName = "JRE_" + tzid.replaceAll("[/-]", "_");
 725                                 names.put(METAZONE_ID_PREFIX + metaName, data);
 726                                 names.put(tzid, metaName);
 727                         });
 728                     });
 729                 }
 730             });
 731         }
 732 
 733         getAvailableZoneIds().stream().forEach(tzid -> {
 734             // If the tzid is deprecated, get the data for the replacement id
 735             String tzKey = Optional.ofNullable((String)handlerSupplMeta.get(tzid))
 736                                    .orElse(tzid);
 737             Object data = map.get(TIMEZONE_ID_PREFIX + tzKey);
 738 
 739             if (data instanceof String[]) {
 740                 names.put(tzid, data);
 741             } else {
 742                 String meta = handlerMetaZones.get(tzKey);
 743                 if (meta != null) {
 744                     String metaKey = METAZONE_ID_PREFIX + meta;
 745                     data = map.get(metaKey);
 746                     if (data instanceof String[]) {
 747                         // Keep the metazone prefix here.
 748                         names.put(metaKey, data);
 749                         names.put(tzid, meta);
 750                     }
 751                 }
 752             }
 753         });


1057         Files.createDirectories(Paths.get(DESTINATION_DIR, "java", "time", "format"));
1058         Files.write(Paths.get(DESTINATION_DIR, "java", "time", "format", "ZoneName.java"),
1059             Files.lines(Paths.get(zoneNameTempFile))
1060                 .flatMap(l -> {
1061                     if (l.equals("%%%%ZIDMAP%%%%")) {
1062                         return zidMapEntry();
1063                     } else if (l.equals("%%%%MZONEMAP%%%%")) {
1064                         return handlerMetaZones.mzoneMapEntry();
1065                     } else if (l.equals("%%%%DEPRECATED%%%%")) {
1066                         return handlerSupplMeta.deprecatedMap();
1067                     } else if (l.equals("%%%%TZDATALINK%%%%")) {
1068                         return tzDataLinkEntry();
1069                     } else {
1070                         return Stream.of(l);
1071                     }
1072                 })
1073                 .collect(Collectors.toList()),
1074             StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
1075     }
1076 
1077     // This method assumes handlerMetaZones is already initialized
1078     private static Set<String> getAvailableZoneIds() {
1079         assert handlerMetaZones != null;
1080         if (AVAILABLE_TZIDS == null) {
1081             AVAILABLE_TZIDS = new HashSet(ZoneId.getAvailableZoneIds());
1082             AVAILABLE_TZIDS.addAll(handlerMetaZones.keySet());
1083             AVAILABLE_TZIDS.remove(MetaZonesParseHandler.NO_METAZONE_KEY);
1084         }
1085 
1086         return AVAILABLE_TZIDS;
1087     }
1088 
1089     private static Stream<String> zidMapEntry() {
1090         return getAvailableZoneIds().stream()
1091                 .map(id -> {
1092                     String canonId = canonicalTZMap.getOrDefault(id, id);
1093                     String meta = handlerMetaZones.get(canonId);
1094                     String zone001 = handlerMetaZones.zidMap().get(meta);
1095                     return zone001 == null ? "" :
1096                             String.format("        \"%s\", \"%s\", \"%s\",",
1097                                             id, meta, zone001);
1098                 })
1099                 .filter(s -> !s.isEmpty())
1100                 .sorted();
1101     }
1102 
1103     private static Stream<String> tzDataLinkEntry() {
1104         try {
1105             return Files.walk(Paths.get(tzDataDir), 1)
1106                 .filter(p -> !Files.isDirectory(p))
1107                 .flatMap(CLDRConverter::extractLinks)
1108                 .sorted();
1109         } catch (IOException e) {
1110             throw new UncheckedIOException(e);


< prev index next >