1 8 package com.ibm.icu.util; 9 import java.util.ArrayList ; 10 import java.util.Arrays ; 11 import java.util.BitSet ; 12 import java.util.Date ; 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.LinkedList ; 16 import java.util.List ; 17 import java.util.Map ; 18 import java.util.MissingResourceException ; 19 import java.util.ResourceBundle ; 20 import java.util.TreeMap ; 21 import com.ibm.icu.impl.Utility; 26 import com.ibm.icu.impl.ZoneMeta; 27 import com.ibm.icu.text.BreakIterator; 28 import com.ibm.icu.text.Collator; 29 import com.ibm.icu.text.DateFormat; 30 import com.ibm.icu.text.NumberFormat; 31 import com.ibm.icu.text.SimpleDateFormat; 32 33 92 public class GlobalizationPreferences implements Freezable { 93 94 99 public GlobalizationPreferences(){} 100 105 public static final int 106 NF_NUMBER = 0, NF_CURRENCY = 1, NF_PERCENT = 2, NF_SCIENTIFIC = 3, NF_INTEGER = 4; 112 private static final int NF_LIMIT = NF_INTEGER + 1; 113 114 119 public static final int 120 DF_FULL = DateFormat.FULL, DF_LONG = DateFormat.LONG, DF_MEDIUM = DateFormat.MEDIUM, DF_SHORT = DateFormat.SHORT, DF_NONE = 4; 125 126 private static final int DF_LIMIT = DF_NONE + 1; 127 128 133 public static final int 134 ID_LOCALE = 0, 135 ID_LANGUAGE = 1, 136 ID_SCRIPT = 2, 137 ID_TERRITORY = 3, 138 ID_VARIANT = 4, 139 ID_KEYWORD = 5, 140 ID_KEYWORD_VALUE = 6, 141 ID_CURRENCY = 7, 142 ID_CURRENCY_SYMBOL = 8, 143 ID_TIMEZONE = 9; 144 145 private static final int ID_LIMIT = ID_TIMEZONE + 1; 146 147 152 public static final int 153 BI_CHARACTER = BreakIterator.KIND_CHARACTER, BI_WORD = BreakIterator.KIND_WORD, BI_LINE = BreakIterator.KIND_LINE, BI_SENTENCE = BreakIterator.KIND_SENTENCE, BI_TITLE = BreakIterator.KIND_TITLE; 159 private static final int BI_LIMIT = BI_TITLE + 1; 160 161 174 public GlobalizationPreferences setLocales(List inputLocales) { 175 if (isFrozen()) { 176 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 177 } 178 locales = processLocales(inputLocales); 179 return this; 180 } 181 182 189 public List getLocales() { 190 List result; 191 if (locales == null) { 192 result = guessLocales(); 193 } else { 194 result = new ArrayList (); 195 result.addAll(locales); 196 } 197 return result; 198 } 199 200 207 public ULocale getLocale(int index) { 208 List lcls = locales; 209 if (lcls == null) { 210 lcls = guessLocales(); 211 } 212 if (index >= 0 && index < lcls.size()) { 213 return (ULocale)lcls.get(index); 214 } 215 return null; 216 } 217 218 228 public GlobalizationPreferences setLocales(ULocale[] uLocales) { 229 if (isFrozen()) { 230 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 231 } 232 return setLocales(Arrays.asList(uLocales)); 233 } 234 235 245 public GlobalizationPreferences setLocale(ULocale uLocale) { 246 if (isFrozen()) { 247 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 248 } 249 return setLocales(new ULocale[]{uLocale}); 250 } 251 252 310 322 public ResourceBundle getResourceBundle(String baseName) { 323 return getResourceBundle(baseName, null); 324 } 325 326 339 public ResourceBundle getResourceBundle(String baseName, ClassLoader loader) { 340 UResourceBundle urb = null; 341 UResourceBundle candidate = null; 342 String actualLocaleName = null; 343 List fallbacks = getLocales(); 344 for (int i = 0; i < fallbacks.size(); i++) { 345 String localeName = ((ULocale)fallbacks.get(i)).toString(); 346 if (actualLocaleName != null && localeName.equals(actualLocaleName)) { 347 urb = candidate; 350 break; 351 } 352 try { 353 if (loader == null) { 354 candidate = UResourceBundle.getBundleInstance(baseName, localeName); 355 } 356 else { 357 candidate = UResourceBundle.getBundleInstance(baseName, localeName, loader); 358 } 359 if (candidate != null) { 360 actualLocaleName = candidate.getULocale().getName(); 361 if (actualLocaleName.equals(localeName)) { 362 urb = candidate; 363 break; 364 } 365 if (urb == null) { 366 urb = candidate; 368 } 369 } 370 } catch (MissingResourceException mre) { 371 actualLocaleName = null; 372 continue; 373 } 374 } 375 if (urb == null) { 376 throw new MissingResourceException ("Can't find bundle for base name " 377 + baseName, baseName, ""); 378 } 379 return urb; 380 } 381 382 394 public GlobalizationPreferences setTerritory(String territory) { 395 if (isFrozen()) { 396 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 397 } 398 this.territory = territory; return this; 400 } 401 402 410 public String getTerritory() { 411 if (territory == null) { 412 return guessTerritory(); 413 } 414 return territory; } 416 417 425 public GlobalizationPreferences setCurrency(Currency currency) { 426 if (isFrozen()) { 427 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 428 } 429 this.currency = currency; return this; 431 } 432 433 440 public Currency getCurrency() { 441 if (currency == null) { 442 return guessCurrency(); 443 } 444 return currency; } 446 447 455 public GlobalizationPreferences setCalendar(Calendar calendar) { 456 if (isFrozen()) { 457 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 458 } 459 this.calendar = (Calendar) calendar.clone(); return this; 461 } 462 463 470 public Calendar getCalendar() { 471 if (calendar == null) { 472 return guessCalendar(); 473 } 474 Calendar temp = (Calendar) calendar.clone(); temp.setTimeZone(getTimeZone()); 476 temp.setTimeInMillis(System.currentTimeMillis()); 477 return temp; 478 } 479 480 488 public GlobalizationPreferences setTimeZone(TimeZone timezone) { 489 if (isFrozen()) { 490 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 491 } 492 this.timezone = (TimeZone) timezone.clone(); return this; 494 } 495 496 504 public TimeZone getTimeZone() { 505 if (timezone == null) { 506 return guessTimeZone(); 507 } 508 return (TimeZone) timezone.clone(); } 510 511 518 public Collator getCollator() { 519 if (collator == null) { 520 return guessCollator(); 521 } 522 try { 523 return (Collator) collator.clone(); } catch (CloneNotSupportedException e) { 525 throw new IllegalStateException ("Error in cloning collator"); 526 } 527 } 528 529 536 public GlobalizationPreferences setCollator(Collator collator) { 537 if (isFrozen()) { 538 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 539 } 540 try { 541 this.collator = (Collator) collator.clone(); } catch (CloneNotSupportedException e) { 543 throw new IllegalStateException ("Error in cloning collator"); 544 } 545 return this; 546 } 547 548 558 public BreakIterator getBreakIterator(int type) { 559 if (type < BI_CHARACTER || type >= BI_LIMIT) { 560 throw new IllegalArgumentException ("Illegal break iterator type"); 561 } 562 if (breakIterators == null || breakIterators[type] == null) { 563 return guessBreakIterator(type); 564 } 565 return (BreakIterator) breakIterators[type].clone(); } 567 568 578 public GlobalizationPreferences setBreakIterator(int type, BreakIterator iterator) { 579 if (type < BI_CHARACTER || type >= BI_LIMIT) { 580 throw new IllegalArgumentException ("Illegal break iterator type"); 581 } 582 if (isFrozen()) { 583 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 584 } 585 if (breakIterators == null) 586 breakIterators = new BreakIterator[BI_LIMIT]; 587 breakIterators[type] = (BreakIterator) iterator.clone(); return this; 589 } 590 591 601 public String getDisplayName(String id, int type) { 602 String result = id; 603 for (Iterator it = getLocales().iterator(); it.hasNext();) { 604 ULocale locale = (ULocale) it.next(); 605 if (!isAvailableLocale(locale, TYPE_GENERIC)) { 606 continue; 607 } 608 switch (type) { 609 case ID_LOCALE: 610 result = ULocale.getDisplayName(id, locale); 611 break; 612 case ID_LANGUAGE: 613 result = ULocale.getDisplayLanguage(id, locale); 614 break; 615 case ID_SCRIPT: 616 result = ULocale.getDisplayScript("und-" + id, locale); 617 break; 618 case ID_TERRITORY: 619 result = ULocale.getDisplayCountry("und-" + id, locale); 620 break; 621 case ID_VARIANT: 622 result = ULocale.getDisplayVariant("und-QQ-" + id, locale); 624 break; 625 case ID_KEYWORD: 626 result = ULocale.getDisplayKeyword(id, locale); 627 break; 628 case ID_KEYWORD_VALUE: 629 String [] parts = new String [2]; 630 Utility.split(id,'=',parts); 631 result = ULocale.getDisplayKeywordValue("und@"+id, parts[0], locale); 632 if (result.equals(parts[1])) { 634 continue; 635 } 636 break; 637 case ID_CURRENCY_SYMBOL: 638 case ID_CURRENCY: 639 Currency temp = new Currency(id); 640 result =temp.getName(locale, type==ID_CURRENCY 641 ? Currency.LONG_NAME 642 : Currency.SYMBOL_NAME, new boolean[1]); 643 break; 649 case ID_TIMEZONE: 650 SimpleDateFormat dtf = new SimpleDateFormat("vvvv",locale); 651 dtf.setTimeZone(TimeZone.getTimeZone(id)); 652 result = dtf.format(new Date ()); 653 break; 661 default: 662 throw new IllegalArgumentException ("Unknown type: " + type); 663 } 664 665 if (!id.equals(result)) { 668 return result; 669 } 670 } 671 return result; 672 } 673 678 679 692 public GlobalizationPreferences setDateFormat(int dateStyle, int timeStyle, DateFormat format) { 693 if (isFrozen()) { 694 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 695 } 696 if (dateFormats == null) { 697 dateFormats = new DateFormat[DF_LIMIT][DF_LIMIT]; 698 } 699 dateFormats[dateStyle][timeStyle] = (DateFormat) format.clone(); return this; 701 } 702 703 716 public DateFormat getDateFormat(int dateStyle, int timeStyle) { 717 if (dateStyle == DF_NONE && timeStyle == DF_NONE 718 || dateStyle < 0 || dateStyle >= DF_LIMIT 719 || timeStyle < 0 || timeStyle >= DF_LIMIT) { 720 throw new IllegalArgumentException ("Illegal date format style arguments"); 721 } 722 DateFormat result = null; 723 if (dateFormats != null) { 724 result = dateFormats[dateStyle][timeStyle]; 725 } 726 if (result != null) { 727 result = (DateFormat) result.clone(); result.setTimeZone(getTimeZone()); 730 } else { 731 result = guessDateFormat(dateStyle, timeStyle); 732 } 733 return result; 734 } 735 736 746 public NumberFormat getNumberFormat(int style) { 747 if (style < 0 || style >= NF_LIMIT) { 748 throw new IllegalArgumentException ("Illegal number format type"); 749 } 750 NumberFormat result = null; 751 if (numberFormats != null) { 752 result = numberFormats[style]; 753 } 754 if (result != null) { 755 result = (NumberFormat) result.clone(); } else { 757 result = guessNumberFormat(style); 758 } 759 return result; 760 } 761 762 771 public GlobalizationPreferences setNumberFormat(int style, NumberFormat format) { 772 if (isFrozen()) { 773 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 774 } 775 if (numberFormats == null) { 776 numberFormats = new NumberFormat[NF_LIMIT]; 777 } 778 numberFormats[style] = (NumberFormat) format.clone(); return this; 780 } 781 782 789 public GlobalizationPreferences reset() { 790 if (isFrozen()) { 791 throw new UnsupportedOperationException ("Attempt to modify immutable object"); 792 } 793 locales = null; 794 territory = null; 795 calendar = null; 796 collator = null; 797 breakIterators = null; 798 timezone = null; 799 currency = null; 800 dateFormats = null; 801 numberFormats = null; 802 implicitLocales = null; 803 return this; 804 } 805 806 844 protected List processLocales(List inputLocales) { 845 List result = new ArrayList (); 846 854 for (int i = 0; i < inputLocales.size(); i++) { 855 ULocale uloc = (ULocale)inputLocales.get(i); 856 857 String language = uloc.getLanguage(); 858 String script = uloc.getScript(); 859 String country = uloc.getCountry(); 860 String variant = uloc.getVariant(); 861 862 boolean bInserted = false; 863 for (int j = 0; j < result.size(); j++) { 864 ULocale u = (ULocale)result.get(j); 868 if (!u.getLanguage().equals(language)) { 869 continue; 870 } 871 String s = u.getScript(); 872 String c = u.getCountry(); 873 String v = u.getVariant(); 874 if (!s.equals(script)) { 875 if (s.length() == 0 && c.length() == 0 && v.length() == 0) { 876 result.add(j, uloc); 877 bInserted = true; 878 break; 879 } else if (s.length() == 0 && c.equals(country)) { 880 result.add(j, uloc); 882 bInserted = true; 883 break; 884 } else if (script.length() == 0 && country.length() > 0 && c.length() == 0) { 885 result.add(j, uloc); 887 bInserted = true; 888 break; 889 } 890 continue; 891 } 892 if (!c.equals(country)) { 893 if (c.length() == 0 && v.length() == 0) { 894 result.add(j, uloc); 895 bInserted = true; 896 break; 897 } 898 } 899 if (!v.equals(variant) && v.length() == 0) { 900 result.add(j, uloc); 901 bInserted = true; 902 break; 903 } 904 } 905 if (!bInserted) { 906 result.add(uloc); 908 } 909 } 910 911 914 922 int index = 0; 923 while (index < result.size()) { 924 ULocale uloc = (ULocale)result.get(index); 925 while (true) { 926 uloc = uloc.getFallback(); 927 if (uloc.getLanguage().length() == 0) { 928 break; 929 } 930 index++; 931 result.add(index, uloc); 932 } 933 index++; 934 } 935 936 945 index = 0; 946 while (index < result.size() - 1) { 947 ULocale uloc = (ULocale)result.get(index); 948 boolean bRemoved = false; 949 for (int i = index + 1; i < result.size(); i++) { 950 if (uloc.equals((ULocale)result.get(i))) { 951 result.remove(index); 953 bRemoved = true; 954 break; 955 } 956 } 957 if (!bRemoved) { 958 index++; 959 } 960 } 961 return result; 962 } 963 964 965 975 protected DateFormat guessDateFormat(int dateStyle, int timeStyle) { 976 DateFormat result; 977 ULocale dfLocale = getAvailableLocale(TYPE_DATEFORMAT); 978 if (dfLocale == null) { 979 dfLocale = ULocale.ROOT; 980 } 981 if (timeStyle == DF_NONE) { 982 result = DateFormat.getDateInstance(getCalendar(), dateStyle, dfLocale); 983 } else if (dateStyle == DF_NONE) { 984 result = DateFormat.getTimeInstance(getCalendar(), timeStyle, dfLocale); 985 } else { 986 result = DateFormat.getDateTimeInstance(getCalendar(), dateStyle, timeStyle, dfLocale); 987 } 988 return result; 989 } 990 991 1000 protected NumberFormat guessNumberFormat(int style) { 1001 NumberFormat result; 1002 ULocale nfLocale = getAvailableLocale(TYPE_NUMBERFORMAT); 1003 if (nfLocale == null) { 1004 nfLocale = ULocale.ROOT; 1005 } 1006 switch (style) { 1007 case NF_NUMBER: 1008 result = NumberFormat.getInstance(nfLocale); 1009 break; 1010 case NF_SCIENTIFIC: 1011 result = NumberFormat.getScientificInstance(nfLocale); 1012 break; 1013 case NF_INTEGER: 1014 result = NumberFormat.getIntegerInstance(nfLocale); 1015 break; 1016 case NF_PERCENT: 1017 result = NumberFormat.getPercentInstance(nfLocale); 1018 break; 1019 case NF_CURRENCY: 1020 result = NumberFormat.getCurrencyInstance(nfLocale); 1021 result.setCurrency(getCurrency()); 1022 break; 1023 default: 1024 throw new IllegalArgumentException ("Unknown number format style"); 1025 } 1026 return result; 1027 } 1028 1029 1035 protected String guessTerritory() { 1036 String result; 1037 for (Iterator it = getLocales().iterator(); it.hasNext();) { 1039 ULocale locale = (ULocale)it.next(); 1040 result = locale.getCountry(); 1041 if (result.length() != 0) { 1042 return result; 1043 } 1044 } 1045 ULocale firstLocale = getLocale(0); 1050 String language = firstLocale.getLanguage(); 1051 String script = firstLocale.getScript(); 1052 result = null; 1053 if (script.length() != 0) { 1054 result = (String ) language_territory_hack_map.get(language + "_" + script); 1055 } 1056 if (result == null) { 1057 result = (String ) language_territory_hack_map.get(language); 1058 } 1059 if (result == null) { 1060 result = "US"; } 1062 return result; 1063 } 1064 1065 1071 protected Currency guessCurrency() { 1072 return Currency.getInstance(new ULocale("und-" + getTerritory())); 1073 } 1074 1075 1083 protected List guessLocales() { 1084 if (implicitLocales == null) { 1085 List result = new ArrayList (1); 1086 result.add(ULocale.getDefault()); 1087 implicitLocales = processLocales(result); 1088 } 1089 return implicitLocales; 1090 } 1091 1092 1100 protected Collator guessCollator() { 1101 ULocale collLocale = getAvailableLocale(TYPE_COLLATOR); 1102 if (collLocale == null) { 1103 collLocale = ULocale.ROOT; 1104 } 1105 return Collator.getInstance(collLocale); 1106 } 1107 1108 1117 protected BreakIterator guessBreakIterator(int type) { 1118 BreakIterator bitr = null; 1119 ULocale brkLocale = getAvailableLocale(TYPE_BREAKITERATOR); 1120 if (brkLocale == null) { 1121 brkLocale = ULocale.ROOT; 1122 } 1123 switch (type) { 1124 case BI_CHARACTER: 1125 bitr = BreakIterator.getCharacterInstance(brkLocale); 1126 break; 1127 case BI_TITLE: 1128 bitr = BreakIterator.getTitleInstance(brkLocale); 1129 break; 1130 case BI_WORD: 1131 bitr = BreakIterator.getWordInstance(brkLocale); 1132 break; 1133 case BI_LINE: 1134 bitr = BreakIterator.getLineInstance(brkLocale); 1135 break; 1136 case BI_SENTENCE: 1137 bitr = BreakIterator.getSentenceInstance(brkLocale); 1138 break; 1139 default: 1140 throw new IllegalArgumentException ("Unknown break iterator type"); 1141 } 1142 return bitr; 1143 } 1144 1145 1153 protected TimeZone guessTimeZone() { 1154 String timezoneString = (String ) territory_tzid_hack_map.get(getTerritory()); 1162 if (timezoneString == null) { 1163 String [] attempt = ZoneMeta.getAvailableIDs(getTerritory()); 1164 if (attempt.length == 0) { 1165 timezoneString = "Etc/GMT"; } else { 1167 int i; 1168 for (i = 0; i < attempt.length; ++i) { 1170 if (attempt[i].indexOf("/") >= 0) break; 1171 } 1172 if (i > attempt.length) i = 0; 1173 timezoneString = attempt[i]; 1174 } 1175 } 1176 return TimeZone.getTimeZone(timezoneString); 1177 } 1178 1179 1187 protected Calendar guessCalendar() { 1188 ULocale calLocale = getAvailableLocale(TYPE_CALENDAR); 1189 if (calLocale == null) { 1190 calLocale = ULocale.US; 1191 } 1192 return Calendar.getInstance(getTimeZone(), calLocale); 1193 } 1194 1195 1197 private List locales; 1198 private String territory; 1199 private Currency currency; 1200 private TimeZone timezone; 1201 private Calendar calendar; 1202 private Collator collator; 1203 private BreakIterator[] breakIterators; 1204 private DateFormat[][] dateFormats; 1205 private NumberFormat[] numberFormats; 1206 private List implicitLocales; 1207 1208 { 1209 reset(); 1210 } 1211 1212 1213 private ULocale getAvailableLocale(int type) { 1214 List locs = getLocales(); 1215 ULocale result = null; 1216 for (int i = 0; i < locs.size(); i++) { 1217 ULocale l = (ULocale)locs.get(i); 1218 if (isAvailableLocale(l, type)) { 1219 result = l; 1220 break; 1221 } 1222 } 1223 return result; 1224 } 1225 1226 private boolean isAvailableLocale(ULocale loc, int type) { 1227 BitSet bits = (BitSet )available_locales.get(loc); 1228 if (bits != null && bits.get(type)) { 1229 return true; 1230 } 1231 return false; 1232 } 1233 1234 1237 private static final HashMap available_locales = new HashMap (); 1238 private static final int 1239 TYPE_GENERIC = 0, 1240 TYPE_CALENDAR = 1, 1241 TYPE_DATEFORMAT= 2, 1242 TYPE_NUMBERFORMAT = 3, 1243 TYPE_COLLATOR = 4, 1244 TYPE_BREAKITERATOR = 5, 1245 TYPE_LIMIT = TYPE_BREAKITERATOR + 1; 1246 1247 static { 1248 BitSet bits; 1249 ULocale[] allLocales = ULocale.getAvailableLocales(); 1250 for (int i = 0; i < allLocales.length; i++) { 1251 bits = new BitSet (TYPE_LIMIT); 1252 available_locales.put(allLocales[i], bits); 1253 bits.set(TYPE_GENERIC); 1254 } 1255 1256 ULocale[] calLocales = Calendar.getAvailableULocales(); 1257 for (int i = 0; i < calLocales.length; i++) { 1258 bits = (BitSet )available_locales.get(calLocales[i]); 1259 if (bits == null) { 1260 bits = new BitSet (TYPE_LIMIT); 1261 available_locales.put(allLocales[i], bits); 1262 } 1263 bits.set(TYPE_CALENDAR); 1264 } 1265 1266 ULocale[] dateLocales = DateFormat.getAvailableULocales(); 1267 for (int i = 0; i < dateLocales.length; i++) { 1268 bits = (BitSet )available_locales.get(dateLocales[i]); 1269 if (bits == null) { 1270 bits = new BitSet (TYPE_LIMIT); 1271 available_locales.put(allLocales[i], bits); 1272 } 1273 bits.set(TYPE_DATEFORMAT); 1274 } 1275 1276 ULocale[] numLocales = NumberFormat.getAvailableULocales(); 1277 for (int i = 0; i < numLocales.length; i++) { 1278 bits = (BitSet )available_locales.get(numLocales[i]); 1279 if (bits == null) { 1280 bits = new BitSet (TYPE_LIMIT); 1281 available_locales.put(allLocales[i], bits); 1282 } 1283 bits.set(TYPE_NUMBERFORMAT); 1284 } 1285 1286 ULocale[] collLocales = Collator.getAvailableULocales(); 1287 for (int i = 0; i < collLocales.length; i++) { 1288 bits = (BitSet )available_locales.get(collLocales[i]); 1289 if (bits == null) { 1290 bits = new BitSet (TYPE_LIMIT); 1291 available_locales.put(allLocales[i], bits); 1292 } 1293 bits.set(TYPE_COLLATOR); 1294 } 1295 1296 ULocale[] brkLocales = BreakIterator.getAvailableULocales(); 1297 for (int i = 0; i < brkLocales.length; i++) { 1298 bits = (BitSet )available_locales.get(brkLocales[i]); 1299 bits.set(TYPE_BREAKITERATOR); 1300 } 1301 } 1302 1303 1306 private static final Map language_territory_hack_map = new HashMap (); 1307 private static final String [][] language_territory_hack = { 1308 {"af", "ZA"}, 1309 {"am", "ET"}, 1310 {"ar", "SA"}, 1311 {"as", "IN"}, 1312 {"ay", "PE"}, 1313 {"az", "AZ"}, 1314 {"bal", "PK"}, 1315 {"be", "BY"}, 1316 {"bg", "BG"}, 1317 {"bn", "IN"}, 1318 {"bs", "BA"}, 1319 {"ca", "ES"}, 1320 {"ch", "MP"}, 1321 {"cpe", "SL"}, 1322 {"cs", "CZ"}, 1323 {"cy", "GB"}, 1324 {"da", "DK"}, 1325 {"de", "DE"}, 1326 {"dv", "MV"}, 1327 {"dz", "BT"}, 1328 {"el", "GR"}, 1329 {"en", "US"}, 1330 {"es", "ES"}, 1331 {"et", "EE"}, 1332 {"eu", "ES"}, 1333 {"fa", "IR"}, 1334 {"fi", "FI"}, 1335 {"fil", "PH"}, 1336 {"fj", "FJ"}, 1337 {"fo", "FO"}, 1338 {"fr", "FR"}, 1339 {"ga", "IE"}, 1340 {"gd", "GB"}, 1341 {"gl", "ES"}, 1342 {"gn", "PY"}, 1343 {"gu", "IN"}, 1344 {"gv", "GB"}, 1345 {"ha", "NG"}, 1346 {"he", "IL"}, 1347 {"hi", "IN"}, 1348 {"ho", "PG"}, 1349 {"hr", "HR"}, 1350 {"ht", "HT"}, 1351 {"hu", "HU"}, 1352 {"hy", "AM"}, 1353 {"id", "ID"}, 1354 {"is", "IS"}, 1355 {"it", "IT"}, 1356 {"ja", "JP"}, 1357 {"ka", "GE"}, 1358 {"kk", "KZ"}, 1359 {"kl", "GL"}, 1360 {"km", "KH"}, 1361 {"kn", "IN"}, 1362 {"ko", "KR"}, 1363 {"kok", "IN"}, 1364 {"ks", "IN"}, 1365 {"ku", "TR"}, 1366 {"ky", "KG"}, 1367 {"la", "VA"}, 1368 {"lb", "LU"}, 1369 {"ln", "CG"}, 1370 {"lo", "LA"}, 1371 {"lt", "LT"}, 1372 {"lv", "LV"}, 1373 {"mai", "IN"}, 1374 {"men", "GN"}, 1375 {"mg", "MG"}, 1376 {"mh", "MH"}, 1377 {"mk", "MK"}, 1378 {"ml", "IN"}, 1379 {"mn", "MN"}, 1380 {"mni", "IN"}, 1381 {"mo", "MD"}, 1382 {"mr", "IN"}, 1383 {"ms", "MY"}, 1384 {"mt", "MT"}, 1385 {"my", "MM"}, 1386 {"na", "NR"}, 1387 {"nb", "NO"}, 1388 {"nd", "ZA"}, 1389 {"ne", "NP"}, 1390 {"niu", "NU"}, 1391 {"nl", "NL"}, 1392 {"nn", "NO"}, 1393 {"no", "NO"}, 1394 {"nr", "ZA"}, 1395 {"nso", "ZA"}, 1396 {"ny", "MW"}, 1397 {"om", "KE"}, 1398 {"or", "IN"}, 1399 {"pa", "IN"}, 1400 {"pau", "PW"}, 1401 {"pl", "PL"}, 1402 {"ps", "PK"}, 1403 {"pt", "BR"}, 1404 {"qu", "PE"}, 1405 {"rn", "BI"}, 1406 {"ro", "RO"}, 1407 {"ru", "RU"}, 1408 {"rw", "RW"}, 1409 {"sd", "IN"}, 1410 {"sg", "CF"}, 1411 {"si", "LK"}, 1412 {"sk", "SK"}, 1413 {"sl", "SI"}, 1414 {"sm", "WS"}, 1415 {"so", "DJ"}, 1416 {"sq", "CS"}, 1417 {"sr", "CS"}, 1418 {"ss", "ZA"}, 1419 {"st", "ZA"}, 1420 {"sv", "SE"}, 1421 {"sw", "KE"}, 1422 {"ta", "IN"}, 1423 {"te", "IN"}, 1424 {"tem", "SL"}, 1425 {"tet", "TL"}, 1426 {"th", "TH"}, 1427 {"ti", "ET"}, 1428 {"tg", "TJ"}, 1429 {"tk", "TM"}, 1430 {"tkl", "TK"}, 1431 {"tvl", "TV"}, 1432 {"tl", "PH"}, 1433 {"tn", "ZA"}, 1434 {"to", "TO"}, 1435 {"tpi", "PG"}, 1436 {"tr", "TR"}, 1437 {"ts", "ZA"}, 1438 {"uk", "UA"}, 1439 {"ur", "IN"}, 1440 {"uz", "UZ"}, 1441 {"ve", "ZA"}, 1442 {"vi", "VN"}, 1443 {"wo", "SN"}, 1444 {"xh", "ZA"}, 1445 {"zh", "CN"}, 1446 {"zh_Hant", "TW"}, 1447 {"zu", "ZA"}, 1448 {"aa", "ET"}, 1449 {"byn", "ER"}, 1450 {"eo", "DE"}, 1451 {"gez", "ET"}, 1452 {"haw", "US"}, 1453 {"iu", "CA"}, 1454 {"kw", "GB"}, 1455 {"sa", "IN"}, 1456 {"sh", "HR"}, 1457 {"sid", "ET"}, 1458 {"syr", "SY"}, 1459 {"tig", "ER"}, 1460 {"tt", "RU"}, 1461 {"wal", "ET"}, }; 1462 static { 1463 for (int i = 0; i < language_territory_hack.length; ++i) { 1464 language_territory_hack_map.put(language_territory_hack[i][0],language_territory_hack[i][1]); 1465 } 1466 } 1467 1468 static final Map territory_tzid_hack_map = new HashMap (); 1469 static final String [][] territory_tzid_hack = { 1470 {"AQ", "Antarctica/McMurdo"}, 1471 {"AR", "America/Buenos_Aires"}, 1472 {"AU", "Australia/Sydney"}, 1473 {"BR", "America/Sao_Paulo"}, 1474 {"CA", "America/Toronto"}, 1475 {"CD", "Africa/Kinshasa"}, 1476 {"CL", "America/Santiago"}, 1477 {"CN", "Asia/Shanghai"}, 1478 {"EC", "America/Guayaquil"}, 1479 {"ES", "Europe/Madrid"}, 1480 {"GB", "Europe/London"}, 1481 {"GL", "America/Godthab"}, 1482 {"ID", "Asia/Jakarta"}, 1483 {"ML", "Africa/Bamako"}, 1484 {"MX", "America/Mexico_City"}, 1485 {"MY", "Asia/Kuala_Lumpur"}, 1486 {"NZ", "Pacific/Auckland"}, 1487 {"PT", "Europe/Lisbon"}, 1488 {"RU", "Europe/Moscow"}, 1489 {"UA", "Europe/Kiev"}, 1490 {"US", "America/New_York"}, 1491 {"UZ", "Asia/Tashkent"}, 1492 {"PF", "Pacific/Tahiti"}, 1493 {"FM", "Pacific/Kosrae"}, 1494 {"KI", "Pacific/Tarawa"}, 1495 {"KZ", "Asia/Almaty"}, 1496 {"MH", "Pacific/Majuro"}, 1497 {"MN", "Asia/Ulaanbaatar"}, 1498 {"SJ", "Arctic/Longyearbyen"}, 1499 {"UM", "Pacific/Midway"}, 1500 }; 1501 static { 1502 for (int i = 0; i < territory_tzid_hack.length; ++i) { 1503 territory_tzid_hack_map.put(territory_tzid_hack[i][0],territory_tzid_hack[i][1]); 1504 } 1505 } 1506 1507 1509 private boolean frozen; 1510 1511 1515 public boolean isFrozen() { 1516 return frozen; 1517 } 1518 1519 1523 public Object freeze() { 1524 frozen = true; 1525 return this; 1526 } 1527 1528 1532 public Object cloneAsThawed() { 1533 try { 1534 GlobalizationPreferences result = (GlobalizationPreferences) clone(); 1535 result.frozen = false; 1536 return result; 1537 } catch (CloneNotSupportedException e) { 1538 return null; 1540 } 1541 } 1542} 1543 1544 | Popular Tags |