Tabnine Logo
InternetDomainName.topPrivateDomain
Code IndexAdd Tabnine to your IDE (free)

How to use
topPrivateDomain
method
in
com.google.common.net.InternetDomainName

Best Java code snippets using com.google.common.net.InternetDomainName.topPrivateDomain (Showing top 20 results out of 315)

origin: google/guava

public void testInvalidTopPrivateDomain() {
 ImmutableSet<String> badCookieDomains = ImmutableSet.of("co.uk", "foo", "com");
 for (String domain : badCookieDomains) {
  try {
   InternetDomainName.from(domain).topPrivateDomain();
   fail(domain);
  } catch (IllegalStateException expected) {
  }
 }
}
origin: google/guava

public void testValidTopPrivateDomain() {
 InternetDomainName googleDomain = InternetDomainName.from("google.com");
 assertEquals(googleDomain, googleDomain.topPrivateDomain());
 assertEquals(googleDomain, googleDomain.child("mail").topPrivateDomain());
 assertEquals(googleDomain, googleDomain.child("foo.bar").topPrivateDomain());
}
origin: google/guava

public void testPublicSuffixMultipleUnders() {
 // PSL has both *.uk and *.sch.uk; the latter should win.
 // See http://code.google.com/p/guava-libraries/issues/detail?id=1176
 InternetDomainName domain = InternetDomainName.from("www.essex.sch.uk");
 assertTrue(domain.hasPublicSuffix());
 assertEquals("essex.sch.uk", domain.publicSuffix().toString());
 assertEquals("www.essex.sch.uk", domain.topPrivateDomain().toString());
}
origin: internetarchive/heritrix3

/**
 * Adds outlinks to whois:{domain} and whois:{ipAddress} 
 */
protected void addWhoisLinks(CrawlURI curi) throws InterruptedException {
  CrawlHost ch = serverCache.getHostFor(curi.getUURI());
  if (ch == null) {
    return;
  }
  if (ch.getIP() != null) {
    // do a whois lookup on the ip address
    addWhoisLink(curi, ch.getIP().getHostAddress());
  }
  if (InternetDomainName.isValid(ch.getHostName())) {
    // do a whois lookup on the domain
    try {
      String topmostAssigned = InternetDomainName.from(ch.getHostName()).topPrivateDomain().toString();
      addWhoisLink(curi, topmostAssigned);
    } catch (IllegalStateException e) {
      // java.lang.IllegalStateException: Not under a public suffix: mod.uk
      logger.warning("problem resolving topmost assigned domain, will try whois lookup on the plain hostname " + ch.getHostName() + " - " + e);
      addWhoisLink(curi, ch.getHostName());
    }
  }
}

origin: stackoverflow.com

 public class Test {
 public static void main(String[] args) throws URISyntaxException {
  ImmutableList<String> urls = ImmutableList.of(
    "http://example.google.com", "http://google.com", 
    "http://bing.bing.bing.com", "http://www.amazon.co.jp/");
  for (String url : urls) {
   System.out.println(url + " -> " + getTopPrivateDomain(url));
  }
 }

 private static String getTopPrivateDomain(String url) throws URISyntaxException {
  String host = new URI(url).getHost();
  InternetDomainName domainName = InternetDomainName.from(host);
  return domainName.topPrivateDomain().name();
 }
}
origin: stackoverflow.com

 public static String getTopLevelDomain(String uri) {

InternetDomainName fullDomainName = InternetDomainName.from(uri);
InternetDomainName publicDomainName = fullDomainName.topPrivateDomain();
String topDomain = "";

Iterator<String> it = publicDomainName.parts().iterator();
while(it.hasNext()){
  String part = it.next();
  if(!topDomain.isEmpty())topDomain += ".";
  topDomain += part;
}
return topDomain;
}
origin: bit4woo/domain_hunter

public static String getRootDomain(String inputDomain) {
  try {
    String rootDomain =InternetDomainName.from(inputDomain).topPrivateDomain().toString();
    return rootDomain;
  }catch(Exception e) {
    return null;
  }
}

origin: nielsbasjes/yauaa

private String extractCompanyFromHostName(String hostname) {
  try {
    InternetDomainName domainName = InternetDomainName.from(hostname);
    return Normalize.brand(domainName.topPrivateDomain().parts().get(0));
  } catch (RuntimeException e) {
    return null;
  }
}
origin: bit4woo/domain_hunter

      public void actionPerformed(ActionEvent e) {
        String enteredRootDomain = JOptionPane.showInputDialog("Enter Root Domain", null);
        enteredRootDomain = enteredRootDomain.trim();
        enteredRootDomain =InternetDomainName.from(enteredRootDomain).topPrivateDomain().toString();
        String keyword = enteredRootDomain.substring(0,enteredRootDomain.indexOf("."));
        
        domainResult.AddToRootDomainMap(enteredRootDomain, keyword);
        showToUI(domainResult);
      
        
/*                if (domainResult.rootDomainMap.containsKey(enteredRootDomain) && domainResult.rootDomainMap.containsValue(keyword)) {
          //do nothing
        }else {
          domainResult.rootDomainMap.put(enteredRootDomain,keyword);
          showToUI(domainResult);
        }*/
      }
    });
origin: jvelo/mayocat-shop

private String extractSlugFromHost(String host)
{
  String rootDomain;
  String siteName = siteSettings.getWebDomainName().or(siteSettings.getDomainName());
  if (Strings.emptyToNull(siteName) == null) {
    InternetDomainName domainName = InternetDomainName.from(host);
    if (domainName.hasPublicSuffix()) {
      // Domain is under a valid TLD, extract the TLD + first child
      rootDomain = domainName.topPrivateDomain().name();
    } else if (host.indexOf(".") > 0 && host.indexOf(".") < host.length()) {
      // Otherwise, best guess : strip everything before the first dot.
      rootDomain = host.substring(host.indexOf(".") + 1);
    } else {
      rootDomain = host;
    }
  } else {
    rootDomain = StringUtils.substringBefore(siteSettings.getDomainName(), ":");
  }
  if (host.indexOf("." + rootDomain) > 0) {
    return host.substring(0, host.indexOf("." + rootDomain));
  } else {
    return host;
  }
}
origin: ukwa/webarchive-discovery

  suffix = domainName.topPrivateDomain();
} else {
  suffix = domainName;
origin: de.otto/jlineup-core

  domain = ".localhost";
} else {
  domain = ".".concat(InternetDomainName.from(new URL(screenshotContext.url).getHost()).topPrivateDomain().toString());
origin: com.google.guava/guava-tests

public void testInvalidTopPrivateDomain() {
 ImmutableSet<String> badCookieDomains =
   ImmutableSet.of("co.uk", "foo", "com");
 for (String domain : badCookieDomains) {
  try {
   InternetDomainName.from(domain).topPrivateDomain();
   fail(domain);
  } catch (IllegalStateException expected) {
  }
 }
}
origin: ViDA-NYU/ache

public static String getTopLevelDomain(String host) {
  InternetDomainName domain = null;
  try {
    domain = getDomainName(host);
    if(domain.isUnderPublicSuffix()) {
      return domain.topPrivateDomain().toString();
    } else {
      // if the domain is a public suffix, just use it as top level domain
      return domain.toString();
    }
  } catch (IllegalArgumentException e) {
    // when host is an IP address, use it as TLD
    if(InetAddresses.isInetAddress(host)) {
      return host;
    }
    throw new IllegalStateException("Invalid top private domain name=["+domain+"] in URL=["+host+"]", e);
  }
}

origin: com.google.guava/guava-tests

public void testValidTopPrivateDomain() {
 InternetDomainName googleDomain = InternetDomainName.from("google.com");
 assertEquals(googleDomain, googleDomain.topPrivateDomain());
 assertEquals(googleDomain, googleDomain.child("mail").topPrivateDomain());
 assertEquals(googleDomain, googleDomain.child("foo.bar").topPrivateDomain());
}
origin: it.unimi.dsi/webgraph

if (! DOTTED_ADDRESS.matcher(name).matches()) {
  final InternetDomainName idn = InternetDomainName.from(name);
  if (idn.isUnderPublicSuffix()) name = idn.topPrivateDomain().toString();
origin: tcplugins/tcWebHooks

  @Override
  public GeneralisedWebAddress getGeneralisedHostName(URL url) {
    String host = url.getHost();
//        if (! url.getHost().contains(".")) {
//            return GeneralisedWebAddress.build(host, GeneralisedWebAddressType.HOST_ADDRESS);
//        } else 
    InetAddress ip = extractInetAddress(host);
    if (ip != null) {
      if (ip instanceof Inet4Address ) {
        return GeneralisedWebAddress.build(host.replaceFirst("\\d+$", ""), GeneralisedWebAddressType.IPV4_ADDRESS);
      } else if (ip instanceof Inet6Address) {
        return GeneralisedWebAddress.build(ip.getHostAddress(), GeneralisedWebAddressType.IPV6_ADDRESS);
      }
    } else if (InternetDomainName.isValid(host)) { 
      InternetDomainName domainName = InternetDomainName.from(host);
      if (domainName.isUnderPublicSuffix()) {
        return GeneralisedWebAddress.build(domainName.topPrivateDomain().toString(), GeneralisedWebAddressType.DOMAIN_NAME);
      } else if (domainName.hasParent()) {
        return GeneralisedWebAddress.build(domainName.parent().toString(), GeneralisedWebAddressType.DOMAIN_NAME);
      }
      return GeneralisedWebAddress.build(host, GeneralisedWebAddressType.HOST_ADDRESS);
    }
    
    return null;
  }
  
origin: org.archive.heritrix/heritrix-modules

/**
 * Adds outlinks to whois:{domain} and whois:{ipAddress} 
 */
protected void addWhoisLinks(CrawlURI curi) throws InterruptedException {
  CrawlHost ch = serverCache.getHostFor(curi.getUURI());
  if (ch == null) {
    return;
  }
  if (ch.getIP() != null) {
    // do a whois lookup on the ip address
    addWhoisLink(curi, ch.getIP().getHostAddress());
  }
  if (InternetDomainName.isValid(ch.getHostName())) {
    // do a whois lookup on the domain
    try {
      String topmostAssigned = InternetDomainName.from(ch.getHostName()).topPrivateDomain().toString();
      addWhoisLink(curi, topmostAssigned);
    } catch (IllegalStateException e) {
      // java.lang.IllegalStateException: Not under a public suffix: mod.uk
      logger.warning("problem resolving topmost assigned domain, will try whois lookup on the plain hostname " + ch.getHostName() + " - " + e);
      addWhoisLink(curi, ch.getHostName());
    }
  }
}

origin: ViDA-NYU/ache

public TargetModelElasticSearch(TargetModelCbor model) {
  URL url = Urls.toJavaURL(model.url);
  String rawContent = (String) model.response.get("body");
  Page page = new Page(url, rawContent);
  page.setParsedData(new ParsedData(new PaginaURL(url, rawContent)));
  this.html = rawContent;
  this.url = model.url;
  this.retrieved = new Date(model.timestamp * 1000);
  this.words = page.getParsedData().getWords();
  this.wordsMeta = page.getParsedData().getWordsMeta();
  this.title = page.getParsedData().getTitle();
  this.domain = url.getHost();
  try {
    this.text = DefaultExtractor.getInstance().getText(page.getContentAsString());
  } catch (Exception e) {
    this.text = "";
  }
  InternetDomainName domainName = InternetDomainName.from(page.getDomainName());
  if (domainName.isUnderPublicSuffix()) {
    this.topPrivateDomain = domainName.topPrivateDomain().toString();
  } else {
    this.topPrivateDomain = domainName.toString();
  }
}
origin: com.google.guava/guava-tests

public void testPublicSuffixMultipleUnders() {
 // PSL has both *.uk and *.sch.uk; the latter should win.
 // See http://code.google.com/p/guava-libraries/issues/detail?id=1176
 InternetDomainName domain = InternetDomainName.from("www.essex.sch.uk");
 assertTrue(domain.hasPublicSuffix());
 assertEquals("essex.sch.uk", domain.publicSuffix().toString());
 assertEquals("www.essex.sch.uk", domain.topPrivateDomain().toString());
}
com.google.common.netInternetDomainNametopPrivateDomain

Javadoc

Returns the portion of this domain name that is one level beneath the #isPublicSuffix(). For example, for x.adwords.google.co.uk it returns google.co.uk, since co.uk is a public suffix. Similarly, for myblog.blogspot.com it returns the same domain, myblog.blogspot.com, since blogspot.com is a public suffix.

If #isTopPrivateDomain() is true, the current domain name instance is returned.

This method can be used to determine the probable highest level parent domain for which cookies may be set, though even that depends on individual browsers' implementations of cookie controls.

Popular methods of InternetDomainName

  • from
    Returns an instance of InternetDomainName after lenient validation. Specifically, validation against
  • toString
    Returns the domain name, normalized to all lower case.
  • hasPublicSuffix
    Indicates whether this domain name ends in a #isPublicSuffix(), including if it is a public suffix i
  • isValid
    Indicates whether the argument is a syntactically valid domain name using lenient validation. Specif
  • isUnderPublicSuffix
    Indicates whether this domain name ends in a #isPublicSuffix(), while not being a public suffix itse
  • isTopPrivateDomain
    Indicates whether this domain name is composed of exactly one subdomain component followed by a #isP
  • hasParent
    Indicates whether this domain is composed of two or more parts.
  • <init>
    Private constructor used to implement #ancestor(int). Argument parts are assumed to be valid, as the
  • ancestor
    Returns the ancestor of the current domain at the given number of levels "higher" (rightward) in the
  • validatePart
    Helper method for #validateSyntax(List). Validates that one part of a domain name is valid.
  • validateSyntax
    Validation method used by to ensure that the domain name is syntactically valid according to RFC 103
  • name
    Returns the domain name, normalized to all lower case.
  • validateSyntax,
  • name,
  • findPublicSuffix,
  • matchesWildcardPublicSuffix,
  • parts,
  • child,
  • hasRegistrySuffix,
  • isTopDomainUnderRegistrySuffix,
  • isUnderRegistrySuffix

Popular in Java

  • Making http post requests using okhttp
  • setContentView (Activity)
  • onRequestPermissionsResult (Fragment)
  • putExtra (Intent)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Reference (javax.naming)
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now