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