@Test public void testExtractDomainFromFullURL() throws URIException { final String[][] TESTS = new String[][]{ {"http: {"http: {"http: {"http: }; for (String[] test: TESTS) { UsableURI url = UsableURIFactory.getInstance(test[0]); String host = url.getHost(); String canonHost = Normalisation.canonicaliseHost(host); assertEquals("The URL '" + test[0] + "' should have the correct host extracted", test[1], canonHost); final String domain = LinkExtractor.extractPrivateSuffixFromHost(canonHost); assertEquals("The URL '" + test[0] + "' should have the correct domain extracted", test[2], domain); } }
public static String extractPrivateSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return host; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 3 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 3) + "." + parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { if( domainName.isTopPrivateDomain() || domainName.isUnderPublicSuffix() ) { suffix = domainName.topPrivateDomain(); } else { suffix = domainName; } } if (suffix == null) suffix = domainName; return suffix.toString(); }
LinkExtractor { public static String extractPrivateSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return host; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 3 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 3) + "." + parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { if( domainName.isTopPrivateDomain() || domainName.isUnderPublicSuffix() ) { suffix = domainName.topPrivateDomain(); } else { suffix = domainName; } } if (suffix == null) suffix = domainName; return suffix.toString(); } }
LinkExtractor { public static String extractPrivateSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return host; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 3 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 3) + "." + parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { if( domainName.isTopPrivateDomain() || domainName.isUnderPublicSuffix() ) { suffix = domainName.topPrivateDomain(); } else { suffix = domainName; } } if (suffix == null) suffix = domainName; return suffix.toString(); }  }
LinkExtractor { public static String extractPrivateSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return host; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 3 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 3) + "." + parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { if( domainName.isTopPrivateDomain() || domainName.isUnderPublicSuffix() ) { suffix = domainName.topPrivateDomain(); } else { suffix = domainName; } } if (suffix == null) suffix = domainName; return suffix.toString(); }  static String extractHost(String url); static Set<String> extractPublicSuffixes( Metadata metadata ); static String extractPublicSuffix( String url ); static String extractPublicSuffixFromHost( String host ); static String extractPrivateSuffix( String url ); static String extractPrivateSuffixFromHost( String host ); static ImmutableList<String> allLevels(String host); static void main( String[] args ); }
LinkExtractor { public static String extractPrivateSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return host; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 3 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 3) + "." + parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { if( domainName.isTopPrivateDomain() || domainName.isUnderPublicSuffix() ) { suffix = domainName.topPrivateDomain(); } else { suffix = domainName; } } if (suffix == null) suffix = domainName; return suffix.toString(); }  static String extractHost(String url); static Set<String> extractPublicSuffixes( Metadata metadata ); static String extractPublicSuffix( String url ); static String extractPublicSuffixFromHost( String host ); static String extractPrivateSuffix( String url ); static String extractPrivateSuffixFromHost( String host ); static ImmutableList<String> allLevels(String host); static void main( String[] args ); static final String MALFORMED_HOST; }