Class DomainNameUtils

java.lang.Object
google.registry.util.DomainNameUtils

public final class DomainNameUtils extends Object
Utility methods related to domain names.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Prefix for unicode domain name parts.
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Canonicalizes a hostname/domain name by lowercasing and converting unicode to punycode.
    static String
    Returns the second level domain name for a fully qualified host name under a given tld.
    static String
    getTldFromDomainName(com.google.common.net.InternetDomainName domainName)
    Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the leftmost part.
    static String
    Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the leftmost part.
    static boolean
    isUnder(com.google.common.net.InternetDomainName name, com.google.common.net.InternetDomainName potentialParent)
    Checks whether "name" is a strict subdomain of "potentialParent".

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • isUnder

      public static boolean isUnder(com.google.common.net.InternetDomainName name, com.google.common.net.InternetDomainName potentialParent)
      Checks whether "name" is a strict subdomain of "potentialParent".
    • canonicalizeHostname

      public static String canonicalizeHostname(String label)
      Canonicalizes a hostname/domain name by lowercasing and converting unicode to punycode.
    • getTldFromDomainName

      public static String getTldFromDomainName(String domainName)
      Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the leftmost part.

      This method should not be called for subdomains.

      This function is compatible with multi-part tlds, e.g. co.uk. This function will also work on domains for which the registry is not authoritative. If you are certain that the input will be under a TLD this registry controls, then it is preferable to use Registries#findTldForName, which will work on hostnames in addition to domains.

      Parameters:
      domainName - must be a punycode SLD (not a host or unicode)
      Throws:
      IllegalArgumentException - if there is no TLD
    • getTldFromDomainName

      public static String getTldFromDomainName(com.google.common.net.InternetDomainName domainName)
      Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the leftmost part.

      This function is compatible with multi-part TLDs and should not be called with subdomains.

      Throws:
      IllegalArgumentException - if there is no TLD
    • getSecondLevelDomain

      public static String getSecondLevelDomain(String hostName, String tld)
      Returns the second level domain name for a fully qualified host name under a given tld.

      This function is merely a string parsing utility, and does not verify if the tld is operated by the registry.

      Throws:
      IllegalArgumentException - if either argument is null or empty, or the domain name is not under the tld