* getDomainName(conf, new URL(http://lucene.apache.org/))
* </code><br>
* will return <br><code> apache.org</code>
* */
public static String getDomainName(URL url) {
DomainSuffixes tlds = DomainSuffixes.getInstance();
String host = url.getHost();
//it seems that java returns hostnames ending with .
if(host.endsWith("."))
host = host.substring(0, host.length() - 1);
if(IP_PATTERN.matcher(host).matches())
return host;
int index = 0;
String candidate = host;
for(;index >= 0;) {
index = candidate.indexOf('.');
String subCandidate = candidate.substring(index+1);
if(tlds.isDomainSuffix(subCandidate)) {
return candidate;
}
candidate = subCandidate;
}
return candidate;