MCPcopy Create free account
hub / github.com/apache/nutch / getDomainName

Method getDomainName

src/java/org/apache/nutch/util/URLUtil.java:95–115  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 9

filterMethod · 0.95
testGetDomainNameMethod · 0.95
createMethod · 0.95
reduceMethod · 0.95
getPartitionMethod · 0.95
isSameDomainNameMethod · 0.95
chooseReprMethod · 0.95
mainMethod · 0.95
mapMethod · 0.95

Calls 4

getInstanceMethod · 0.95
isDomainSuffixMethod · 0.95
getHostMethod · 0.45
matchesMethod · 0.45

Tested by 1

testGetDomainNameMethod · 0.76