< prev index next >

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

Print this page
rev 47734 : imported patch 8190918
   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  67         minDaysMap = new HashMap<>();
  68         parentLocalesMap = new HashMap<>();
  69     }
  70 
  71     /**
  72      * It returns Map that contains the firstDay and minDays information for
  73      * the country. The Map is created in JRE format after obtaining the data
  74      * from two Maps, firstDayMap and minDaysMap.
  75      *
  76      * It returns null when there is no firstDay and minDays for the country
  77      * although this should not happen because supplementalData.xml includes
  78      * default value for the world ("001") for firstDay and minDays.
  79      */
  80     Map<String, Object> getData(String id) {
  81         Map<String, Object> values = new HashMap<>();
  82         if ("root".equals(id)) {
  83             parentLocalesMap.keySet().forEach(key -> {
  84             values.put(CLDRConverter.PARENT_LOCALE_PREFIX+key,
  85                 parentLocalesMap.get(key));
  86             });
  87         } else {
  88             String countryData = getWeekData(id, JAVA_FIRSTDAY, firstDayMap);
  89         if (countryData != null) {
  90             values.put(JAVA_FIRSTDAY, countryData);
  91         }
  92             String minDaysData = getWeekData(id, JAVA_MINDAY, minDaysMap);
  93         if (minDaysData != null) {
  94             values.put(JAVA_MINDAY, minDaysData);
  95         }
  96         }
  97         return values.isEmpty() ? null : values;
  98     }
  99 
 100     /**
 101      * It returns either firstDay or minDays in the JRE format for the country.
 102      *
 103      * @param country       territory code of the requested data
 104      * @param jreDataName   JAVA_FIRSTDAY or JAVA_MINDAY
 105      * @param dataMap       firstDayMap or minDaysMap
 106      * @return the value for the given jreDataName, or null if requested value
 107      *         (firstDay/minDays) is not available although that is highly unlikely
 108      *         because of the default value for the world (001).
 109      */
 110     String getWeekData(String country, final String jreDataName, final Map<String, Object> dataMap) {
 111         String countryValue = null;
 112         String defaultWorldValue = null;
 113         for (String key : dataMap.keySet()) {
 114             if (key.contains(country)) {
 115                 if (jreDataName.equals(JAVA_FIRSTDAY)) {
 116                     countryValue = DAY_OF_WEEK_MAP.get((String) dataMap.get(key));
 117                 } else if (jreDataName.equals(JAVA_MINDAY)) {
 118                     countryValue = (String) dataMap.get(key);
 119                 }
 120                 if (countryValue != null) {
 121                     return countryValue;
 122                 }
 123             } else if (key.contains(WORLD)) {
 124                 if (jreDataName.equals(JAVA_FIRSTDAY)) {
 125                     defaultWorldValue = DAY_OF_WEEK_MAP.get((String) dataMap.get(key));
 126                 } else if (jreDataName.equals(JAVA_MINDAY)) {
 127                     defaultWorldValue = (String) dataMap.get(key);
 128                 }
 129             }
 130         }
 131         return defaultWorldValue;
 132     }
 133 
 134     @Override
 135     public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException {
 136         // avoid HTTP traffic to unicode.org
 137         if (systemID.startsWith(CLDRConverter.SPPL_LDML_DTD_SYSTEM_ID)) {
 138             return new InputSource((new File(CLDRConverter.LOCAL_SPPL_LDML_DTD)).toURI().toString());
 139         }
 140         return null;
 141     }
 142 
 143     /**
 144      * JRE requires all the data to be organized by the locale while CLDR 1.4 list
 145      * Calendar related data (weekData)in SupplementalData.xml.
 146      * startElement stores JRE required data into two Maps,
 147      * firstDayMap and minDaysMap.
 148      */
 149     @Override
 150     public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
 151         // elements we need to actively ignore
 152         switch (qName) {
 153         case "firstDay":
 154             if (!isIgnored(attributes)) {
 155                 firstDayMap.put(attributes.getValue("territories"), attributes.getValue("day"));


























 156             }
 157             break;
 158         case "minDays":
 159             if (!isIgnored(attributes)) {
 160                 minDaysMap.put(attributes.getValue("territories"), attributes.getValue("count"));
 161             }
 162             break;
 163         case "parentLocale":
 164             if (!isIgnored(attributes)) {
 165                 parentLocalesMap.put(
 166                     attributes.getValue("parent").replaceAll("_", "-"),
 167                     attributes.getValue("locales").replaceAll("_", "-"));
 168             }
 169             break;
 170         default:
 171             // treat anything else as a container
 172             pushContainer(qName, attributes);
 173             break;
 174         }
 175     }
   1 /*
   2  * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  67         minDaysMap = new HashMap<>();
  68         parentLocalesMap = new HashMap<>();
  69     }
  70 
  71     /**
  72      * It returns Map that contains the firstDay and minDays information for
  73      * the country. The Map is created in JRE format after obtaining the data
  74      * from two Maps, firstDayMap and minDaysMap.
  75      *
  76      * It returns null when there is no firstDay and minDays for the country
  77      * although this should not happen because supplementalData.xml includes
  78      * default value for the world ("001") for firstDay and minDays.
  79      */
  80     Map<String, Object> getData(String id) {
  81         Map<String, Object> values = new HashMap<>();
  82         if ("root".equals(id)) {
  83             parentLocalesMap.keySet().forEach(key -> {
  84             values.put(CLDRConverter.PARENT_LOCALE_PREFIX+key,
  85                 parentLocalesMap.get(key));
  86             });
  87             firstDayMap.keySet().forEach(key -> {
  88             values.put(CLDRConverter.CALENDAR_FIRSTDAY_PREFIX+firstDayMap.get(key),
  89                 key);
  90             });
  91             minDaysMap.keySet().forEach(key -> {
  92             values.put(CLDRConverter.CALENDAR_MINDAYS_PREFIX+minDaysMap.get(key),
  93                 key);
  94             });

  95         }
  96         return values.isEmpty() ? null : values;
  97     }
  98 


































  99     @Override
 100     public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException {
 101         // avoid HTTP traffic to unicode.org
 102         if (systemID.startsWith(CLDRConverter.SPPL_LDML_DTD_SYSTEM_ID)) {
 103             return new InputSource((new File(CLDRConverter.LOCAL_SPPL_LDML_DTD)).toURI().toString());
 104         }
 105         return null;
 106     }
 107 
 108     /**
 109      * JRE requires all the data to be organized by the locale while CLDR 1.4 list
 110      * Calendar related data (weekData)in SupplementalData.xml.
 111      * startElement stores JRE required data into two Maps,
 112      * firstDayMap and minDaysMap.
 113      */
 114     @Override
 115     public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
 116         // elements we need to actively ignore
 117         switch (qName) {
 118         case "firstDay":
 119             if (!isIgnored(attributes)) {
 120                 String fd;
 121                 
 122                 switch (attributes.getValue("day")) {
 123                     case "sun":
 124                         fd = "1";
 125                         break;
 126                     default:
 127                     case "mon":
 128                         fd = "2";
 129                         break;
 130                     case "tue":
 131                         fd = "3";
 132                         break;
 133                     case "wed":
 134                         fd = "4";
 135                         break;
 136                     case "thu":
 137                         fd = "5";
 138                         break;
 139                     case "fri":
 140                         fd = "6";
 141                         break;
 142                     case "sat":
 143                         fd = "7";
 144                         break;
 145                 }
 146                 firstDayMap.put(attributes.getValue("territories"), fd);
 147             }
 148             break;
 149         case "minDays":
 150             if (!isIgnored(attributes)) {
 151                 minDaysMap.put(attributes.getValue("territories"), attributes.getValue("count"));
 152             }
 153             break;
 154         case "parentLocale":
 155             if (!isIgnored(attributes)) {
 156                 parentLocalesMap.put(
 157                     attributes.getValue("parent").replaceAll("_", "-"),
 158                     attributes.getValue("locales").replaceAll("_", "-"));
 159             }
 160             break;
 161         default:
 162             // treat anything else as a container
 163             pushContainer(qName, attributes);
 164             break;
 165         }
 166     }
< prev index next >