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

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

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

origin: Graylog2/graylog2-server

/**
 * Extract the domain name (without subdomain). The Guava {@link InternetDomainName} implementation
 * provides a method to correctly handle this (and handles special cases for TLDs with multiple
 * names. eg. for lb01.store.amazon.co.uk, only amazon.co.uk would be extracted).
 * It uses https://publicsuffix.org behind the scenes.
 * <p>
 * Some domains (eg. completely randomly defined PTR domains) are not considered to have a public
 * suffix according to Guava. For those, the only option is to manually extract the domain with
 * string operations. This should be a rare case.
 */
public static void parseReverseLookupDomain(PtrDnsAnswer.Builder dnsAnswerBuilder, String hostname) {
  dnsAnswerBuilder.fullDomain(hostname);
  final InternetDomainName internetDomainName = InternetDomainName.from(hostname);
  if (internetDomainName.hasPublicSuffix()) {
    // Use Guava to extract domain name.
    final InternetDomainName topDomainName = internetDomainName.topDomainUnderRegistrySuffix();
    dnsAnswerBuilder.domain(topDomainName.toString());
  } else {
    /* Manually extract domain name.
     * Eg. for hostname test.some-domain.com, only some-domain.com will be extracted. */
    String[] split = hostname.split("\\.");
    if (split.length > 1) {
      dnsAnswerBuilder.domain(split[split.length - 2] + "." + split[split.length - 1]);
    } else if (split.length == 1) {
      dnsAnswerBuilder.domain(hostname); // Domain is a single word with no dots.
    } else {
      dnsAnswerBuilder.domain(""); // Domain is blank.
    }
  }
}
origin: google/guava

public void testRegistrySuffixMultipleUnders() {
 // 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.hasRegistrySuffix());
 assertEquals("essex.sch.uk", domain.registrySuffix().toString());
 assertEquals("www.essex.sch.uk", domain.topDomainUnderRegistrySuffix().toString());
}
origin: org.graylog2/graylog2-server

/**
 * Extract the domain name (without subdomain). The Guava {@link InternetDomainName} implementation
 * provides a method to correctly handle this (and handles special cases for TLDs with multiple
 * names. eg. for lb01.store.amazon.co.uk, only amazon.co.uk would be extracted).
 * It uses https://publicsuffix.org behind the scenes.
 * <p>
 * Some domains (eg. completely randomly defined PTR domains) are not considered to have a public
 * suffix according to Guava. For those, the only option is to manually extract the domain with
 * string operations. This should be a rare case.
 */
public static void parseReverseLookupDomain(PtrDnsAnswer.Builder dnsAnswerBuilder, String hostname) {
  dnsAnswerBuilder.fullDomain(hostname);
  final InternetDomainName internetDomainName = InternetDomainName.from(hostname);
  if (internetDomainName.hasPublicSuffix()) {
    // Use Guava to extract domain name.
    final InternetDomainName topDomainName = internetDomainName.topDomainUnderRegistrySuffix();
    dnsAnswerBuilder.domain(topDomainName.toString());
  } else {
    /* Manually extract domain name.
     * Eg. for hostname test.some-domain.com, only some-domain.com will be extracted. */
    String[] split = hostname.split("\\.");
    if (split.length > 1) {
      dnsAnswerBuilder.domain(split[split.length - 2] + "." + split[split.length - 1]);
    } else if (split.length == 1) {
      dnsAnswerBuilder.domain(hostname); // Domain is a single word with no dots.
    } else {
      dnsAnswerBuilder.domain(""); // Domain is blank.
    }
  }
}
origin: com.google.guava/guava-tests

public void testRegistrySuffixMultipleUnders() {
 // 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.hasRegistrySuffix());
 assertEquals("essex.sch.uk", domain.registrySuffix().toString());
 assertEquals("www.essex.sch.uk", domain.topDomainUnderRegistrySuffix().toString());
}
com.google.common.netInternetDomainNametopDomainUnderRegistrySuffix

Javadoc

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

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

Warning: This method should not be used to determine whether a domain is probably the highest level for which cookies may be set. Use #isTopPrivateDomain() for that purpose.

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
  • topPrivateDomain
    Returns the portion of this domain name that is one level beneath the public suffix. For example, fo
  • validateSyntax,
  • topPrivateDomain,
  • name,
  • findPublicSuffix,
  • matchesWildcardPublicSuffix,
  • parts,
  • child,
  • hasRegistrySuffix,
  • isTopDomainUnderRegistrySuffix,
  • isUnderRegistrySuffix

Popular in Java

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • getExternalFilesDir (Context)
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • 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