< prev index next >

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

Print this page
rev 47728 : [mq]: 8190918

*** 35,44 **** --- 35,45 ---- import java.util.*; import java.util.ResourceBundle.Control; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; + import java.util.stream.IntStream; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException;
*** 74,83 **** --- 75,86 ---- static final String LOCALE_TYPE_PREFIX = LOCALE_NAME_PREFIX + "type."; static final String LOCALE_TYPE_PREFIX_CA = LOCALE_TYPE_PREFIX + "ca."; static final String CURRENCY_SYMBOL_PREFIX = "currency.symbol."; static final String CURRENCY_NAME_PREFIX = "currency.displayname."; static final String CALENDAR_NAME_PREFIX = "calendarname."; + static final String CALENDAR_FIRSTDAY_PREFIX = "firstDay."; + static final String CALENDAR_MINDAYS_PREFIX = "minDays."; static final String TIMEZONE_ID_PREFIX = "timezone.id."; static final String ZONE_NAME_PREFIX = "timezone.displayname."; static final String METAZONE_ID_PREFIX = "metazone.id."; static final String PARENT_LOCALE_PREFIX = "parentLocale.";
*** 229,239 **** parseSupplemental(); parseBCP47(); List<Bundle> bundles = readBundleList(); convertBundles(bundles); - convertBundles(addedBundles); } private static void usage() { errout("Usage: java CLDRConverter [options]%n" + "\t-help output this usage message and exit%n" --- 232,241 ----
*** 325,347 **** } return retList; } private static final Map<String, Map<String, Object>> cldrBundles = new HashMap<>(); - // this list will contain additional bundles to be generated for Region dependent Data. - private static List<Bundle> addedBundles = new ArrayList<>(); private static Map<String, SortedSet<String>> metaInfo = new HashMap<>(); static { // For generating information on supported locales. metaInfo.put("AvailableLocales", new TreeSet<>()); } - - private static Set<String> calendarDataFields = Set.of("firstDayOfWeek", "minimalDaysInFirstWeek"); - static Map<String, Object> getCLDRBundle(String id) throws Exception { Map<String, Object> bundle = cldrBundles.get(id); if (bundle != null) { return bundle; } --- 327,344 ----
*** 355,367 **** LDMLParseHandler handler = new LDMLParseHandler(id); parseLDMLFile(file, handler); bundle = handler.getData(); cldrBundles.put(id, bundle); ! String country = getCountryCode(id); ! if (country != null) { ! bundle = handlerSuppl.getData(country); if (bundle != null) { //merge two maps into one map Map<String, Object> temp = cldrBundles.remove(id); bundle.putAll(temp); cldrBundles.put(id, bundle); --- 352,365 ---- LDMLParseHandler handler = new LDMLParseHandler(id); parseLDMLFile(file, handler); bundle = handler.getData(); cldrBundles.put(id, bundle); ! ! if (id.equals("root")) { ! // Calendar data (firstDayOfWeek & minDaysInFirstWeek) ! bundle = handlerSuppl.getData("root"); if (bundle != null) { //merge two maps into one map Map<String, Object> temp = cldrBundles.remove(id); bundle.putAll(temp); cldrBundles.put(id, bundle);
*** 383,393 **** // are othrwise not to be fallen back. Process them here as well. // handlerSuppl = new SupplementDataParseHandler(); parseLDMLFile(new File(SPPL_SOURCE_FILE), handlerSuppl); Map<String, Object> parentData = handlerSuppl.getData("root"); ! parentData.keySet().forEach(key -> { parentLocalesMap.put(key, new TreeSet( Arrays.asList(((String)parentData.get(key)).split(" ")))); }); // Parse numberingSystems to get digit zero character information. --- 381,393 ---- // are othrwise not to be fallen back. Process them here as well. // handlerSuppl = new SupplementDataParseHandler(); parseLDMLFile(new File(SPPL_SOURCE_FILE), handlerSuppl); Map<String, Object> parentData = handlerSuppl.getData("root"); ! parentData.keySet().stream() ! .filter(key -> key.startsWith(PARENT_LOCALE_PREFIX)) ! .forEach(key -> { parentLocalesMap.put(key, new TreeSet( Arrays.asList(((String)parentData.get(key)).split(" ")))); }); // Parse numberingSystems to get digit zero character information.
*** 418,477 **** SAXParser parser = pf.newSAXParser(); enableFileAccess(parser); parser.parse(srcfile, handler); } - /** - * This method will check if a new region dependent Bundle needs to be - * generated for this Locale id and targetMap. New Bundle will be generated - * when Locale id has non empty script and country code and targetMap - * contains region dependent data. This method will also remove region - * dependent data from this targetMap after candidate locales check. E.g. It - * will call genRegionDependentBundle() in case of az_Latn_AZ locale and - * remove region dependent data from this targetMap so that az_Latn_AZ - * bundle will not be created. For az_Cyrl_AZ, new Bundle will be generated - * but region dependent data will not be removed from targetMap as its candidate - * locales are [az_Cyrl_AZ, az_Cyrl, root], which does not include az_AZ for - * fallback. - * - */ - - private static void checkRegionDependentBundle(Map<String, Object> targetMap, String id) { - if ((CLDRConverter.getScript(id) != "") - && (CLDRConverter.getCountryCode(id) != "")) { - Map<String, Object> regionDepDataMap = targetMap - .keySet() - .stream() - .filter(calendarDataFields::contains) - .collect(Collectors.toMap(k -> k, targetMap::get)); - if (!regionDepDataMap.isEmpty()) { - Locale cldrLoc = new Locale(CLDRConverter.getLanguageCode(id), - CLDRConverter.getCountryCode(id)); - genRegionDependentBundle(regionDepDataMap, cldrLoc); - if (checkCandidateLocales(id, cldrLoc)) { - // Remove matchedKeys from this targetMap only if checkCandidateLocales() returns true. - regionDepDataMap.keySet().forEach(targetMap::remove); - } - } - } - } - /** - * This method will generate a new Bundle for region dependent data, - * minimalDaysInFirstWeek and firstDayOfWeek. Newly generated Bundle will be added - * to addedBundles list. - */ - private static void genRegionDependentBundle(Map<String, Object> targetMap, Locale cldrLoc) { - String localeId = cldrLoc.toString(); - StringBuilder sb = getCandLocales(cldrLoc); - if (sb.indexOf(localeId) == -1) { - sb.append(localeId); - } - Bundle bundle = new Bundle(localeId, sb.toString(), null, null); - cldrBundles.put(localeId, targetMap); - addedBundles.add(bundle); - } - private static StringBuilder getCandLocales(Locale cldrLoc) { List<Locale> candList = getCandidateLocales(cldrLoc); StringBuilder sb = new StringBuilder(); for (Locale loc : candList) { if (!loc.equals(Locale.ROOT)) { --- 418,427 ----
*** 486,505 **** List<Locale> candList = new ArrayList<>(); candList = applyParentLocales("", defCon.getCandidateLocales("", cldrLoc)); return candList; } - /** - * This method will return true, if for a given locale, its language and - * country specific locale will exist in runtime lookup path. E.g. it will - * return true for bs_Latn_BA. - */ - private static boolean checkCandidateLocales(String id, Locale cldrLoc) { - return(getCandidateLocales(Locale.forLanguageTag(id.replaceAll("_", "-"))) - .contains(cldrLoc)); - } - private static void convertBundles(List<Bundle> bundles) throws Exception { // parent locales map. The mappings are put in base metaInfo file // for now. if (isBaseModule) { metaInfo.putAll(parentLocalesMap); --- 436,445 ----
*** 509,520 **** // Get the target map, which contains all the data that should be // visible for the bundle's locale Map<String, Object> targetMap = bundle.getTargetMap(); - // check if new region DependentBundle needs to be generated for this Locale. - checkRegionDependentBundle(targetMap, bundle.getID()); EnumSet<Bundle.Type> bundleTypes = bundle.getBundleTypes(); if (bundle.isRoot()) { // Add DateTimePatternChars because CLDR no longer supports localized patterns. targetMap.put("DateTimePatternChars", "GyMdkHmsSEDFwWahKzZ"); --- 449,458 ----
*** 607,624 **** */ static String getRegionCode(String id) { return Locale.forLanguageTag(id.replaceAll("_", "-")).getCountry(); } - /* - * Returns the script portion of the given id. - * If id is "root", "" is returned. - */ - static String getScript(String id) { - return "root".equals(id) ? "" : Locale.forLanguageTag(id.replaceAll("_", "-")).getScript(); - } - private static class KeyComparator implements Comparator<String> { static KeyComparator INSTANCE = new KeyComparator(); private KeyComparator() { } --- 545,554 ----
*** 747,758 **** return names; } private static Map<String, Object> extractCalendarData(Map<String, Object> map, String id) { Map<String, Object> calendarData = new LinkedHashMap<>(); ! copyIfPresent(map, "firstDayOfWeek", calendarData); ! copyIfPresent(map, "minimalDaysInFirstWeek", calendarData); return calendarData; } static final String[] FORMAT_DATA_ELEMENTS = { "MonthNames", --- 677,700 ---- return names; } private static Map<String, Object> extractCalendarData(Map<String, Object> map, String id) { Map<String, Object> calendarData = new LinkedHashMap<>(); ! if (id.equals("root")) { ! calendarData.put("firstDayOfWeek", ! IntStream.range(1, 8) ! .mapToObj(String::valueOf) ! .filter(d -> map.keySet().contains(CALENDAR_FIRSTDAY_PREFIX + d)) ! .map(d -> d + ": " + map.get(CALENDAR_FIRSTDAY_PREFIX + d)) ! .collect(Collectors.joining(";"))); ! calendarData.put("minimalDaysInFirstWeek", ! IntStream.range(0, 7) ! .mapToObj(String::valueOf) ! .filter(d -> map.keySet().contains(CALENDAR_MINDAYS_PREFIX + d)) ! .map(d -> d + ": " + map.get(CALENDAR_MINDAYS_PREFIX + d)) ! .collect(Collectors.joining(";"))); ! } return calendarData; } static final String[] FORMAT_DATA_ELEMENTS = { "MonthNames",
< prev index next >