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

Print this page




  51     static String LOCAL_SPPL_LDML_DTD;
  52     private static String SOURCE_FILE_DIR;
  53     private static String SPPL_SOURCE_FILE;
  54     private static String NUMBERING_SOURCE_FILE;
  55     private static String METAZONES_SOURCE_FILE;
  56     static String DESTINATION_DIR = "build/gensrc";
  57 
  58     static final String LOCALE_NAME_PREFIX = "locale.displayname.";
  59     static final String CURRENCY_SYMBOL_PREFIX = "currency.symbol.";
  60     static final String CURRENCY_NAME_PREFIX = "currency.displayname.";
  61     static final String CALENDAR_NAME_PREFIX = "calendarname.";
  62     static final String TIMEZONE_ID_PREFIX = "timezone.id.";
  63     static final String ZONE_NAME_PREFIX = "timezone.displayname.";
  64     static final String METAZONE_ID_PREFIX = "metazone.id.";
  65 
  66     private static SupplementDataParseHandler handlerSuppl;
  67     static NumberingSystemsParseHandler handlerNumbering;
  68     static MetaZonesParseHandler handlerMetaZones;
  69     private static BundleGenerator bundleGenerator;
  70 
  71     static int draftType;
  72     private static final String DRAFT_UNCONFIRMED = "unconfirmed";
  73     private static final String DRAFT_PROVISIONAL = "provisional";
  74     private static final String DRAFT_CONTRIBUTED = "contributed";
  75     private static final String DRAFT_APPROVED = "approved";
  76     private static final String DRAFT_TRUE = "true";
  77     private static final String DRAFT_FALSE = "false";
  78     private static final String DRAFT_DEFAULT = DRAFT_APPROVED;
  79     static final Map<String, Integer> DRAFT_MAP = new HashMap<>();
  80 

  81     static {
  82         DRAFT_MAP.put(DRAFT_UNCONFIRMED, 0);
  83         DRAFT_MAP.put(DRAFT_PROVISIONAL, 1);
  84         DRAFT_MAP.put(DRAFT_CONTRIBUTED, 2);
  85         DRAFT_MAP.put(DRAFT_APPROVED, 3);
  86         DRAFT_MAP.put(DRAFT_TRUE, 0);
  87         DRAFT_MAP.put(DRAFT_FALSE, 2);
  88         draftType = DRAFT_MAP.get(DRAFT_DEFAULT);
  89     };





















  90 
  91     static boolean USE_UTF8 = false;
  92     private static boolean verbose;
  93 
  94     private CLDRConverter() {
  95        // no instantiation
  96     }
  97 
  98     @SuppressWarnings("AssignmentToForLoopParameter")
  99     public static void main(String[] args) throws Exception {
 100         if (args.length != 0) {
 101             String currentArg = null;
 102             try {
 103                 for (int i = 0; i < args.length; i++) {
 104                     currentArg = args[i];
 105                     switch (currentArg) {
 106                     case "-draft":
 107                         String draftDataType = args[++i];
 108                         try {
 109                             draftType = DRAFT_MAP.get(draftDataType);
 110                         } catch (NullPointerException e) {
 111                             severe("Error: incorrect draft value: %s%n", draftDataType);
 112                             System.exit(1);
 113                         }
 114                         info("Using the specified data type: %s%n", draftDataType);
 115                         break;
 116 
 117                     case "-base":
 118                         // base directory for input files
 119                         CLDR_BASE = args[++i];
 120                         if (!CLDR_BASE.endsWith("/")) {
 121                             CLDR_BASE += "/";
 122                         }
 123                         break;
 124 
 125                     case "-o":
 126                         // output directory
 127                         DESTINATION_DIR = args[++i];
 128                         break;
 129 


 549         "field.month",
 550         "field.week",
 551         "field.weekday",
 552         "field.dayperiod",
 553         "field.hour",
 554         "field.minute",
 555         "field.second",
 556         "field.zone",
 557         "TimePatterns",
 558         "DatePatterns",
 559         "DateTimePatterns",
 560         "DateTimePatternChars"
 561     };
 562 
 563     private static Map<String, Object> extractFormatData(Map<String, Object> map, String id) {
 564         Map<String, Object> formatData = new LinkedHashMap<>();
 565         for (CalendarType calendarType : CalendarType.values()) {
 566             String prefix = calendarType.keyElementName();
 567             for (String element : FORMAT_DATA_ELEMENTS) {
 568                 String key = prefix + element;
 569                 copyIfPresent(map, "cldr." + key, formatData);
 570                 copyIfPresent(map, key, formatData);
 571             }
 572         }
 573 
 574         // Copy available calendar names
 575         for (String key : map.keySet()) {
 576             if (key.startsWith(CLDRConverter.CALENDAR_NAME_PREFIX)) {
 577                 String type = key.substring(CLDRConverter.CALENDAR_NAME_PREFIX.length());
 578                 for (CalendarType calendarType : CalendarType.values()) {
 579                     if (type.equals(calendarType.lname())) {
 580                         Object value = map.get(key);
 581                         formatData.put(key, value);
 582                         String ukey = CLDRConverter.CALENDAR_NAME_PREFIX + calendarType.uname();
 583                         if (!key.equals(ukey)) {
 584                             formatData.put(ukey, value);
 585                         }
 586                     }
 587                 }
 588             }
 589         }




  51     static String LOCAL_SPPL_LDML_DTD;
  52     private static String SOURCE_FILE_DIR;
  53     private static String SPPL_SOURCE_FILE;
  54     private static String NUMBERING_SOURCE_FILE;
  55     private static String METAZONES_SOURCE_FILE;
  56     static String DESTINATION_DIR = "build/gensrc";
  57 
  58     static final String LOCALE_NAME_PREFIX = "locale.displayname.";
  59     static final String CURRENCY_SYMBOL_PREFIX = "currency.symbol.";
  60     static final String CURRENCY_NAME_PREFIX = "currency.displayname.";
  61     static final String CALENDAR_NAME_PREFIX = "calendarname.";
  62     static final String TIMEZONE_ID_PREFIX = "timezone.id.";
  63     static final String ZONE_NAME_PREFIX = "timezone.displayname.";
  64     static final String METAZONE_ID_PREFIX = "metazone.id.";
  65 
  66     private static SupplementDataParseHandler handlerSuppl;
  67     static NumberingSystemsParseHandler handlerNumbering;
  68     static MetaZonesParseHandler handlerMetaZones;
  69     private static BundleGenerator bundleGenerator;
  70 
  71     static enum DraftType {
  72         UNCONFIRMED,
  73         PROVISIONAL,
  74         CONTRIBUTED,
  75         APPROVED;




  76 
  77         private static final Map<String, DraftType> map = new HashMap<>();
  78         static {
  79             for (DraftType dt : values()) {
  80                 map.put(dt.getKeyword(), dt);
  81             }
  82         }
  83         static private DraftType defaultType = CONTRIBUTED;
  84 
  85         private final String keyword;
  86 
  87         private DraftType() {
  88             keyword = this.name().toLowerCase(Locale.ROOT);
  89 
  90         }
  91 
  92         static DraftType forKeyword(String keyword) {
  93             return map.get(keyword);
  94         }
  95 
  96         static DraftType getDefault() {
  97             return defaultType;
  98         }
  99 
 100         static void setDefault(String keyword) {
 101             defaultType = Objects.requireNonNull(forKeyword(keyword));
 102         }
 103 
 104         String getKeyword() {
 105             return keyword;
 106         }
 107     }
 108 
 109     static boolean USE_UTF8 = false;
 110     private static boolean verbose;
 111 
 112     private CLDRConverter() {
 113        // no instantiation
 114     }
 115 
 116     @SuppressWarnings("AssignmentToForLoopParameter")
 117     public static void main(String[] args) throws Exception {
 118         if (args.length != 0) {
 119             String currentArg = null;
 120             try {
 121                 for (int i = 0; i < args.length; i++) {
 122                     currentArg = args[i];
 123                     switch (currentArg) {
 124                     case "-draft":
 125                         String draftDataType = args[++i];
 126                         try {
 127                             DraftType.setDefault(draftDataType);
 128                         } catch (NullPointerException e) {
 129                             severe("Error: incorrect draft value: %s%n", draftDataType);
 130                             System.exit(1);
 131                         }
 132                         info("Using the specified data type: %s%n", draftDataType);
 133                         break;
 134 
 135                     case "-base":
 136                         // base directory for input files
 137                         CLDR_BASE = args[++i];
 138                         if (!CLDR_BASE.endsWith("/")) {
 139                             CLDR_BASE += "/";
 140                         }
 141                         break;
 142 
 143                     case "-o":
 144                         // output directory
 145                         DESTINATION_DIR = args[++i];
 146                         break;
 147 


 567         "field.month",
 568         "field.week",
 569         "field.weekday",
 570         "field.dayperiod",
 571         "field.hour",
 572         "field.minute",
 573         "field.second",
 574         "field.zone",
 575         "TimePatterns",
 576         "DatePatterns",
 577         "DateTimePatterns",
 578         "DateTimePatternChars"
 579     };
 580 
 581     private static Map<String, Object> extractFormatData(Map<String, Object> map, String id) {
 582         Map<String, Object> formatData = new LinkedHashMap<>();
 583         for (CalendarType calendarType : CalendarType.values()) {
 584             String prefix = calendarType.keyElementName();
 585             for (String element : FORMAT_DATA_ELEMENTS) {
 586                 String key = prefix + element;
 587                 copyIfPresent(map, "java.time." + key, formatData);
 588                 copyIfPresent(map, key, formatData);
 589             }
 590         }
 591 
 592         // Copy available calendar names
 593         for (String key : map.keySet()) {
 594             if (key.startsWith(CLDRConverter.CALENDAR_NAME_PREFIX)) {
 595                 String type = key.substring(CLDRConverter.CALENDAR_NAME_PREFIX.length());
 596                 for (CalendarType calendarType : CalendarType.values()) {
 597                     if (type.equals(calendarType.lname())) {
 598                         Object value = map.get(key);
 599                         formatData.put(key, value);
 600                         String ukey = CLDRConverter.CALENDAR_NAME_PREFIX + calendarType.uname();
 601                         if (!key.equals(ukey)) {
 602                             formatData.put(ukey, value);
 603                         }
 604                     }
 605                 }
 606             }
 607         }