]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/localespi/readme.html
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / localespi / readme.html
1 <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">\r
2 <html>\r
3 <head>\r
4   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\r
5   <meta http-equiv="Content-Style-Type" content="text/css2">\r
6   <title>ReadMe for ICU4J Locale Service Provider</title>\r
7   <meta name="COPYRIGHT" content="Copyright 2008-2009, International Business Machines Corporation and others. All Rights Reserved.">\r
8   <style type="text/css">\r
9 h3.doc { background: #CCCCFF }\r
10   </style>\r
11 </head>\r
12 <body style="background-color: rgb(255, 255, 255);" lang="EN-US"\r
13  link="#0000ff" vlink="#800080">\r
14 <h2>ICU4J Locale Service Provider</h2>\r
15 <h3>Read Me for ICU4J Locale Service Provider</h3>\r
16 <hr size="2" width="100%">\r
17 <p><b>Note:</b> This is a technical preview for ICU4J Locale Service Provider.\r
18 This component may be changed or removed in future release of ICU4J.\r
19 </p>\r
20 <h3 class="doc">Contents</h3>\r
21 <ul type="disc">\r
22   <li><a href="#intro">Introduction</a></li>\r
23   <li><a href="#usage">Using ICU4J Locale Service Provider</a></li>\r
24   <li><a href="#config">Optional Configuration</a></li>\r
25   <li><a href="#build">Building and Testing ICU4J Locale Service Provider</a></li>\r
26 </ul>\r
27 \r
28 <h3 class="doc"><a name="intro"></a>Introduction</h3>\r
29 \r
30 <p>Java SE 6 introduced a new feature which allows Java user code to extend locale support\r
31 in Java runtime environment.  JREs shipped by Sun or IBM come with decent locale coverage,\r
32 but some users may want more locale support.  Java SE 6 includes abstract classes extending\r
33 <a href="http://java.sun.com/javase/6/docs/api/java/util/spi/LocaleServiceProvider.html">\r
34 java.util.spi.LocaleServiceProvider</a>.  Java SE 6 users can create a subclass of these\r
35 abstract class to supply their own locale support for text break, collation, date/number\r
36 formatting or providing translations for currency, locale and time zone names.</p>\r
37 \r
38 <p>ICU4J has been providing more comprehensive locale coverage than standard JREs.  However,\r
39 Java programmers have to use ICU4J's own internationalization service APIs (com.ibm.icu.*)\r
40 to utilize the rich locale support.  Sometimes, the migration is not an option for various\r
41 reasons.  For example, your code may depend on existing Java libraries utilizing JDK\r
42 internationalization service APIs, but you have no access to the source code.  In this case,\r
43 it is not possible to modify the libraries to use ICU4J APIs.</p>\r
44 \r
45 <p>ICU4J Locale Service Provider is a component consists of classes implementing the Java\r
46 SE 6 locale sensitive service provider interfaces.  Available service providers are -\r
47 <ul>\r
48   <li><a href="http://java.sun.com/javase/6/docs/api/java/text/spi/BreakIteratorProvider.html">BreakIteratorProvider</a></li>\r
49   <li><a href="http://java.sun.com/javase/6/docs/api/java/text/spi/CollatorProvider.html">CollatorProvider</a></li>\r
50   <li><a href="http://java.sun.com/javase/6/docs/api/java/text/spi/DateFormatProvider.html">DateFormatProvider</a></li>\r
51   <li><a href="http://java.sun.com/javase/6/docs/api/java/text/spi/DateFormatSymbolsProvider.html">DateFormatSymbolsProvider</a></li>\r
52   <li><a href="http://java.sun.com/javase/6/docs/api/java/text/spi/DecimalFormatSymbolsProvider.html">DecimalFormatSymbolsProvider</a></li>\r
53   <li><a href="http://java.sun.com/javase/6/docs/api/java/text/spi/NumberFormatProvider.html">NumberFormatProvider</a></li>\r
54   <li><a href="http://java.sun.com/javase/6/docs/api/java/util/spi/CurrencyNameProvider.html">CurrencyNameProvider</a></li>\r
55   <li><a href="http://java.sun.com/javase/6/docs/api/java/util/spi/LocaleNameProvider.html">LocaleNameProvider</a></li>\r
56   <li><a href="http://java.sun.com/javase/6/docs/api/java/util/spi/TimeZoneNameProvider.html">TimeZoneNameProvider</a></li>\r
57 </ul>\r
58 ICU4J Locale Service Provider is designed to work as installed extensions in a JRE.\r
59 Once the component is configured properly, Java application running on the JRE automatically\r
60 picks the ICU4J's internationalization service implementation when a requested locale is not\r
61 available in the JRE.</p>\r
62 \r
63 <h3 class="doc"><a name="usage"></a>Using ICU4J Locale Service Provider</h3>\r
64 \r
65 <p>Java SE 6 locale sensitive service providers are using the\r
66 <a href="http://java.sun.com/javase/6/docs/technotes/guides/extensions/index.html">Java Extension Mechanism</a>.\r
67 An implementation of a locale sensitive service provider is installed as an optional package\r
68 to extend the functionality of the Java core platform.  To install an optional package, its JAR\r
69 files must be placed in the Java extension directory.  The standard location is \r
70 &lt;<i>java-home</i>&gt;/lib/ext.  You can alternatively use the system property <i>java.ext.dirs</i>\r
71 to specify one or more locations where optional packages are installed.  For example,\r
72 if the JRE root directry is JAVA_HOME and you put ICU4J Locale Service Provider files\r
73 in ICU_SPI_DIR, the ICU4J Locale Service Provider is enabled by the following command.\r
74 <pre>\r
75   java -Djava.ext.dirs=%JAVA_HOME%\lib\ext;%ICU_SPI_DIR% &lt;your_java_app&gt;  [Microsoft Windows]\r
76   java -Djava.ext.dirs=$JAVA_HOME/lib/ext:$ICU_SPI_DIR &lt;your_java_app&gt;    [Linux, Solaris and other unix like platforms]\r
77 </pre>\r
78 </p>\r
79 \r
80 <p>The ICU4J's implementations of Java SE 6 locale sensitive service provider interfaces\r
81 and configuration files are packaged in a single JAR file (icu4j-localespi-&lt;<i>version</i>&gt;.jar).\r
82 But the actual implementation of the service classes and data are in the ICU4J core JAR\r
83 file (icu4j-&lt;<i>version</i>&gt;.jar).  So you need to put the localespi JAR file along\r
84 with the core JAR file in the Java extension directory.</p>\r
85 \r
86 <p>Once the ICU4J Locale Service Provider is installed properly, factory methods in\r
87 JDK internationalization classes look for the implementation provided by ICU4J when\r
88 a requested locale is not supported by the JDK service class.  For example, locale\r
89 af_ZA (Afrikaans - South Africa) is not supported by JDK DateFormat in Sun Java SE 6.\r
90 The following code snippet returns an instance of DateFormat from ICU4J Locale Service\r
91 Provider and prints out the current date localized for af_ZA.\r
92 <pre>\r
93   DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, new Locale("af", "ZA"));\r
94   System.out.println(df.format(new Date()));\r
95 </pre>\r
96 Sample output:\r
97 <pre>\r
98   2008 Junie 19     [With ICU4J Locale Service Provider enabled]\r
99   June 19, 2008     [Without ICU4J Locale Service Provider]\r
100 </pre>\r
101 </p>\r
102 \r
103 <h3 class="doc"><a name="config"></a>Optional Configuration</h3>\r
104 \r
105 <h4>Enabling or disabling individual service</h4>\r
106 <p>By default, all Java 6 SE locale sensitive service providers are enabled in the\r
107 ICU4J Locale Service Provider JAR file.  If you want to disable specific providers\r
108 supported by ICU4J, you can remove the corresponding provider configuration files\r
109 from META-INF/services in the localespi JAR file.  For example, if you do not want\r
110 to use ICU's time zone name service at all, you can remove the file: \r
111 META-INF/services/java.util.spi.TimeZoneNameProvider from the JAR file.</p>\r
112 \r
113 <p><b>Note:</b> Disabling DateFormatSymbolsProvider/DecimalFormatSymbolsProvider\r
114 won't affect the localized symbols actually used by DateFormatProvider/NumberFormatProvider\r
115 by the current implementation.  These services are implemented independently.</p>\r
116 \r
117 <h4>Configuring the behavior of ICU4J Locale Service Provider</h4>\r
118 <p>com/ibm/icu/impl/javaspi/ICULocaleServiceProviderConfig.properties in the localespi\r
119 JAR file is used for configuring the behavior of the ICU4J Locale Service Provider\r
120 implementation.  There are some configuration properties available.  See the table below\r
121 for each configuration in detail.</p>\r
122 <table border="1">\r
123 <tr>\r
124   <th>Property</th>\r
125   <th>Value</th>\r
126   <th>Default</th>\r
127   <th>Description</th>\r
128 </tr>\r
129 <tr>\r
130   <td>com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.enableIcuVariants</td>\r
131   <td>"true" or "false"</td>\r
132   <td>"true"</td>\r
133   <td>\r
134     Whether if Locales with ICU's variant suffix will be included in getAvailableLocales.\r
135     The current Java SE 6 locale sensitive service does not allow user provided provider\r
136     implementations to override locales supported by JRE itself.  When this property is\r
137     "true"(default), ICU4J Locale Service Provider includes Locales with\r
138     the suffix(com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.icuVariantSuffix)\r
139     in the variant field.  For example, the ICU4J provider includes locales fr_FR and\r
140     fr_FR_ICU in the available locale list.  So JDK API user can still access the\r
141     internationalization service object created by the ICU4J provider by the special locale\r
142     fr_FR_ICU.\r
143   </td>\r
144 </tr>\r
145 <tr>\r
146   <td>com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.icuVariantSuffix</td>\r
147   <td><i>Any String</i></td>\r
148   <td>"ICU"</td>\r
149   <td>\r
150     Suffix string used in Locale's variant field to specify the ICU implementation.\r
151   </td>\r
152 </tr>\r
153 <tr>\r
154   <td>com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.enableIso3Languages</td>\r
155   <td>"true" or "false"</td>\r
156   <td>"true"</td>\r
157   <td>\r
158     Whether if 3-letter language Locales are included in getAvailabeLocales.  Use of\r
159     3-letter language codes in java.util.Locale is not supported by the API reference\r
160     document.  However, the implementation does not check the length of language code,\r
161     so there is no practical problem with it.\r
162   </td>\r
163 </tr>\r
164 <tr>\r
165   <td>com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.useDecimalFormat</td>\r
166   <td>"true" or "false"</td>\r
167   <td>"false"</td>\r
168   <td>\r
169     Whether if java.text.DecimalFormat subclass is used for NumberFormat#getXXXInstance.\r
170     DecimalFormat#format(Object,StringBuffer,FieldPosition) is declared as final, so\r
171     ICU cannot override the implementation.  As a result, some number types such as\r
172     BigInteger/BigDecimal are not handled by the ICU implementation.  If a client expects\r
173     NumberFormat#getXXXInstance returns a DecimalFormat (for example, need to manipulate\r
174     decimal format patterns), he/she can set true to this setting.  However, in this case,\r
175     BigInteger/BigDecimal support is not done by ICU's implementation.\r
176   </td>\r
177 </tr>\r
178 </table>\r
179 \r
180 <h3 class="doc"><a name="build"></a>Building and Testing ICU4J Locale Service Provider</h3>\r
181 \r
182 <p>ICU4J Locale Service Provider classes depend on the ICU4J core files.  To build the\r
183 component, you should build the ICU4J core JAR file first.  Please refer <a href="../readme.html">\r
184 ReadMe for ICU4J</a> to set up the build environment.  The actual steps building the\r
185 ICU4J Locale Service Provider JAR file are described below.  The examples used in these steps\r
186 assume the ICU4J source package is extracted to C:\icu4j on Microsoft Windows.</p>\r
187 <p>1. Build the ICU4J core JAR file (icu4j.jar).\r
188 <pre>\r
189   C:\icu4j>ant jar\r
190 </pre>\r
191 </p>\r
192 <p>2. Set JAVA_HOME to JDK 6.0.  The ICU4J Locale Service Provider requires JDK 6.0.\r
193 If you used JDK 6.0 for building the ICU4J core JAR file, this step is not necessary.\r
194 <pre>\r
195   C:\icu4j>set JAVA_HOME=C:\jdk1.6.0\r
196 </pre>\r
197 </p>\r
198 <p>3. Change directory to a subdirectory named "localespi"</p>\r
199 <p>4. Run <b>ant</b> with the default target ("jar").\r
200 <pre>\r
201   C:\icu4j\localespi>ant\r
202   Buildfile: build.xml\r
203 \r
204   check-env-java6:\r
205 \r
206   icu4j-jar:\r
207 \r
208   compile:\r
209       [mkdir] Created dir: C:\icu4j\localespi\classes\r
210       [javac] Compiling 22 source files to C:\icu4j\localespi\classes\r
211 \r
212   jar:\r
213         [jar] Building jar: C:\icu4j\localespi\icu4j-localespi.jar\r
214 \r
215   build-jar:\r
216 \r
217   BUILD SUCCESSFUL\r
218   Total time: 5 seconds\r
219 </pre>\r
220 </p>\r
221 <p>With above steps, icu4j-localespi.jar is created in localespi subdirectory.  To\r
222 verify the ICU4J Locale Service Provider component, you can run <b>ant</b> with the\r
223 target "check". (Note: The target "check" actually creates icu4j-localespi.jar, so\r
224 you can simply run this target to build and test the component.)\r
225 <pre>\r
226   C:\icu4j\localespi\ant check\r
227 </pre>\r
228 After compiling classes used for testing, the test cases for ICU4J Locale Service\r
229 Provider are executed.  The test output looks like below.\r
230 <pre>\r
231      [java] TestAll {\r
232      [java]   BreakIteratorTest {\r
233      [java]     TestGetInstance Passed\r
234      [java]     TestICUEquivalent Passed\r
235      [java]   } Passed\r
236      [java]   CollatorTest {\r
237      [java]     TestGetInstance Passed\r
238      [java]     TestICUEquivalent Passed\r
239      [java]   } Passed\r
240      [java]   CurrencyNameTest {\r
241      [java]     TestCurrencySymbols Passe\r
242      [java]   } Passed\r
243      [java]   DateFormatSymbolsTest {\r
244      [java]     TestGetInstance Passed\r
245      [java]     TestICUEquivalent Passed\r
246      [java]     TestNynorsk Passed\r
247      [java]     TestSetSymbols Passed\r
248      [java]   } Passed\r
249      [java]   DateFormatTest {\r
250      [java]     TestGetInstance Passed\r
251      [java]     TestICUEquivalent Passed\r
252      [java]     TestThaiDigit Passed\r
253      [java]   } Passed\r
254      [java]   DecimalFormatSymbolsTest {\r
255      [java]     TestGetInstance Passed\r
256      [java]     TestICUEquivalent Passed\r
257      [java]     TestSetSymbols Passed\r
258      [java]   } Passed\r
259      [java]   LocaleNameTest {\r
260      [java]     TestCountryNames Passed\r
261      [java]     TestLanguageNames Passed\r
262      [java]     TestVariantNames Passed\r
263      [java]   } Passed\r
264      [java]   NumberFormatTest {\r
265      [java]     TestGetInstance Passed\r
266      [java]     TestICUEquivalent Passed\r
267      [java]   } Passed\r
268      [java]   TimeZoneNameTest {\r
269      [java]     TestTimeZoneNames Passed\r
270      [java]   } Passed\r
271      [java] } Passed\r
272 </pre>\r
273 </p>\r
274 <p><I><font size="-1">Copyright &copy; 2008-2009 International Business\r
275 Machines Corporation and others. All Rights\r
276 Reserved.<br>\r
277 4400 North First Street, San Jos&eacute;, CA 95193, USA\r
278 </font></I></p>\r
279 </body>\r
280 </html>