1475 *
1476 * <pre>
1477 * Locale.forLanguageTag("ar-aao").getLanguage(); // returns "aao"
1478 * Locale.forLanguageTag("en-abc-def-us").toString(); // returns "abc_US"
1479 * </pre>
1480 *
1481 * <li>Case is normalized except for variant tags, which are left
1482 * unchanged. Language is normalized to lower case, script to
1483 * title case, country to upper case, and extensions to lower
1484 * case.
1485 *
1486 * <li>If, after processing, the locale would exactly match either
1487 * ja_JP_JP or th_TH_TH with no extensions, the appropriate
1488 * extensions are added as though the constructor had been called:
1489 *
1490 * <pre>
1491 * Locale.forLanguageTag("ja-JP-x-lvariant-JP").toLanguageTag();
1492 * // returns "ja-JP-u-ca-japanese-x-lvariant-JP"
1493 * Locale.forLanguageTag("th-TH-x-lvariant-TH").toLanguageTag();
1494 * // returns "th-TH-u-nu-thai-x-lvariant-TH"
1495 * <pre></ul>
1496 *
1497 * <p>This implements the 'Language-Tag' production of BCP47, and
1498 * so supports grandfathered (regular and irregular) as well as
1499 * private use language tags. Stand alone private use tags are
1500 * represented as empty language and extension 'x-whatever',
1501 * and grandfathered tags are converted to their canonical replacements
1502 * where they exist.
1503 *
1504 * <p>Grandfathered tags with canonical replacements are as follows:
1505 *
1506 * <table>
1507 * <tbody align="center">
1508 * <tr><th>grandfathered tag</th><th> </th><th>modern replacement</th></tr>
1509 * <tr><td>art-lojban</td><td> </td><td>jbo</td></tr>
1510 * <tr><td>i-ami</td><td> </td><td>ami</td></tr>
1511 * <tr><td>i-bnn</td><td> </td><td>bnn</td></tr>
1512 * <tr><td>i-hak</td><td> </td><td>hak</td></tr>
1513 * <tr><td>i-klingon</td><td> </td><td>tlh</td></tr>
1514 * <tr><td>i-lux</td><td> </td><td>lb</td></tr>
1515 * <tr><td>i-navajo</td><td> </td><td>nv</td></tr>
2126 * @param out the <code>ObjectOutputStream</code> to write
2127 * @throws IOException
2128 * @since 1.7
2129 */
2130 private void writeObject(ObjectOutputStream out) throws IOException {
2131 ObjectOutputStream.PutField fields = out.putFields();
2132 fields.put("language", baseLocale.getLanguage());
2133 fields.put("script", baseLocale.getScript());
2134 fields.put("country", baseLocale.getRegion());
2135 fields.put("variant", baseLocale.getVariant());
2136 fields.put("extensions", localeExtensions == null ? "" : localeExtensions.getID());
2137 fields.put("hashcode", -1); // place holder just for backward support
2138 out.writeFields();
2139 }
2140
2141 /**
2142 * Deserializes this <code>Locale</code>.
2143 * @param in the <code>ObjectInputStream</code> to read
2144 * @throws IOException
2145 * @throws ClassNotFoundException
2146 * @throws IllformdLocaleException
2147 * @since 1.7
2148 */
2149 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
2150 ObjectInputStream.GetField fields = in.readFields();
2151 String language = (String)fields.get("language", "");
2152 String script = (String)fields.get("script", "");
2153 String country = (String)fields.get("country", "");
2154 String variant = (String)fields.get("variant", "");
2155 String extStr = (String)fields.get("extensions", "");
2156 baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant);
2157 if (extStr.length() > 0) {
2158 try {
2159 InternalLocaleBuilder bldr = new InternalLocaleBuilder();
2160 bldr.setExtensions(extStr);
2161 localeExtensions = bldr.getLocaleExtensions();
2162 } catch (LocaleSyntaxException e) {
2163 throw new IllformedLocaleException(e.getMessage());
2164 }
2165 } else {
2166 localeExtensions = null;
|
1475 *
1476 * <pre>
1477 * Locale.forLanguageTag("ar-aao").getLanguage(); // returns "aao"
1478 * Locale.forLanguageTag("en-abc-def-us").toString(); // returns "abc_US"
1479 * </pre>
1480 *
1481 * <li>Case is normalized except for variant tags, which are left
1482 * unchanged. Language is normalized to lower case, script to
1483 * title case, country to upper case, and extensions to lower
1484 * case.
1485 *
1486 * <li>If, after processing, the locale would exactly match either
1487 * ja_JP_JP or th_TH_TH with no extensions, the appropriate
1488 * extensions are added as though the constructor had been called:
1489 *
1490 * <pre>
1491 * Locale.forLanguageTag("ja-JP-x-lvariant-JP").toLanguageTag();
1492 * // returns "ja-JP-u-ca-japanese-x-lvariant-JP"
1493 * Locale.forLanguageTag("th-TH-x-lvariant-TH").toLanguageTag();
1494 * // returns "th-TH-u-nu-thai-x-lvariant-TH"
1495 * </pre></ul>
1496 *
1497 * <p>This implements the 'Language-Tag' production of BCP47, and
1498 * so supports grandfathered (regular and irregular) as well as
1499 * private use language tags. Stand alone private use tags are
1500 * represented as empty language and extension 'x-whatever',
1501 * and grandfathered tags are converted to their canonical replacements
1502 * where they exist.
1503 *
1504 * <p>Grandfathered tags with canonical replacements are as follows:
1505 *
1506 * <table>
1507 * <tbody align="center">
1508 * <tr><th>grandfathered tag</th><th> </th><th>modern replacement</th></tr>
1509 * <tr><td>art-lojban</td><td> </td><td>jbo</td></tr>
1510 * <tr><td>i-ami</td><td> </td><td>ami</td></tr>
1511 * <tr><td>i-bnn</td><td> </td><td>bnn</td></tr>
1512 * <tr><td>i-hak</td><td> </td><td>hak</td></tr>
1513 * <tr><td>i-klingon</td><td> </td><td>tlh</td></tr>
1514 * <tr><td>i-lux</td><td> </td><td>lb</td></tr>
1515 * <tr><td>i-navajo</td><td> </td><td>nv</td></tr>
2126 * @param out the <code>ObjectOutputStream</code> to write
2127 * @throws IOException
2128 * @since 1.7
2129 */
2130 private void writeObject(ObjectOutputStream out) throws IOException {
2131 ObjectOutputStream.PutField fields = out.putFields();
2132 fields.put("language", baseLocale.getLanguage());
2133 fields.put("script", baseLocale.getScript());
2134 fields.put("country", baseLocale.getRegion());
2135 fields.put("variant", baseLocale.getVariant());
2136 fields.put("extensions", localeExtensions == null ? "" : localeExtensions.getID());
2137 fields.put("hashcode", -1); // place holder just for backward support
2138 out.writeFields();
2139 }
2140
2141 /**
2142 * Deserializes this <code>Locale</code>.
2143 * @param in the <code>ObjectInputStream</code> to read
2144 * @throws IOException
2145 * @throws ClassNotFoundException
2146 * @throws IllformedLocaleException
2147 * @since 1.7
2148 */
2149 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
2150 ObjectInputStream.GetField fields = in.readFields();
2151 String language = (String)fields.get("language", "");
2152 String script = (String)fields.get("script", "");
2153 String country = (String)fields.get("country", "");
2154 String variant = (String)fields.get("variant", "");
2155 String extStr = (String)fields.get("extensions", "");
2156 baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant);
2157 if (extStr.length() > 0) {
2158 try {
2159 InternalLocaleBuilder bldr = new InternalLocaleBuilder();
2160 bldr.setExtensions(extStr);
2161 localeExtensions = bldr.getLocaleExtensions();
2162 } catch (LocaleSyntaxException e) {
2163 throw new IllformedLocaleException(e.getMessage());
2164 }
2165 } else {
2166 localeExtensions = null;
|