make/tools/src/build/tools/generatebreakiteratordata/GenerateBreakIteratorData.java

Print this page
rev 5615 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o Jigsaw. by Naoto Sato and Masayoshi Okutsu)
   1 /*
   2  * Copyright (c) 2003, 2011, 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


  62     public static void main(String[] args) {
  63         /* Parse command-line options */
  64         processArgs(args);
  65 
  66         /* Make categoryMap from Unicode data */
  67         CharacterCategory.makeCategoryMap(unicodeData);
  68 
  69         /* Generate files */
  70         generateFiles();
  71     }
  72 
  73     /**
  74      * Generate data files whose names are included in
  75      * sun.text.resources.BreakIteratorInfo+<localeName>
  76      */
  77     private static void generateFiles() {
  78         String[] classNames;
  79         ResourceBundle rules, info;
  80 
  81         info =  ResourceBundle.getBundle("sun.text.resources.BreakIteratorInfo",
  82                                        new Locale(language, country, valiant));

  83         classNames = info.getStringArray("BreakIteratorClasses");
  84 
  85         rules = ResourceBundle.getBundle("sun.text.resources.BreakIteratorRules",
  86                                        new Locale(language, country, valiant));

  87 
  88         /*
  89          * Fallback is not necessary here.... So, cannot use getBundle().
  90          */
  91         try {
  92             info = (ResourceBundle)Class.forName("sun.text.resources.BreakIteratorInfo" + localeName).newInstance();
  93 
  94             Enumeration<String> keys = info.getKeys();
  95             while (keys.hasMoreElements()) {
  96                 String key = keys.nextElement();
  97 
  98                 if (key.equals("CharacterData")) {
  99                     generateDataFile(info.getString(key),
 100                                      rules.getString("CharacterBreakRules"),
 101                                      classNames[0]);
 102                 } else if (key.endsWith("WordData")) {
 103                     generateDataFile(info.getString(key),

 104                                      rules.getString("WordBreakRules"),
 105                                      classNames[1]);
 106                 } else if (key.endsWith("LineData")) {
 107                     generateDataFile(info.getString(key),

 108                                      rules.getString("LineBreakRules"),
 109                                      classNames[2]);
 110                 } else if (key.endsWith("SentenceData")) {
 111                     generateDataFile(info.getString(key),

 112                                      rules.getString("SentenceBreakRules"),
 113                                      classNames[3]);
 114                 }
 115             }
 116         }
 117         catch (Exception e) {
 118             throw new InternalError(e.toString());
 119         }
 120     }
 121 
 122     /**
 123      * Generate a data file for break-iterator
 124      */
 125     private static void generateDataFile(String datafile, String rule, String builder) {
 126         RuleBasedBreakIteratorBuilder bld;
 127         if (builder.equals("RuleBasedBreakIterator")) {
 128             bld = new RuleBasedBreakIteratorBuilder(rule);
 129         } else if (builder.equals("DictionaryBasedBreakIterator")) {
 130             bld = new DictionaryBasedBreakIteratorBuilder(rule);
 131         } else {
 132             throw new IllegalArgumentException("Invalid break iterator class \"" + builder + "\"");
 133         }
 134 
 135         bld.makeFile(datafile);
 136     }
 137 
 138     /**
 139      * Parses the specified arguments and sets up the variables.
 140      */


   1 /*
   2  * Copyright (c) 2003, 2012, 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


  62     public static void main(String[] args) {
  63         /* Parse command-line options */
  64         processArgs(args);
  65 
  66         /* Make categoryMap from Unicode data */
  67         CharacterCategory.makeCategoryMap(unicodeData);
  68 
  69         /* Generate files */
  70         generateFiles();
  71     }
  72 
  73     /**
  74      * Generate data files whose names are included in
  75      * sun.text.resources.BreakIteratorInfo+<localeName>
  76      */
  77     private static void generateFiles() {
  78         String[] classNames;
  79         ResourceBundle rules, info;
  80 
  81         info =  ResourceBundle.getBundle("sun.text.resources.BreakIteratorInfo",
  82                                          new Locale(language, country, valiant),
  83                                          BreakIteratorRBControl.INSTANCE);
  84         classNames = info.getStringArray("BreakIteratorClasses");
  85 
  86         rules = ResourceBundle.getBundle("sun.text.resources.BreakIteratorRules",
  87                                          new Locale(language, country, valiant),
  88                                          BreakIteratorRBControl.INSTANCE);
  89 
  90         if (info.containsKey("CharacterData")) {
  91             generateDataFile(info.getString("CharacterData"),










  92                              rules.getString("CharacterBreakRules"),
  93                              classNames[0]);
  94         }
  95         if (info.containsKey("WordData")) {
  96             generateDataFile(info.getString("WordData"),
  97                              rules.getString("WordBreakRules"),
  98                              classNames[1]);
  99         }
 100         if (info.containsKey("LineData")) {
 101             generateDataFile(info.getString("LineData"),
 102                              rules.getString("LineBreakRules"),
 103                              classNames[2]);
 104         }
 105         if (info.containsKey("SentenceData")) {
 106             generateDataFile(info.getString("SentenceData"),
 107                              rules.getString("SentenceBreakRules"),
 108                              classNames[3]);
 109         }
 110     }





 111 
 112     /**
 113      * Generate a data file for break-iterator
 114      */
 115     private static void generateDataFile(String datafile, String rule, String builder) {
 116         RuleBasedBreakIteratorBuilder bld;
 117         if (builder.equals("RuleBasedBreakIterator")) {
 118             bld = new RuleBasedBreakIteratorBuilder(rule);
 119         } else if (builder.equals("DictionaryBasedBreakIterator")) {
 120             bld = new DictionaryBasedBreakIteratorBuilder(rule);
 121         } else {
 122             throw new IllegalArgumentException("Invalid break iterator class \"" + builder + "\"");
 123         }
 124 
 125         bld.makeFile(datafile);
 126     }
 127 
 128     /**
 129      * Parses the specified arguments and sets up the variables.
 130      */