Print this page
rev 5696 : 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 packaging changes. by Naoto Sato and Masayoshi Okutsu)
Split |
Close |
Expand all |
Collapse all |
--- old/make/tools/src/build/tools/generatebreakiteratordata/GenerateBreakIteratorData.java
+++ new/make/tools/src/build/tools/generatebreakiteratordata/GenerateBreakIteratorData.java
1 1 /*
2 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2 + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 package build.tools.generatebreakiteratordata;
27 27
28 28 import java.util.Enumeration;
29 29 import java.util.ListResourceBundle;
30 30 import java.util.Locale;
31 31 import java.util.ResourceBundle;
32 32
33 33 /**
34 34 * Generates datafile for BreakIterator.
35 35 */
36 36 public class GenerateBreakIteratorData {
37 37
38 38 /**
39 39 * Directory where generated data files are put in.
40 40 */
41 41 private static String outputDir = "" ;
42 42
43 43 /**
44 44 * Unicode data file
45 45 */
46 46 private static String unicodeData = "UnicodeData.txt";
47 47
48 48 /**
49 49 * Rules file
50 50 */
51 51 private static String rules = "sun.text.resources.BreakIteratorRules";
52 52
53 53 /**
54 54 * Locale data
55 55 */
56 56 private static String language = "";
57 57 private static String country = "";
58 58 private static String valiant = "";
59 59 private static String localeName = ""; /* _language_country_valiant */
60 60
61 61
62 62 public static void main(String[] args) {
63 63 /* Parse command-line options */
64 64 processArgs(args);
65 65
66 66 /* Make categoryMap from Unicode data */
67 67 CharacterCategory.makeCategoryMap(unicodeData);
68 68
69 69 /* Generate files */
70 70 generateFiles();
71 71 }
↓ open down ↓ |
59 lines elided |
↑ open up ↑ |
72 72
73 73 /**
74 74 * Generate data files whose names are included in
75 75 * sun.text.resources.BreakIteratorInfo+<localeName>
76 76 */
77 77 private static void generateFiles() {
78 78 String[] classNames;
79 79 ResourceBundle rules, info;
80 80
81 81 info = ResourceBundle.getBundle("sun.text.resources.BreakIteratorInfo",
82 - new Locale(language, country, valiant));
82 + new Locale(language, country, valiant),
83 + BreakIteratorRBControl.INSTANCE);
83 84 classNames = info.getStringArray("BreakIteratorClasses");
84 85
85 86 rules = ResourceBundle.getBundle("sun.text.resources.BreakIteratorRules",
86 - new Locale(language, country, valiant));
87 + new Locale(language, country, valiant),
88 + BreakIteratorRBControl.INSTANCE);
87 89
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 - }
90 + if (info.containsKey("CharacterData")) {
91 + generateDataFile(info.getString("CharacterData"),
92 + rules.getString("CharacterBreakRules"),
93 + classNames[0]);
116 94 }
117 - catch (Exception e) {
118 - throw new InternalError(e.toString());
95 + if (info.containsKey("WordData")) {
96 + generateDataFile(info.getString("WordData"),
97 + rules.getString("WordBreakRules"),
98 + classNames[1]);
119 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 + }
120 110 }
121 111
122 112 /**
123 113 * Generate a data file for break-iterator
124 114 */
125 115 private static void generateDataFile(String datafile, String rule, String builder) {
126 116 RuleBasedBreakIteratorBuilder bld;
127 117 if (builder.equals("RuleBasedBreakIterator")) {
128 118 bld = new RuleBasedBreakIteratorBuilder(rule);
129 119 } else if (builder.equals("DictionaryBasedBreakIterator")) {
130 120 bld = new DictionaryBasedBreakIteratorBuilder(rule);
131 121 } else {
132 122 throw new IllegalArgumentException("Invalid break iterator class \"" + builder + "\"");
133 123 }
134 124
135 125 bld.makeFile(datafile);
136 126 }
137 127
138 128 /**
139 129 * Parses the specified arguments and sets up the variables.
140 130 */
141 131 private static void processArgs(String[] args) {
142 132 for (int i = 0; i < args.length; i++) {
143 133 String arg = args[i];
144 134 if (arg.equals("-o")) {
145 135 outputDir = args[++i];
146 136 } else if (arg.equals("-spec")) {
147 137 unicodeData = args[++i];
148 138 } else if (arg.equals("-language")) {
149 139 language = args[++i];
150 140 } else if (arg.equals("-country")) {
151 141 country = args[++i];
152 142 } else if (arg.equals("-valiant")) {
153 143 valiant = args[++i];
154 144 } else {
155 145 usage();
156 146 }
157 147 }
158 148
159 149 // Set locale name
160 150 localeName = getLocaleName();
161 151 }
162 152
163 153 /**
164 154 * Make locale name ("_language_country_valiant")
165 155 */
166 156 private static String getLocaleName() {
167 157 if (language.equals("")) {
168 158 if (!country.equals("") || !valiant.equals("")) {
169 159 language = "en";
170 160 } else {
171 161 return "";
172 162 }
173 163 }
174 164
175 165 StringBuffer sb = new StringBuffer();
176 166 sb.append('_');
177 167 sb.append(language);
178 168 if (!country.equals("") || !valiant.equals("")) {
179 169 sb.append('_');
180 170 sb.append(country);
181 171 if (!valiant.equals("")) {
182 172 sb.append('_');
183 173 sb.append(valiant);
184 174 }
185 175 }
186 176
187 177 return sb.toString();
188 178 }
189 179
190 180 /**
191 181 * Usage: Displayed when an invalid command-line option is specified.
192 182 */
193 183 private static void usage() {
194 184 System.err.println("Usage: GenerateBreakIteratorData [options]\n" +
195 185 " -o outputDir output directory name\n" +
196 186 " -spec specname unicode text filename\n" +
197 187 " and locale data:\n" +
198 188 " -lang language target language name\n" +
199 189 " -country country target country name\n" +
200 190 " -valiant valiant target valiant name\n"
201 191 );
202 192 }
203 193
204 194 /**
205 195 * Return the path of output directory
206 196 */
207 197 static String getOutputDirectory() {
208 198 return outputDir;
209 199 }
210 200 }
↓ open down ↓ |
81 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX