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