1 package org.unicode.cldr.util; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 6 import org.unicode.cldr.icu.LDMLConstants; 7 8 /** 9 * @deprecated 10 */ 11 public class PathUtilities { 12 13 // ===== types of data and menu names 14 public static final String LOCALEDISPLAYNAMES = "//ldml/localeDisplayNames/"; 15 /** 16 * All of the data items under LOCALEDISPLAYNAMES (menu items) 17 */ 18 public static final String LOCALEDISPLAYNAMES_ITEMS[] = { LDMLConstants.LANGUAGES, 19 LDMLConstants.SCRIPTS, LDMLConstants.TERRITORIES, LDMLConstants.VARIANTS, LDMLConstants.KEYS, 20 LDMLConstants.TYPES, PathUtilities.CURRENCIES, PathUtilities.TIMEZONES, 21 PathUtilities.CODEPATTERNS, PathUtilities.MEASNAMES }; 22 public static final String OTHER_CALENDARS_XPATH = "//ldml/dates/calendars/calendar"; 23 24 public static final String LOCALEDISPLAYPATTERN_XPATH = LOCALEDISPLAYNAMES 25 + LDMLConstants.LOCALEDISPLAYPATTERN; 26 public static final String NUMBERSCURRENCIES = LDMLConstants.NUMBERS + "/" 27 + PathUtilities.CURRENCIES; 28 public static final String CURRENCIES = "currencies"; 29 public static final String TIMEZONES = "timezones"; 30 public static final String METAZONES = "metazones"; 31 public static String xOTHER = "misc"; 32 public static final String CODEPATTERNS = "codePatterns"; 33 public static final String MEASNAMES = "measurementSystemNames"; 34 xpathToMenu(String path)35 public static String xpathToMenu(String path) { 36 String theMenu = null; 37 if (path.startsWith(LOCALEDISPLAYNAMES)) { 38 for (int i = 0; i < LOCALEDISPLAYNAMES_ITEMS.length; i++) { 39 if (path.startsWith(LOCALEDISPLAYNAMES 40 + LOCALEDISPLAYNAMES_ITEMS[i])) { 41 theMenu = LOCALEDISPLAYNAMES_ITEMS[i]; 42 } 43 } 44 if (path.startsWith(LOCALEDISPLAYPATTERN_XPATH)) { 45 theMenu = LDMLConstants.LOCALEDISPLAYPATTERN; 46 } 47 // } else if(path.startsWith(GREGO_XPATH)) { 48 // theMenu=GREGORIAN_CALENDAR; 49 } else if (path.startsWith(OTHER_CALENDARS_XPATH)) { 50 String items[] = getCalendarsItems(); 51 for (String which : items) { 52 String CAL_XPATH = "//ldml/dates/calendars/calendar[@type=\"" + which + "\"]"; 53 if (path.startsWith(CAL_XPATH)) { 54 theMenu = which; 55 break; 56 } 57 } 58 } else if (path.startsWith(LOCALEDISPLAYPATTERN_XPATH)) { 59 theMenu = LDMLConstants.LOCALEDISPLAYPATTERN; 60 } else if (path.startsWith("//ldml/" + NUMBERSCURRENCIES)) { 61 theMenu = CURRENCIES; 62 } else if (path.startsWith("//ldml/" + "dates/timeZoneNames/zone")) { 63 theMenu = TIMEZONES; 64 } else if (path.startsWith("//ldml/" + "units")) { 65 theMenu = "units"; 66 } else if (path.startsWith("//ldml/" + "dates/timeZoneNames/metazone")) { 67 theMenu = getMetazoneContinent(path); 68 if (theMenu == null) { 69 theMenu = METAZONES; 70 } 71 } else if (path.startsWith("//ldml/" + LDMLConstants.CHARACTERS + "/" + LDMLConstants.EXEMPLAR_CHARACTERS)) { 72 theMenu = LDMLConstants.CHARACTERS; 73 } else if (path.startsWith("//ldml/" + LDMLConstants.NUMBERS)) { 74 theMenu = LDMLConstants.NUMBERS; 75 } else if (path.startsWith("//ldml/" + LDMLConstants.REFERENCES)) { 76 theMenu = LDMLConstants.REFERENCES; 77 } else { 78 theMenu = xOTHER; 79 // other? 80 } 81 return theMenu; 82 } 83 getCalendarsItems()84 public static String[] getCalendarsItems() { 85 // TODO : Make this data driven from supplementalMetaData ; 86 // I couldn't get the xpath right.... 87 // CLDRFile mySupp = getFactory().make("supplementalMetaData",false); 88 // String xpath = 89 // "//supplementalData/metadata/validity/variable[@id=\"$calendar\"][@type=\"choice\"]"; 90 // String items = mySupp.getStringValue(xpath); 91 // if ( items != null ) { 92 // return (items.split(" ")); 93 // } 94 // else { 95 96 String defaultCalendarsItems = "gregorian buddhist coptic ethiopic chinese hebrew indian islamic japanese persian roc"; 97 return (defaultCalendarsItems.split(" ")); 98 99 // } 100 } 101 getMetazonesItems()102 public static String[] getMetazonesItems() { 103 String defaultMetazonesItems = "Africa America Antarctica Asia Australia Europe Atlantic Indian Pacific"; 104 return (defaultMetazonesItems.split(" ")); 105 } 106 107 private static Map<String, String> mzXpathToContinent = new HashMap<String, String>(); 108 getMetazoneContinent(String xpath)109 private synchronized static String getMetazoneContinent(String xpath) { 110 String continent = mzXpathToContinent.get(xpath); 111 if (continent == null) { 112 XPathParts parts = new XPathParts(null, null); 113 // SupplementalDataInfo mySupp = getSupplementalDataInfo(); 114 parts.set(xpath); 115 String thisMetazone = parts.getAttributeValue(3, "type"); 116 continent = getMetazoneToContinentMap().get(thisMetazone); 117 } 118 return continent; 119 } 120 121 static Map<String, String> mzToContinentMap = null; 122 getMetazoneToContinentMap()123 private static Map<String, String> getMetazoneToContinentMap() { 124 if (mzToContinentMap == null) { 125 System.err 126 .println( 127 "PathUtilities.java getMetazoneToContinentMap(): TODO: Get this data from supplemental data! http://unicode.org/cldr/trac/ticket/3761"); 128 HashMap<String, String> newMap = new HashMap<String, String>(); 129 for (int i = 0; i < mzToContinentStatic.length; i += 2) { 130 newMap.put(mzToContinentStatic[i + 0], mzToContinentStatic[i + 1]); 131 } 132 mzToContinentMap = newMap; 133 } 134 return mzToContinentMap; 135 } 136 137 private static final String mzToContinentStatic[] = { 138 139 "Philippines", "Asia", 140 "Gambier", "Pacific", 141 "Ecuador", "America", 142 "Kuybyshev", "Europe", 143 "Europe_Western", "Atlantic", 144 "Chile", "America", 145 "Afghanistan", "Asia", 146 "Pierre_Miquelon", "America", 147 "Solomon", "Pacific", 148 "Arabian", "Asia", 149 "Krasnoyarsk", "Asia", 150 "Vladivostok", "Asia", 151 "Fiji", "Pacific", 152 "Niue", "Pacific", 153 "Marquesas", "Pacific", 154 "Karachi", "Asia", 155 "Aqtobe", "Asia", 156 "Irish", "Europe", 157 "Yakutsk", "Asia", 158 "Galapagos", "Pacific", 159 "Bangladesh", "Asia", 160 "America_Pacific", "America", 161 "Urumqi", "Asia", 162 "Tahiti", "Pacific", 163 "Samoa", "Pacific", 164 "Uzbekistan", "Asia", 165 "Turkey", "Europe", 166 "Kyrgystan", "Asia", 167 "Europe_Eastern", "Europe", 168 "Casey", "Antarctica", 169 "Lord_Howe", "Australia", 170 "Kizilorda", "Asia", 171 "Kashgar", "Asia", 172 "Africa_Western", "Africa", 173 "Macquarie", "Antarctica", 174 "Wake", "Pacific", 175 "Australia_Eastern", "Australia", 176 "Guyana", "America", 177 "Taipei", "Asia", 178 "Samarkand", "Asia", 179 "Mawson", "Antarctica", 180 "Africa_Eastern", "Africa", 181 "Guam", "Pacific", 182 "Kazakhstan_Western", "Asia", 183 "Aqtau", "Asia", 184 "Cook", "Pacific", 185 "Wallis", "Pacific", 186 "Irkutsk", "Asia", 187 "Africa_Southern", "Africa", 188 "French_Guiana", "America", 189 "Chatham", "Pacific", 190 "Oral", "Asia", 191 "Noronha", "America", 192 "Paraguay", "America", 193 "Moscow", "Europe", 194 "Hong_Kong", "Asia", 195 "Yerevan", "Asia", 196 "Vostok", "Antarctica", 197 "Rothera", "Antarctica", 198 "Colombia", "America", 199 "Newfoundland", "America", 200 "Hawaii_Aleutian", "Pacific", 201 "East_Timor", "Asia", 202 "GMT", "Atlantic", 203 "Indian_Ocean", "Indian", 204 "Reunion", "Indian", 205 "Vanuatu", "Pacific", 206 "Malaysia", "Asia", 207 "Kwajalein", "Pacific", 208 "Line_Islands", "Pacific", 209 "Shevchenko", "Asia", 210 "Azores", "Atlantic", 211 "Frunze", "Asia", 212 "Greenland_Eastern", "America", 213 "Hovd", "Asia", 214 "Lanka", "Asia", 215 "Almaty", "Asia", 216 "Macau", "Asia", 217 "Mongolia", "Asia", 218 "Easter", "Pacific", 219 "British", "Europe", 220 "Korea", "Asia", 221 "Papua_New_Guinea", "Pacific", 222 "Bering", "America", 223 "Cocos", "Indian", 224 "Mauritius", "Indian", 225 "Argentina", "America", 226 "Tokelau", "Pacific", 227 "America_Central", "America", 228 "Alaska", "America", 229 "Georgia", "Asia", 230 "Choibalsan", "Asia", 231 "Sakhalin", "Asia", 232 "Anadyr", "Asia", 233 "Dushanbe", "Asia", 234 "Indonesia_Eastern", "Asia", 235 "Japan", "Asia", 236 "Omsk", "Asia", 237 "Nauru", "Pacific", 238 "Cuba", "America", 239 "Iran", "Asia", 240 "Sverdlovsk", "Asia", 241 "Maldives", "Indian", 242 "Europe_Central", "Europe", 243 "Kamchatka", "Asia", 244 "Tajikistan", "Asia", 245 "Pitcairn", "Pacific", 246 "Gilbert_Islands", "Pacific", 247 "Novosibirsk", "Asia", 248 "Brunei", "Asia", 249 "Tonga", "Pacific", 250 "Changbai", "Asia", 251 "India", "Asia", 252 "Indonesia_Western", "Asia", 253 "Malaya", "Asia", 254 "Dacca", "Asia", 255 "Tashkent", "Asia", 256 "New_Zealand", "Pacific", 257 "Indonesia_Central", "Asia", 258 "Myanmar", "Asia", 259 "South_Georgia", "Atlantic", 260 "Truk", "Pacific", 261 "Pakistan", "Asia", 262 "Borneo", "Asia", 263 "DumontDUrville", "Antarctica", 264 "Argentina_Western", "America", 265 "Uruguay", "America", 266 "Dutch_Guiana", "America", 267 "Ponape", "Pacific", 268 "Gulf", "Asia", 269 "Aktyubinsk", "Asia", 270 "America_Mountain", "America", 271 "Dominican", "America", 272 "North_Mariana", "Pacific", 273 "Yukon", "America", 274 "Armenia", "Asia", 275 "Falkland", "Atlantic", 276 "Tbilisi", "Asia", 277 "Baku", "Asia", 278 "Venezuela", "America", 279 "Ashkhabad", "Asia", 280 "Cape_Verde", "Atlantic", 281 "Phoenix_Islands", "Pacific", 282 "Brasilia", "America", 283 "Marshall_Islands", "Pacific", 284 "Volgograd", "Europe", 285 "Yekaterinburg", "Asia", 286 "Kosrae", "Pacific", 287 "Tuvalu", "Pacific", 288 "Africa_Central", "Africa", 289 "Palau", "Pacific", 290 "Alaska_Hawaii", "America", 291 "Qyzylorda", "Asia", 292 "Bhutan", "Asia", 293 "Israel", "Asia", 294 "America_Eastern", "America", 295 "Nepal", "Asia", 296 "Azerbaijan", "Asia", 297 "Uralsk", "Asia", 298 "Bolivia", "America", 299 "Liberia", "Africa", 300 "Turkmenistan", "Asia", 301 "Davis", "Antarctica", 302 "Norfolk", "Pacific", 303 "Indochina", "Asia", 304 "Peru", "America", 305 "Acre", "America", 306 "China", "Asia", 307 "Chamorro", "Pacific", 308 "Atlantic", "America", 309 "Syowa", "Antarctica", 310 "Africa_FarWestern", "Africa", 311 "New_Caledonia", "Pacific", 312 "Greenland_Western", "America", 313 "Suriname", "America", 314 "Seychelles", "Indian", 315 "Christmas", "Indian", 316 "Australia_CentralWestern", "Australia", 317 "Greenland_Central", "America", 318 "French_Southern", "Indian", 319 "Australia_Central", "Australia", 320 "Australia_Western", "Australia", 321 "Magadan", "Asia", 322 "Kazakhstan_Eastern", "Asia", 323 "Goose_Bay", "America", 324 "Singapore", "Asia", 325 "Amazon", "America", 326 "Long_Shu", "Asia", 327 "Samara", "Europe", 328 }; 329 330 } 331