1 | /*
|
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
|
---|
3 | * contributor license agreements. See the NOTICE file distributed with
|
---|
4 | * this work for additional information regarding copyright ownership.
|
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
|
---|
6 | * (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | *
|
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
10 | *
|
---|
11 | * Unless required by applicable law or agreed to in writing, software
|
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
14 | * See the License for the specific language governing permissions and
|
---|
15 | * limitations under the License.
|
---|
16 | */
|
---|
17 | package org.openstreetmap.josm.data.validation.routines;
|
---|
18 |
|
---|
19 | import java.util.Arrays;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * <p><b>Domain name</b> validation routines.</p>
|
---|
23 | *
|
---|
24 | * <p>
|
---|
25 | * This validator provides methods for validating Internet domain names
|
---|
26 | * and top-level domains.
|
---|
27 | * </p>
|
---|
28 | *
|
---|
29 | * <p>Domain names are evaluated according
|
---|
30 | * to the standards <a href="http://www.ietf.org/rfc/rfc1034.txt">RFC1034</a>,
|
---|
31 | * section 3, and <a href="http://www.ietf.org/rfc/rfc1123.txt">RFC1123</a>,
|
---|
32 | * section 2.1. No accomodation is provided for the specialized needs of
|
---|
33 | * other applications; if the domain name has been URL-encoded, for example,
|
---|
34 | * validation will fail even though the equivalent plaintext version of the
|
---|
35 | * same name would have passed.
|
---|
36 | * </p>
|
---|
37 | *
|
---|
38 | * <p>
|
---|
39 | * Validation is also provided for top-level domains (TLDs) as defined and
|
---|
40 | * maintained by the Internet Assigned Numbers Authority (IANA):
|
---|
41 | * </p>
|
---|
42 | *
|
---|
43 | * <ul>
|
---|
44 | * <li>{@link #isValidInfrastructureTld} - validates infrastructure TLDs
|
---|
45 | * (<code>.arpa</code>, etc.)</li>
|
---|
46 | * <li>{@link #isValidGenericTld} - validates generic TLDs
|
---|
47 | * (<code>.com, .org</code>, etc.)</li>
|
---|
48 | * <li>{@link #isValidCountryCodeTld} - validates country code TLDs
|
---|
49 | * (<code>.us, .uk, .cn</code>, etc.)</li>
|
---|
50 | * </ul>
|
---|
51 | *
|
---|
52 | * <p>
|
---|
53 | * (<b>NOTE</b>: This class does not provide IP address lookup for domain names or
|
---|
54 | * methods to ensure that a given domain name matches a specific IP; see
|
---|
55 | * {@link java.net.InetAddress} for that functionality.)
|
---|
56 | * </p>
|
---|
57 | *
|
---|
58 | * @version $Revision: 1640271 $ $Date: 2014-11-18 02:32:15 2014 UTC (Tue, 18 Nov 2014) $
|
---|
59 | * @since Validator 1.4
|
---|
60 | */
|
---|
61 | public class DomainValidator extends AbstractValidator {
|
---|
62 |
|
---|
63 | // Regular expression strings for hostnames (derived from RFC2396 and RFC 1123)
|
---|
64 | private static final String DOMAIN_LABEL_REGEX = "\\p{Alnum}(?>[\\p{Alnum}-]*\\p{Alnum})*";
|
---|
65 | private static final String TOP_LABEL_REGEX = "\\p{Alpha}{2,}";
|
---|
66 | private static final String DOMAIN_NAME_REGEX =
|
---|
67 | "^(?:" + DOMAIN_LABEL_REGEX + "\\.)+" + "(" + TOP_LABEL_REGEX + ")$";
|
---|
68 |
|
---|
69 | private final boolean allowLocal;
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Singleton instance of this validator, which
|
---|
73 | * doesn't consider local addresses as valid.
|
---|
74 | */
|
---|
75 | private static final DomainValidator DOMAIN_VALIDATOR = new DomainValidator(false);
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Singleton instance of this validator, which does
|
---|
79 | * consider local addresses valid.
|
---|
80 | */
|
---|
81 | private static final DomainValidator DOMAIN_VALIDATOR_WITH_LOCAL = new DomainValidator(true);
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * RegexValidator for matching domains.
|
---|
85 | */
|
---|
86 | private final RegexValidator domainRegex =
|
---|
87 | new RegexValidator(DOMAIN_NAME_REGEX);
|
---|
88 | /**
|
---|
89 | * RegexValidator for matching the a local hostname
|
---|
90 | */
|
---|
91 | private final RegexValidator hostnameRegex =
|
---|
92 | new RegexValidator(DOMAIN_LABEL_REGEX);
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Returns the singleton instance of this validator. It
|
---|
96 | * will not consider local addresses as valid.
|
---|
97 | * @return the singleton instance of this validator
|
---|
98 | */
|
---|
99 | public static DomainValidator getInstance() {
|
---|
100 | return DOMAIN_VALIDATOR;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Returns the singleton instance of this validator,
|
---|
105 | * with local validation as required.
|
---|
106 | * @param allowLocal Should local addresses be considered valid?
|
---|
107 | * @return the singleton instance of this validator
|
---|
108 | */
|
---|
109 | public static DomainValidator getInstance(boolean allowLocal) {
|
---|
110 | if(allowLocal) {
|
---|
111 | return DOMAIN_VALIDATOR_WITH_LOCAL;
|
---|
112 | }
|
---|
113 | return DOMAIN_VALIDATOR;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /** Private constructor. */
|
---|
117 | private DomainValidator(boolean allowLocal) {
|
---|
118 | this.allowLocal = allowLocal;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Returns true if the specified <code>String</code> parses
|
---|
123 | * as a valid domain name with a recognized top-level domain.
|
---|
124 | * The parsing is case-sensitive.
|
---|
125 | * @param domain the parameter to check for domain name syntax
|
---|
126 | * @return true if the parameter is a valid domain name
|
---|
127 | */
|
---|
128 | @Override
|
---|
129 | public boolean isValid(String domain) {
|
---|
130 | String[] groups = domainRegex.match(domain);
|
---|
131 | if (groups != null && groups.length > 0) {
|
---|
132 | return isValidTld(groups[0]);
|
---|
133 | } else if(allowLocal) {
|
---|
134 | if (hostnameRegex.isValid(domain)) {
|
---|
135 | return true;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | return false;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Returns true if the specified <code>String</code> matches any
|
---|
143 | * IANA-defined top-level domain. Leading dots are ignored if present.
|
---|
144 | * The search is case-sensitive.
|
---|
145 | * @param tld the parameter to check for TLD status
|
---|
146 | * @return true if the parameter is a TLD
|
---|
147 | */
|
---|
148 | public boolean isValidTld(String tld) {
|
---|
149 | if(allowLocal && isValidLocalTld(tld)) {
|
---|
150 | return true;
|
---|
151 | }
|
---|
152 | return isValidInfrastructureTld(tld)
|
---|
153 | || isValidGenericTld(tld)
|
---|
154 | || isValidCountryCodeTld(tld);
|
---|
155 | }
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Returns true if the specified <code>String</code> matches any
|
---|
159 | * IANA-defined infrastructure top-level domain. Leading dots are
|
---|
160 | * ignored if present. The search is case-sensitive.
|
---|
161 | * @param iTld the parameter to check for infrastructure TLD status
|
---|
162 | * @return true if the parameter is an infrastructure TLD
|
---|
163 | */
|
---|
164 | public boolean isValidInfrastructureTld(String iTld) {
|
---|
165 | return Arrays.binarySearch(INFRASTRUCTURE_TLDS, (chompLeadingDot(iTld.toLowerCase()))) >= 0;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Returns true if the specified <code>String</code> matches any
|
---|
170 | * IANA-defined generic top-level domain. Leading dots are ignored
|
---|
171 | * if present. The search is case-sensitive.
|
---|
172 | * @param gTld the parameter to check for generic TLD status
|
---|
173 | * @return true if the parameter is a generic TLD
|
---|
174 | */
|
---|
175 | public boolean isValidGenericTld(String gTld) {
|
---|
176 | return Arrays.binarySearch(GENERIC_TLDS, chompLeadingDot(gTld.toLowerCase())) >= 0;
|
---|
177 | }
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Returns true if the specified <code>String</code> matches any
|
---|
181 | * IANA-defined country code top-level domain. Leading dots are
|
---|
182 | * ignored if present. The search is case-sensitive.
|
---|
183 | * @param ccTld the parameter to check for country code TLD status
|
---|
184 | * @return true if the parameter is a country code TLD
|
---|
185 | */
|
---|
186 | public boolean isValidCountryCodeTld(String ccTld) {
|
---|
187 | return Arrays.binarySearch(COUNTRY_CODE_TLDS, chompLeadingDot(ccTld.toLowerCase())) >= 0;
|
---|
188 | }
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Returns true if the specified <code>String</code> matches any
|
---|
192 | * widely used "local" domains (localhost or localdomain). Leading dots are
|
---|
193 | * ignored if present. The search is case-sensitive.
|
---|
194 | * @param iTld the parameter to check for local TLD status
|
---|
195 | * @return true if the parameter is an local TLD
|
---|
196 | */
|
---|
197 | public boolean isValidLocalTld(String iTld) {
|
---|
198 | return Arrays.binarySearch(LOCAL_TLDS, chompLeadingDot(iTld.toLowerCase())) >= 0;
|
---|
199 | }
|
---|
200 |
|
---|
201 | private String chompLeadingDot(String str) {
|
---|
202 | if (str.startsWith(".")) {
|
---|
203 | return str.substring(1);
|
---|
204 | } else {
|
---|
205 | return str;
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | // ---------------------------------------------
|
---|
210 | // ----- TLDs defined by IANA
|
---|
211 | // ----- Authoritative and comprehensive list at:
|
---|
212 | // ----- http://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
---|
213 |
|
---|
214 | private static final String[] INFRASTRUCTURE_TLDS = new String[] {
|
---|
215 | "arpa", // internet infrastructure
|
---|
216 | "root" // diagnostic marker for non-truncated root zone
|
---|
217 | };
|
---|
218 |
|
---|
219 | private static final String[] GENERIC_TLDS = new String[] {
|
---|
220 | "abogado",
|
---|
221 | "academy",
|
---|
222 | "accountants",
|
---|
223 | "active",
|
---|
224 | "actor",
|
---|
225 | "aero",
|
---|
226 | "agency",
|
---|
227 | "airforce",
|
---|
228 | "allfinanz",
|
---|
229 | "alsace",
|
---|
230 | "archi",
|
---|
231 | "army",
|
---|
232 | "arpa",
|
---|
233 | "asia",
|
---|
234 | "associates",
|
---|
235 | "attorney",
|
---|
236 | "auction",
|
---|
237 | "audio",
|
---|
238 | "autos",
|
---|
239 | "axa",
|
---|
240 | "band",
|
---|
241 | "bar",
|
---|
242 | "bargains",
|
---|
243 | "bayern",
|
---|
244 | "beer",
|
---|
245 | "berlin",
|
---|
246 | "best",
|
---|
247 | "bid",
|
---|
248 | "bike",
|
---|
249 | "bio",
|
---|
250 | "biz",
|
---|
251 | "black",
|
---|
252 | "blackfriday",
|
---|
253 | "blue",
|
---|
254 | "bmw",
|
---|
255 | "bnpparibas",
|
---|
256 | "boo",
|
---|
257 | "boutique",
|
---|
258 | "brussels",
|
---|
259 | "budapest",
|
---|
260 | "build",
|
---|
261 | "builders",
|
---|
262 | "business",
|
---|
263 | "buzz",
|
---|
264 | "bzh",
|
---|
265 | "cab",
|
---|
266 | "cal",
|
---|
267 | "camera",
|
---|
268 | "camp",
|
---|
269 | "cancerresearch",
|
---|
270 | "capetown",
|
---|
271 | "capital",
|
---|
272 | "caravan",
|
---|
273 | "cards",
|
---|
274 | "care",
|
---|
275 | "career",
|
---|
276 | "careers",
|
---|
277 | "casa",
|
---|
278 | "cash",
|
---|
279 | "cat",
|
---|
280 | "catering",
|
---|
281 | "center",
|
---|
282 | "ceo",
|
---|
283 | "cern",
|
---|
284 | "channel",
|
---|
285 | "cheap",
|
---|
286 | "christmas",
|
---|
287 | "chrome",
|
---|
288 | "church",
|
---|
289 | "citic",
|
---|
290 | "city",
|
---|
291 | "claims",
|
---|
292 | "cleaning",
|
---|
293 | "click",
|
---|
294 | "clinic",
|
---|
295 | "clothing",
|
---|
296 | "club",
|
---|
297 | "codes",
|
---|
298 | "coffee",
|
---|
299 | "college",
|
---|
300 | "cologne",
|
---|
301 | "com",
|
---|
302 | "community",
|
---|
303 | "company",
|
---|
304 | "computer",
|
---|
305 | "condos",
|
---|
306 | "construction",
|
---|
307 | "consulting",
|
---|
308 | "contractors",
|
---|
309 | "cooking",
|
---|
310 | "cool",
|
---|
311 | "coop",
|
---|
312 | "country",
|
---|
313 | "credit",
|
---|
314 | "creditcard",
|
---|
315 | "crs",
|
---|
316 | "cruises",
|
---|
317 | "cuisinella",
|
---|
318 | "cymru",
|
---|
319 | "dad",
|
---|
320 | "dance",
|
---|
321 | "dating",
|
---|
322 | "day",
|
---|
323 | "deals",
|
---|
324 | "degree",
|
---|
325 | "democrat",
|
---|
326 | "dental",
|
---|
327 | "dentist",
|
---|
328 | "desi",
|
---|
329 | "diamonds",
|
---|
330 | "diet",
|
---|
331 | "digital",
|
---|
332 | "direct",
|
---|
333 | "directory",
|
---|
334 | "discount",
|
---|
335 | "dnp",
|
---|
336 | "domains",
|
---|
337 | "durban",
|
---|
338 | "dvag",
|
---|
339 | "eat",
|
---|
340 | "edu",
|
---|
341 | "education",
|
---|
342 | "email",
|
---|
343 | "engineer",
|
---|
344 | "engineering",
|
---|
345 | "enterprises",
|
---|
346 | "equipment",
|
---|
347 | "esq",
|
---|
348 | "estate",
|
---|
349 | "eus",
|
---|
350 | "events",
|
---|
351 | "exchange",
|
---|
352 | "expert",
|
---|
353 | "exposed",
|
---|
354 | "fail",
|
---|
355 | "farm",
|
---|
356 | "feedback",
|
---|
357 | "finance",
|
---|
358 | "financial",
|
---|
359 | "fish",
|
---|
360 | "fishing",
|
---|
361 | "fitness",
|
---|
362 | "flights",
|
---|
363 | "florist",
|
---|
364 | "flsmidth",
|
---|
365 | "fly",
|
---|
366 | "foo",
|
---|
367 | "forsale",
|
---|
368 | "foundation",
|
---|
369 | "frl",
|
---|
370 | "frogans",
|
---|
371 | "fund",
|
---|
372 | "furniture",
|
---|
373 | "futbol",
|
---|
374 | "gal",
|
---|
375 | "gallery",
|
---|
376 | "gbiz",
|
---|
377 | "gent",
|
---|
378 | "gift",
|
---|
379 | "gifts",
|
---|
380 | "gives",
|
---|
381 | "glass",
|
---|
382 | "gle",
|
---|
383 | "global",
|
---|
384 | "globo",
|
---|
385 | "gmail",
|
---|
386 | "gmo",
|
---|
387 | "gmx",
|
---|
388 | "google",
|
---|
389 | "gop",
|
---|
390 | "gov",
|
---|
391 | "graphics",
|
---|
392 | "gratis",
|
---|
393 | "green",
|
---|
394 | "gripe",
|
---|
395 | "guide",
|
---|
396 | "guitars",
|
---|
397 | "guru",
|
---|
398 | "hamburg",
|
---|
399 | "haus",
|
---|
400 | "healthcare",
|
---|
401 | "help",
|
---|
402 | "here",
|
---|
403 | "hiphop",
|
---|
404 | "hiv",
|
---|
405 | "holdings",
|
---|
406 | "holiday",
|
---|
407 | "homes",
|
---|
408 | "horse",
|
---|
409 | "host",
|
---|
410 | "hosting",
|
---|
411 | "house",
|
---|
412 | "how",
|
---|
413 | "ibm",
|
---|
414 | "immo",
|
---|
415 | "immobilien",
|
---|
416 | "industries",
|
---|
417 | "info",
|
---|
418 | "ing",
|
---|
419 | "ink",
|
---|
420 | "institute",
|
---|
421 | "insure",
|
---|
422 | "int",
|
---|
423 | "international",
|
---|
424 | "investments",
|
---|
425 | "jetzt",
|
---|
426 | "jobs",
|
---|
427 | "joburg",
|
---|
428 | "juegos",
|
---|
429 | "kaufen",
|
---|
430 | "kim",
|
---|
431 | "kitchen",
|
---|
432 | "kiwi",
|
---|
433 | "koeln",
|
---|
434 | "krd",
|
---|
435 | "kred",
|
---|
436 | "lacaixa",
|
---|
437 | "land",
|
---|
438 | "lawyer",
|
---|
439 | "lease",
|
---|
440 | "lgbt",
|
---|
441 | "life",
|
---|
442 | "lighting",
|
---|
443 | "limited",
|
---|
444 | "limo",
|
---|
445 | "link",
|
---|
446 | "loans",
|
---|
447 | "london",
|
---|
448 | "lotto",
|
---|
449 | "ltda",
|
---|
450 | "luxe",
|
---|
451 | "luxury",
|
---|
452 | "maison",
|
---|
453 | "management",
|
---|
454 | "mango",
|
---|
455 | "market",
|
---|
456 | "marketing",
|
---|
457 | "media",
|
---|
458 | "meet",
|
---|
459 | "melbourne",
|
---|
460 | "meme",
|
---|
461 | "menu",
|
---|
462 | "miami",
|
---|
463 | "mil",
|
---|
464 | "mini",
|
---|
465 | "mobi",
|
---|
466 | "moda",
|
---|
467 | "moe",
|
---|
468 | "monash",
|
---|
469 | "mortgage",
|
---|
470 | "moscow",
|
---|
471 | "motorcycles",
|
---|
472 | "mov",
|
---|
473 | "museum",
|
---|
474 | "nagoya",
|
---|
475 | "name",
|
---|
476 | "navy",
|
---|
477 | "net",
|
---|
478 | "network",
|
---|
479 | "neustar",
|
---|
480 | "new",
|
---|
481 | "nexus",
|
---|
482 | "ngo",
|
---|
483 | "nhk",
|
---|
484 | "ninja",
|
---|
485 | "nra",
|
---|
486 | "nrw",
|
---|
487 | "nyc",
|
---|
488 | "okinawa",
|
---|
489 | "ong",
|
---|
490 | "onl",
|
---|
491 | "ooo",
|
---|
492 | "org",
|
---|
493 | "organic",
|
---|
494 | "otsuka",
|
---|
495 | "ovh",
|
---|
496 | "paris",
|
---|
497 | "partners",
|
---|
498 | "parts",
|
---|
499 | "pharmacy",
|
---|
500 | "photo",
|
---|
501 | "photography",
|
---|
502 | "photos",
|
---|
503 | "physio",
|
---|
504 | "pics",
|
---|
505 | "pictures",
|
---|
506 | "pink",
|
---|
507 | "pizza",
|
---|
508 | "place",
|
---|
509 | "plumbing",
|
---|
510 | "pohl",
|
---|
511 | "poker",
|
---|
512 | "post",
|
---|
513 | "praxi",
|
---|
514 | "press",
|
---|
515 | "pro",
|
---|
516 | "prod",
|
---|
517 | "productions",
|
---|
518 | "prof",
|
---|
519 | "properties",
|
---|
520 | "property",
|
---|
521 | "pub",
|
---|
522 | "qpon",
|
---|
523 | "quebec",
|
---|
524 | "realtor",
|
---|
525 | "recipes",
|
---|
526 | "red",
|
---|
527 | "rehab",
|
---|
528 | "reise",
|
---|
529 | "reisen",
|
---|
530 | "ren",
|
---|
531 | "rentals",
|
---|
532 | "repair",
|
---|
533 | "report",
|
---|
534 | "republican",
|
---|
535 | "rest",
|
---|
536 | "restaurant",
|
---|
537 | "reviews",
|
---|
538 | "rich",
|
---|
539 | "rio",
|
---|
540 | "rip",
|
---|
541 | "rocks",
|
---|
542 | "rodeo",
|
---|
543 | "rsvp",
|
---|
544 | "ruhr",
|
---|
545 | "ryukyu",
|
---|
546 | "saarland",
|
---|
547 | "sarl",
|
---|
548 | "sca",
|
---|
549 | "scb",
|
---|
550 | "schmidt",
|
---|
551 | "schule",
|
---|
552 | "scot",
|
---|
553 | "services",
|
---|
554 | "sexy",
|
---|
555 | "shiksha",
|
---|
556 | "shoes",
|
---|
557 | "singles",
|
---|
558 | "social",
|
---|
559 | "software",
|
---|
560 | "sohu",
|
---|
561 | "solar",
|
---|
562 | "solutions",
|
---|
563 | "soy",
|
---|
564 | "space",
|
---|
565 | "spiegel",
|
---|
566 | "supplies",
|
---|
567 | "supply",
|
---|
568 | "support",
|
---|
569 | "surf",
|
---|
570 | "surgery",
|
---|
571 | "suzuki",
|
---|
572 | "systems",
|
---|
573 | "tatar",
|
---|
574 | "tattoo",
|
---|
575 | "tax",
|
---|
576 | "technology",
|
---|
577 | "tel",
|
---|
578 | "tienda",
|
---|
579 | "tips",
|
---|
580 | "tirol",
|
---|
581 | "today",
|
---|
582 | "tokyo",
|
---|
583 | "tools",
|
---|
584 | "top",
|
---|
585 | "town",
|
---|
586 | "toys",
|
---|
587 | "trade",
|
---|
588 | "training",
|
---|
589 | "travel",
|
---|
590 | "tui",
|
---|
591 | "university",
|
---|
592 | "uno",
|
---|
593 | "uol",
|
---|
594 | "vacations",
|
---|
595 | "vegas",
|
---|
596 | "ventures",
|
---|
597 | "versicherung",
|
---|
598 | "vet",
|
---|
599 | "viajes",
|
---|
600 | "villas",
|
---|
601 | "vision",
|
---|
602 | "vlaanderen",
|
---|
603 | "vodka",
|
---|
604 | "vote",
|
---|
605 | "voting",
|
---|
606 | "voto",
|
---|
607 | "voyage",
|
---|
608 | "wales",
|
---|
609 | "wang",
|
---|
610 | "watch",
|
---|
611 | "webcam",
|
---|
612 | "website",
|
---|
613 | "wed",
|
---|
614 | "wedding",
|
---|
615 | "whoswho",
|
---|
616 | "wien",
|
---|
617 | "wiki",
|
---|
618 | "williamhill",
|
---|
619 | "wme",
|
---|
620 | "work",
|
---|
621 | "works",
|
---|
622 | "world",
|
---|
623 | "wtc",
|
---|
624 | "wtf",
|
---|
625 | "xxx",
|
---|
626 | "xyz",
|
---|
627 | "yachts",
|
---|
628 | "yandex",
|
---|
629 | "yoga",
|
---|
630 | "yokohama",
|
---|
631 | "youtube",
|
---|
632 | "zip",
|
---|
633 | "zone",
|
---|
634 | };
|
---|
635 |
|
---|
636 | private static final String[] COUNTRY_CODE_TLDS = new String[] {
|
---|
637 | "ac", // Ascension Island
|
---|
638 | "ad", // Andorra
|
---|
639 | "ae", // United Arab Emirates
|
---|
640 | "af", // Afghanistan
|
---|
641 | "ag", // Antigua and Barbuda
|
---|
642 | "ai", // Anguilla
|
---|
643 | "al", // Albania
|
---|
644 | "am", // Armenia
|
---|
645 | "an", // Netherlands Antilles
|
---|
646 | "ao", // Angola
|
---|
647 | "aq", // Antarctica
|
---|
648 | "ar", // Argentina
|
---|
649 | "as", // American Samoa
|
---|
650 | "at", // Austria
|
---|
651 | "au", // Australia (includes Ashmore and Cartier Islands and Coral Sea Islands)
|
---|
652 | "aw", // Aruba
|
---|
653 | "ax", // Åland
|
---|
654 | "az", // Azerbaijan
|
---|
655 | "ba", // Bosnia and Herzegovina
|
---|
656 | "bb", // Barbados
|
---|
657 | "bd", // Bangladesh
|
---|
658 | "be", // Belgium
|
---|
659 | "bf", // Burkina Faso
|
---|
660 | "bg", // Bulgaria
|
---|
661 | "bh", // Bahrain
|
---|
662 | "bi", // Burundi
|
---|
663 | "bj", // Benin
|
---|
664 | "bm", // Bermuda
|
---|
665 | "bn", // Brunei Darussalam
|
---|
666 | "bo", // Bolivia
|
---|
667 | "br", // Brazil
|
---|
668 | "bs", // Bahamas
|
---|
669 | "bt", // Bhutan
|
---|
670 | "bv", // Bouvet Island
|
---|
671 | "bw", // Botswana
|
---|
672 | "by", // Belarus
|
---|
673 | "bz", // Belize
|
---|
674 | "ca", // Canada
|
---|
675 | "cc", // Cocos (Keeling) Islands
|
---|
676 | "cd", // Democratic Republic of the Congo (formerly Zaire)
|
---|
677 | "cf", // Central African Republic
|
---|
678 | "cg", // Republic of the Congo
|
---|
679 | "ch", // Switzerland
|
---|
680 | "ci", // Côte d'Ivoire
|
---|
681 | "ck", // Cook Islands
|
---|
682 | "cl", // Chile
|
---|
683 | "cm", // Cameroon
|
---|
684 | "cn", // China, mainland
|
---|
685 | "co", // Colombia
|
---|
686 | "cr", // Costa Rica
|
---|
687 | "cu", // Cuba
|
---|
688 | "cv", // Cape Verde
|
---|
689 | "cw", // Curaçao
|
---|
690 | "cx", // Christmas Island
|
---|
691 | "cy", // Cyprus
|
---|
692 | "cz", // Czech Republic
|
---|
693 | "de", // Germany
|
---|
694 | "dj", // Djibouti
|
---|
695 | "dk", // Denmark
|
---|
696 | "dm", // Dominica
|
---|
697 | "do", // Dominican Republic
|
---|
698 | "dz", // Algeria
|
---|
699 | "ec", // Ecuador
|
---|
700 | "ee", // Estonia
|
---|
701 | "eg", // Egypt
|
---|
702 | "er", // Eritrea
|
---|
703 | "es", // Spain
|
---|
704 | "et", // Ethiopia
|
---|
705 | "eu", // European Union
|
---|
706 | "fi", // Finland
|
---|
707 | "fj", // Fiji
|
---|
708 | "fk", // Falkland Islands
|
---|
709 | "fm", // Federated States of Micronesia
|
---|
710 | "fo", // Faroe Islands
|
---|
711 | "fr", // France
|
---|
712 | "ga", // Gabon
|
---|
713 | "gb", // Great Britain (United Kingdom)
|
---|
714 | "gd", // Grenada
|
---|
715 | "ge", // Georgia
|
---|
716 | "gf", // French Guiana
|
---|
717 | "gg", // Guernsey
|
---|
718 | "gh", // Ghana
|
---|
719 | "gi", // Gibraltar
|
---|
720 | "gl", // Greenland
|
---|
721 | "gm", // The Gambia
|
---|
722 | "gn", // Guinea
|
---|
723 | "gp", // Guadeloupe
|
---|
724 | "gq", // Equatorial Guinea
|
---|
725 | "gr", // Greece
|
---|
726 | "gs", // South Georgia and the South Sandwich Islands
|
---|
727 | "gt", // Guatemala
|
---|
728 | "gu", // Guam
|
---|
729 | "gw", // Guinea-Bissau
|
---|
730 | "gy", // Guyana
|
---|
731 | "hk", // Hong Kong
|
---|
732 | "hm", // Heard Island and McDonald Islands
|
---|
733 | "hn", // Honduras
|
---|
734 | "hr", // Croatia (Hrvatska)
|
---|
735 | "ht", // Haiti
|
---|
736 | "hu", // Hungary
|
---|
737 | "id", // Indonesia
|
---|
738 | "ie", // Ireland (Éire)
|
---|
739 | "il", // Israel
|
---|
740 | "im", // Isle of Man
|
---|
741 | "in", // India
|
---|
742 | "io", // British Indian Ocean Territory
|
---|
743 | "iq", // Iraq
|
---|
744 | "ir", // Iran
|
---|
745 | "is", // Iceland
|
---|
746 | "it", // Italy
|
---|
747 | "je", // Jersey
|
---|
748 | "jm", // Jamaica
|
---|
749 | "jo", // Jordan
|
---|
750 | "jp", // Japan
|
---|
751 | "ke", // Kenya
|
---|
752 | "kg", // Kyrgyzstan
|
---|
753 | "kh", // Cambodia (Khmer)
|
---|
754 | "ki", // Kiribati
|
---|
755 | "km", // Comoros
|
---|
756 | "kn", // Saint Kitts and Nevis
|
---|
757 | "kp", // North Korea
|
---|
758 | "kr", // South Korea
|
---|
759 | "kw", // Kuwait
|
---|
760 | "ky", // Cayman Islands
|
---|
761 | "kz", // Kazakhstan
|
---|
762 | "la", // Laos (currently being marketed as the official domain for Los Angeles)
|
---|
763 | "lb", // Lebanon
|
---|
764 | "lc", // Saint Lucia
|
---|
765 | "li", // Liechtenstein
|
---|
766 | "lk", // Sri Lanka
|
---|
767 | "lr", // Liberia
|
---|
768 | "ls", // Lesotho
|
---|
769 | "lt", // Lithuania
|
---|
770 | "lu", // Luxembourg
|
---|
771 | "lv", // Latvia
|
---|
772 | "ly", // Libya
|
---|
773 | "ma", // Morocco
|
---|
774 | "mc", // Monaco
|
---|
775 | "md", // Moldova
|
---|
776 | "me", // Montenegro
|
---|
777 | "mg", // Madagascar
|
---|
778 | "mh", // Marshall Islands
|
---|
779 | "mk", // Republic of Macedonia
|
---|
780 | "ml", // Mali
|
---|
781 | "mm", // Myanmar
|
---|
782 | "mn", // Mongolia
|
---|
783 | "mo", // Macau
|
---|
784 | "mp", // Northern Mariana Islands
|
---|
785 | "mq", // Martinique
|
---|
786 | "mr", // Mauritania
|
---|
787 | "ms", // Montserrat
|
---|
788 | "mt", // Malta
|
---|
789 | "mu", // Mauritius
|
---|
790 | "mv", // Maldives
|
---|
791 | "mw", // Malawi
|
---|
792 | "mx", // Mexico
|
---|
793 | "my", // Malaysia
|
---|
794 | "mz", // Mozambique
|
---|
795 | "na", // Namibia
|
---|
796 | "nc", // New Caledonia
|
---|
797 | "ne", // Niger
|
---|
798 | "nf", // Norfolk Island
|
---|
799 | "ng", // Nigeria
|
---|
800 | "ni", // Nicaragua
|
---|
801 | "nl", // Netherlands
|
---|
802 | "no", // Norway
|
---|
803 | "np", // Nepal
|
---|
804 | "nr", // Nauru
|
---|
805 | "nu", // Niue
|
---|
806 | "nz", // New Zealand
|
---|
807 | "om", // Oman
|
---|
808 | "pa", // Panama
|
---|
809 | "pe", // Peru
|
---|
810 | "pf", // French Polynesia With Clipperton Island
|
---|
811 | "pg", // Papua New Guinea
|
---|
812 | "ph", // Philippines
|
---|
813 | "pk", // Pakistan
|
---|
814 | "pl", // Poland
|
---|
815 | "pm", // Saint-Pierre and Miquelon
|
---|
816 | "pn", // Pitcairn Islands
|
---|
817 | "pr", // Puerto Rico
|
---|
818 | "ps", // Palestinian territories (PA-controlled West Bank and Gaza Strip)
|
---|
819 | "pt", // Portugal
|
---|
820 | "pw", // Palau
|
---|
821 | "py", // Paraguay
|
---|
822 | "qa", // Qatar
|
---|
823 | "re", // Réunion
|
---|
824 | "ro", // Romania
|
---|
825 | "rs", // Serbia
|
---|
826 | "ru", // Russia
|
---|
827 | "rw", // Rwanda
|
---|
828 | "sa", // Saudi Arabia
|
---|
829 | "sb", // Solomon Islands
|
---|
830 | "sc", // Seychelles
|
---|
831 | "sd", // Sudan
|
---|
832 | "se", // Sweden
|
---|
833 | "sg", // Singapore
|
---|
834 | "sh", // Saint Helena
|
---|
835 | "si", // Slovenia
|
---|
836 | "sj", // Svalbard and Jan Mayen Islands Not in use (Norwegian dependencies; see .no)
|
---|
837 | "sk", // Slovakia
|
---|
838 | "sl", // Sierra Leone
|
---|
839 | "sm", // San Marino
|
---|
840 | "sn", // Senegal
|
---|
841 | "so", // Somalia
|
---|
842 | "sr", // Suriname
|
---|
843 | "st", // São Tomé and Príncipe
|
---|
844 | "su", // Soviet Union (deprecated)
|
---|
845 | "sv", // El Salvador
|
---|
846 | "sx", // Sint Maarten
|
---|
847 | "sy", // Syria
|
---|
848 | "sz", // Swaziland
|
---|
849 | "tc", // Turks and Caicos Islands
|
---|
850 | "td", // Chad
|
---|
851 | "tf", // French Southern and Antarctic Lands
|
---|
852 | "tg", // Togo
|
---|
853 | "th", // Thailand
|
---|
854 | "tj", // Tajikistan
|
---|
855 | "tk", // Tokelau
|
---|
856 | "tl", // East Timor (deprecated old code)
|
---|
857 | "tm", // Turkmenistan
|
---|
858 | "tn", // Tunisia
|
---|
859 | "to", // Tonga
|
---|
860 | "tp", // East Timor
|
---|
861 | "tr", // Turkey
|
---|
862 | "tt", // Trinidad and Tobago
|
---|
863 | "tv", // Tuvalu
|
---|
864 | "tw", // Taiwan, Republic of China
|
---|
865 | "tz", // Tanzania
|
---|
866 | "ua", // Ukraine
|
---|
867 | "ug", // Uganda
|
---|
868 | "uk", // United Kingdom
|
---|
869 | "um", // United States Minor Outlying Islands
|
---|
870 | "us", // United States of America
|
---|
871 | "uy", // Uruguay
|
---|
872 | "uz", // Uzbekistan
|
---|
873 | "va", // Vatican City State
|
---|
874 | "vc", // Saint Vincent and the Grenadines
|
---|
875 | "ve", // Venezuela
|
---|
876 | "vg", // British Virgin Islands
|
---|
877 | "vi", // U.S. Virgin Islands
|
---|
878 | "vn", // Vietnam
|
---|
879 | "vu", // Vanuatu
|
---|
880 | "wf", // Wallis and Futuna
|
---|
881 | "ws", // Samoa (formerly Western Samoa)
|
---|
882 | "ye", // Yemen
|
---|
883 | "yt", // Mayotte
|
---|
884 | "yu", // Serbia and Montenegro (originally Yugoslavia)
|
---|
885 | "za", // South Africa
|
---|
886 | "zm", // Zambia
|
---|
887 | "zw", // Zimbabwe
|
---|
888 | };
|
---|
889 |
|
---|
890 | private static final String[] LOCAL_TLDS = new String[] {
|
---|
891 | "localhost", // RFC2606 defined
|
---|
892 | "localdomain" // Also widely used as localhost.localdomain
|
---|
893 | };
|
---|
894 |
|
---|
895 | static {
|
---|
896 | Arrays.sort(INFRASTRUCTURE_TLDS);
|
---|
897 | Arrays.sort(COUNTRY_CODE_TLDS);
|
---|
898 | Arrays.sort(GENERIC_TLDS);
|
---|
899 | Arrays.sort(LOCAL_TLDS);
|
---|
900 | }
|
---|
901 | }
|
---|