Class DomainNameUtils


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

      Fields 
      Modifier and Type Field Description
      static java.lang.String ACE_PREFIX
      Prefix for unicode domain name parts.
      static java.lang.String ACE_PREFIX_REGEX  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String canonicalizeHostname​(java.lang.String label)
      Canonicalizes a hostname/domain name by lowercasing and converting unicode to punycode.
      static java.lang.String getSecondLevelDomain​(java.lang.String hostName, java.lang.String tld)
      Returns the second level domain name for a fully qualified host name under a given tld.
      static java.lang.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 java.lang.String getTldFromDomainName​(java.lang.String domainName)
      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 Detail

      • ACE_PREFIX

        public static final java.lang.String ACE_PREFIX
        Prefix for unicode domain name parts.
        See Also:
        Constant Field Values
      • ACE_PREFIX_REGEX

        public static final java.lang.String ACE_PREFIX_REGEX
        See Also:
        Constant Field Values
    • Method Detail

      • 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 java.lang.String canonicalizeHostname​(java.lang.String label)
        Canonicalizes a hostname/domain name by lowercasing and converting unicode to punycode.
      • getTldFromDomainName

        public static java.lang.String getTldFromDomainName​(java.lang.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:
        java.lang.IllegalArgumentException - if there is no TLD
      • getTldFromDomainName

        public static java.lang.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:
        java.lang.IllegalArgumentException - if there is no TLD
      • getSecondLevelDomain

        public static java.lang.String getSecondLevelDomain​(java.lang.String hostName,
                                                            java.lang.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:
        java.lang.IllegalArgumentException - if either argument is null or empty, or the domain name is not under the tld