1 package org.unicode.cldr.util; 2 3 /** 4 * Generate URLs to parts of CLDR and the SurveyTool. You can change the urls used with for example, 5 * -DCLDR_SURVEY_BASE=http://st.unicode.org/smoketest 6 * 7 * @author srl 8 */ 9 public abstract class CLDRURLS { 10 public static final String CLDR_SCHEMA_BASE = "https://schemas.unicode.org/cldr"; 11 public static final String CLDR_CURVER_BASE = CLDR_SCHEMA_BASE + "/" + CLDRFile.GEN_VERSION; 12 /** Base URL for the CLDR repository */ 13 public static final String CLDR_REPO_BASE = "https://github.com/unicode-org/cldr"; 14 15 public static final String DEFAULT_COMMIT_BASE = CLDR_REPO_BASE + "/commit/"; 16 /** Hostname for the Survey Tool */ 17 public static final String DEFAULT_HOST = "st.unicode.org"; 18 19 public static final String DEFAULT_PATH = "/cldr-apps"; 20 public static final String DEFAULT_BASE = "https://" + DEFAULT_HOST + DEFAULT_PATH; 21 /** URL for filing a new ticket */ 22 public static final String CLDR_NEWTICKET_URL = 23 "https://cldr.unicode.org/index/bug-reports#TOC-Filing-a-Ticket"; 24 25 public static final String CLDR_REPO_ROOT = "https://github.com/unicode-org/cldr"; 26 public static final String CLDR_HOMEPAGE = "https://cldr.unicode.org"; 27 public static final String UNICODE_CONSORTIUM = "The Unicode Consortium"; 28 public static final String CLDR_UPDATINGDTD_URL = CLDR_HOMEPAGE + "/development/updating-dtds"; 29 /** Our license, in SPDX format */ 30 public static final String UNICODE_SPDX = "Unicode-3.0"; 31 /** 32 * See: 33 * https://spdx.github.io/spdx-spec/appendix-V-using-SPDX-short-identifiers-in-source-files/ 34 */ 35 public static final String UNICODE_SPDX_HEADER = "SPDX-License-Identifier: " + UNICODE_SPDX; 36 /** 37 * Override this property if you want to change the absolute URL to the SurveyTool base from 38 * DEFAULT_BASE 39 */ 40 public static final String CLDR_SURVEY_BASE = "CLDR_SURVEY_BASE"; 41 /** 42 * Override this property if you want to change the relative URL to the SurveyTool base from 43 * DEFAULT_PATH (within SurveyTool only) 44 */ 45 public static final String CLDR_SURVEY_PATH = "CLDR_SURVEY_PATH"; 46 47 public static final String TOOLSURL = "http://cldr.unicode.org/tools/"; 48 49 /** 50 * "special" pages 51 * 52 * @author srl 53 */ 54 public enum Special { 55 /** The 'main' view */ 56 Survey(""), 57 /** The list of locales */ 58 Locales, 59 /** The vetting viewer (i.e. Dashboard) */ 60 Vetting("dashboard"), 61 /** Forums. use "id" for the numeric post id */ 62 Forum; 63 Special(String s)64 Special(String s) { 65 this.id = s; 66 } 67 68 /** Convenience - just lowercases */ Special()69 Special() { 70 this.id = this.name().toLowerCase(); 71 } 72 73 private final String id; 74 } 75 76 protected static String VPATH = "/v#"; 77 /** Constant for an unknown git revision. Use the same in the builders. */ 78 public static final String UNKNOWN_REVISION = "(unknown)"; 79 80 public static final String GENERAL_HELP_URL = "https://cldr.unicode.org/translation/"; 81 public static final String ADMIN_HELP_URL = 82 "https://cldr.unicode.org/index/survey-tool/survey-tool-administration"; 83 public static final String CAPITALIZATION_URL = 84 "https://cldr.unicode.org/translation/translation-guide-general/capitalization"; 85 public static final String CHARACTERS_HELP = "https://cldr.unicode.org/translation/characters"; 86 public static final String CHARACTER_LABELS = 87 "https://cldr.unicode.org/translation/characters/character-labels"; 88 public static final String CHARTS_URL = "https://cldr.unicode.org/index/charts#TOC-Summary"; 89 public static final String COMPOUND_UNITS_HELP = 90 "https://cldr.unicode.org/translation/units/unit-names-and-patterns#h.7kdholgw8hpx"; 91 public static final String COUNTRY_NAMES = 92 "https://cldr.unicode.org/translation/displaynames/countryregion-territory-names"; 93 public static final String CURRENCY_NAMES = 94 "https://cldr.unicode.org/translation/currency-names-and-symbols"; 95 public static final String DATE_TIME_HELP = 96 "https://cldr.unicode.org/translation/date-time/date-time-names#h.ewzjebmpoi4k"; 97 public static final String DATE_TIME_NAMES = 98 "https://cldr.unicode.org/translation/date-time/datetime-names"; 99 public static final String DATE_TIME_NAMES_CYCLIC = 100 "https://cldr.unicode.org/translation/date-time/date-time-names#h.h0vy2eyzcj0n"; 101 public static final String DATE_TIME_NAMES_FIELD = 102 "https://cldr.unicode.org/translation/date-time/date-time-names#h.8wfk3599ck9x"; 103 public static final String DATE_TIME_NAMES_MONTH = 104 "https://cldr.unicode.org/translation/date-time/date-time-names#h.fww3pfyk0uwn"; 105 public static final String DATE_TIME_NAMES_RELATIVE = 106 "https://cldr.unicode.org/translation/date-time/date-time-names#h.aevw0tiix80v"; 107 public static final String DATE_TIME_PATTERNS = 108 "https://cldr.unicode.org/translation/date-time/date-time-patterns"; 109 public static final String DATE_TIME_PATTERNS_URL = 110 "https://cldr.unicode.org/translation/date-time/date-time-patterns"; 111 public static final String ERRORS_URL = 112 "https://cldr.unicode.org/translation/error-and-warning-codes"; 113 public static final String EXEMPLAR_CHARACTERS = 114 "https://cldr.unicode.org/translation/core-data/exemplars"; 115 public static final String GRAMMATICAL_INFLECTION = 116 "https://cldr.unicode.org/translation/grammatical-inflection"; 117 public static final String KEY_NAMES = 118 "https://cldr.unicode.org/translation/displaynames/countryregion-territory-names#h.x27jspwj91af"; 119 public static final String LANGUAGE_NAMES = 120 "https://cldr.unicode.org/translation/displaynames/languagelocale-names"; 121 public static final String LISTS_HELP = 122 "https://cldr.unicode.org/translation/miscellaneous-displaying-lists"; 123 public static final String LOCALE_PATTERN = 124 "https://cldr.unicode.org/translation/displaynames/languagelocale-name-patterns"; 125 public static final String NUMBERING_SYSTEMS = 126 "https://cldr.unicode.org/translation/core-data/numbering-systems"; 127 public static final String NUMBERS_HELP = 128 "https://cldr.unicode.org/translation/currency-names-and-symbols"; 129 public static final String NUMBERS_PLURAL = 130 "https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns#h.mnb2fmj0pt72"; 131 public static final String NUMBERS_SHORT = 132 "https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns#h.eradhhuxzqqz"; 133 public static final String NUMBER_PATTERNS = 134 "https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns#h.j899g3kk2p1z"; 135 public static final String PARSE_LENIENT = 136 "https://cldr.unicode.org/translation/core-data/characters#h.j3x0cwalqgqt"; 137 public static final String PERSON_NAME_FORMATS = 138 "https://cldr.unicode.org/translation/miscellaneous-person-name-formats"; 139 public static final String PLURALS_HELP = 140 "https://cldr.unicode.org/translation/getting-started/plurals"; 141 public static final String PLURALS_HELP_MINIMAL = 142 "https://cldr.unicode.org/translation/getting-started/plurals#h.pnla5cp3nl4l"; 143 public static final String SCRIPT_NAMES = 144 "https://cldr.unicode.org/translation/displaynames/script-names"; 145 public static final String SHORT_CHARACTER_NAMES = 146 "https://cldr.unicode.org/translation/characters/short-names-and-keywords#h.4a8wthj27m74"; 147 public static final String TRANSFORMS_HELP = "https://cldr.unicode.org/translation/transforms"; 148 public static final String TYPOGRAPHIC_NAMES = 149 "https://cldr.unicode.org/translation/characters/typographic-names"; 150 public static final String TZ_CITY_NAMES = 151 "https://cldr.unicode.org/translation/time-zones-and-city-names"; 152 public static final String UNITS_HELP = "https://cldr.unicode.org/translation/units"; 153 /* 154 * TODO: UNITS_MISC_HELP, formerly "https://cldr.unicode.org/translation/units-1/misc", 155 * now temporarily (?) the same as UNITS_HELP until a distinct URL is identified 156 * Reference: https://unicode-org.atlassian.net/browse/CLDR-15080 157 */ 158 public static final String UNITS_MISC_HELP = UNITS_HELP; 159 160 public static final String PRIORITY_SUMMARY_HELP_URL = 161 "https://cldr.unicode.org/translation/getting-started/vetting-view#TOC-Priority-Items"; 162 163 public static final String UPDATING_CURRENCY_CODES = 164 "https://cldr.unicode.org/development/updating-codes/update-currency-codes"; 165 166 public static final String CLDR_ARCHIVE = 167 "https://cldr.unicode.org/development/creating-the-archive"; 168 169 /** 170 * Get the relative base URL for the SurveyTool. This may be "/cldr-apps", for example. 171 * 172 * @return example, "/cldr-apps" 173 */ base()174 public abstract String base(); 175 176 /** 177 * please use CLDRLocale instead 178 * 179 * @param locale 180 * @param xpath 181 * @return 182 */ forXpath(String locale, String xpath)183 public String forXpath(String locale, String xpath) { 184 return forXpath(CLDRLocale.getInstance(locale), xpath); 185 } 186 187 /** 188 * Get a link to a specific xpath and locale. 189 * 190 * @param locale locale to view 191 * @param xpath the xpath to view 192 */ forXpath(CLDRLocale locale, String xpath)193 public final String forXpath(CLDRLocale locale, String xpath) { 194 assertIsXpath(xpath); 195 final String hexid = (xpath == null) ? null : StringId.getHexId(xpath); 196 return forXpathHexId(locale, hexid); 197 } 198 199 /** 200 * please use CLDRLocale instead 201 * 202 * @param locale 203 * @param hexid 204 * @return 205 */ forXpathHexId(String locale, String hexid)206 public final String forXpathHexId(String locale, String hexid) { 207 return forXpathHexId(CLDRLocale.getInstance(locale), hexid); 208 } 209 210 /** 211 * Get a link to a specific xpath hex ID and locale. 212 * 213 * @param locale 214 * @param hexid 215 * @return 216 */ forXpathHexId(CLDRLocale locale, String hexid)217 public final String forXpathHexId(CLDRLocale locale, String hexid) { 218 assertIsHexId(hexid); 219 return forSpecial(Special.Survey, locale, (String) null, hexid); 220 } 221 222 /** 223 * please use CLDRLocale instead 224 * 225 * @param locale 226 * @param hexid 227 * @return 228 */ forXpathHexId(String locale, PathHeader.PageId page, String hexid)229 public final String forXpathHexId(String locale, PathHeader.PageId page, String hexid) { 230 return forXpathHexId(CLDRLocale.getInstance(locale), page, hexid); 231 } 232 233 /** 234 * Get a link to a specific xpath hex ID and locale. 235 * 236 * @param locale 237 * @param hexid 238 * @return 239 */ forXpathHexId(CLDRLocale locale, PathHeader.PageId page, String hexid)240 public final String forXpathHexId(CLDRLocale locale, PathHeader.PageId page, String hexid) { 241 assertIsHexId(hexid); 242 return forSpecial(Special.Survey, locale, page, hexid); 243 } 244 245 /** 246 * please use CLDRLocale instead 247 * 248 * @param locale 249 * @param page 250 * @return 251 */ forPage(String locale, PathHeader.PageId page)252 public final String forPage(String locale, PathHeader.PageId page) { 253 return forPage(CLDRLocale.getInstance(locale), page); 254 } 255 forPage(CLDRLocale locale, PathHeader.PageId page)256 public final String forPage(CLDRLocale locale, PathHeader.PageId page) { 257 return forSpecial(Special.Survey, locale, page.name(), null); 258 } 259 260 /** 261 * Get a link to a specific locale in the SurveyTool. 262 * 263 * @param locale 264 * @return 265 */ forLocale(CLDRLocale locale)266 public final String forLocale(CLDRLocale locale) { 267 return forXpath(locale, null); 268 } 269 forSpecial( Special special, CLDRLocale locale, PathHeader.PageId page, String hexid)270 public final String forSpecial( 271 Special special, CLDRLocale locale, PathHeader.PageId page, String hexid) { 272 return forSpecial(special, locale, page.name(), hexid); 273 } 274 forSpecial(Special special)275 public final String forSpecial(Special special) { 276 return forSpecial(special, (CLDRLocale) null, (String) null, null); 277 } 278 forSpecial(Special special, CLDRLocale locale)279 public final String forSpecial(Special special, CLDRLocale locale) { 280 return forSpecial(special, locale, (String) null, null); 281 } 282 283 /** 284 * Get a link from all of the parts. 285 * 286 * @param special 287 * @param locale 288 * @param page 289 * @param xpath 290 * @return 291 */ forSpecial(Special special, CLDRLocale locale, String page, String hexid)292 public String forSpecial(Special special, CLDRLocale locale, String page, String hexid) { 293 StringBuilder sb = new StringBuilder(base()); 294 sb.append(VPATH); 295 if (special != null) { 296 sb.append(special.id); 297 } 298 sb.append('/'); 299 if (locale != null) { 300 sb.append(locale.getBaseName()); 301 } 302 sb.append('/'); 303 if (page != null) { 304 sb.append(page); 305 } 306 sb.append('/'); 307 if (hexid != null) { 308 sb.append(hexid); 309 } 310 return sb.toString(); 311 } 312 313 /** 314 * @param hexid 315 * @throws IllegalArgumentException 316 */ assertIsHexId(String hexid)317 public final void assertIsHexId(String hexid) throws IllegalArgumentException { 318 if (hexid != null && hexid.startsWith("/")) { 319 throw new IllegalArgumentException( 320 "This function takes a hex StringID: perhaps you meant to use forXpath() instead."); 321 } 322 } 323 324 /** 325 * @param xpath 326 * @throws IllegalArgumentException 327 */ assertIsXpath(String xpath)328 public final void assertIsXpath(String xpath) throws IllegalArgumentException { 329 if (xpath != null && !xpath.startsWith("/")) { 330 throw new IllegalArgumentException( 331 "This function takes an XPath: perhaps you meant to use forXpathHexId() instead."); 332 } 333 } 334 335 /** 336 * please use CLDRLocale instead 337 * 338 * @param vetting 339 * @param localeID 340 * @return 341 */ forSpecial(Special special, String localeID)342 public final String forSpecial(Special special, String localeID) { 343 return forSpecial(special, CLDRLocale.getInstance(localeID)); 344 } 345 forPathHeader(String locale, PathHeader pathHeader)346 public final String forPathHeader(String locale, PathHeader pathHeader) { 347 return forPathHeader(CLDRLocale.getInstance(locale), pathHeader); 348 } 349 350 /** 351 * This is the preferred function for jumping to an item relatively. It will reduce blinkage. 352 * 353 * @param locale 354 * @param pathHeader 355 * @return 356 */ forPathHeader(CLDRLocale locale, PathHeader pathHeader)357 public final String forPathHeader(CLDRLocale locale, PathHeader pathHeader) { 358 return forSpecial( 359 Special.Survey, 360 locale, 361 pathHeader.getPageId(), 362 StringId.getHexId(pathHeader.getOriginalPath())); 363 } 364 365 /** 366 * For a given hash, return as a link 367 * 368 * @param hash 369 * @return 370 */ gitHashToLink(String hash)371 public static String gitHashToLink(String hash) { 372 if (!isKnownHash(hash)) 373 return "<span class=\"githashLink\">" + hash + "</span>"; // Not linkifiable 374 return "<a class=\"githashLink\" href=\"" 375 + CldrUtility.getProperty("CLDR_COMMIT_BASE", DEFAULT_COMMIT_BASE) 376 + hash 377 + "\">" 378 + hash.substring(0, 8) 379 + "</a>"; 380 } 381 382 /** 383 * Is this a 'known' git hash? Or unknown? 384 * 385 * @param hash 386 * @return true if known, false if (unknown) 387 */ isKnownHash(String hash)388 public static boolean isKnownHash(String hash) { 389 return !hash.equals(UNKNOWN_REVISION); 390 } 391 392 /** 393 * Convert a URL into an HTML link to itself 394 * 395 * @param url 396 * @return 397 */ toHTML(String url)398 public static final String toHTML(String url) { 399 return "<a href=\"" + url + "\">" + url + "</a>"; 400 } 401 402 /** 403 * Provide the styles for inclusion into the ST <head> element. 404 * 405 * @return 406 */ getVettingViewerHeaderStyles()407 public static String getVettingViewerHeaderStyles() { 408 return "<style>\n" 409 + ".hide {display:none}\n" 410 + ".vve {}\n" 411 + ".vvn {}\n" 412 + ".vvp {}\n" 413 + ".vvl {}\n" 414 + ".vvm {}\n" 415 + ".vvu {}\n" 416 + ".vvw {}\n" 417 + ".vvd {}\n" 418 + ".vvo {}\n" 419 + "</style>"; 420 } 421 } 422