@Test public void testExtractPublicSuffixFromHost() { testExtractPublicSuffixFromHost("news.bbc.co.uk", "bbc.co.uk"); testExtractPublicSuffixFromHost("bbc.co.uk", "bbc.co.uk"); testExtractPublicSuffixFromHost("place.nhs.uk", "place.nhs.uk"); testExtractPublicSuffixFromHost("nhs.uk", "nhs.uk"); testExtractPublicSuffixFromHost("parliament.uk", "parliament.uk"); }
public static String extractPublicSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return null; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 2 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { suffix = domainName.publicSuffix(); } if( suffix == null ) return null; return suffix.toString(); }
LinkExtractor { public static String extractPublicSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return null; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 2 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { suffix = domainName.publicSuffix(); } if( suffix == null ) return null; return suffix.toString(); } }
LinkExtractor { public static String extractPublicSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return null; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 2 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { suffix = domainName.publicSuffix(); } if( suffix == null ) return null; return suffix.toString(); }  }
LinkExtractor { public static String extractPublicSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return null; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 2 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { suffix = domainName.publicSuffix(); } if( suffix == null ) return null; 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 extractPublicSuffixFromHost( String host ) { if( host == null ) return null; InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch( Exception e ) { return null; } InternetDomainName suffix = null; if( host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if( parts.size() >= 2 ) { suffix = InternetDomainName.from(parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { suffix = domainName.publicSuffix(); } if( suffix == null ) return null; 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; }