Returns the domain name of the url. The domain name of a url is the substring of the url's hostname, w/o subdomain names. As an example getDomainName(conf, new URL(http://lucene.apache.org/)) will return apache.org
(URL url)
| 93 | * <code> apache.org</code> |
| 94 | * */ |
| 95 | public static String getDomainName(URL url) { |
| 96 | DomainSuffixes tlds = DomainSuffixes.getInstance(); |
| 97 | String host = url.getHost(); |
| 98 | // it seems that java returns hostnames ending with . |
| 99 | if (host.endsWith(".")) |
| 100 | host = host.substring(0, host.length() - 1); |
| 101 | if (IP_PATTERN.matcher(host).matches()) |
| 102 | return host; |
| 103 | |
| 104 | int index = 0; |
| 105 | String candidate = host; |
| 106 | for (; index >= 0;) { |
| 107 | index = candidate.indexOf('.'); |
| 108 | String subCandidate = candidate.substring(index + 1); |
| 109 | if (tlds.isDomainSuffix(subCandidate)) { |
| 110 | return candidate; |
| 111 | } |
| 112 | candidate = subCandidate; |
| 113 | } |
| 114 | return candidate; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Returns the domain name of the url. The domain name of a url is the |