Class DomainUtils


  • public final class DomainUtils
    extends java.lang.Object
    Utilities for working with domain names.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DOMAINNAME_CHAR_REGEX_STRING
      Valid characters in a domain name, according to RFC3490.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String domainNameFromHostname​(java.lang.String hostname)
      Return a domain name.
      static boolean isValidDomainName​(java.lang.String domainName)
      Check if a given domainName is valid domain.
      static java.lang.String reduceHostname​(java.lang.String hostname)
      Reduce a hostname to a more readable form.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isValidDomainName

        public static boolean isValidDomainName​(java.lang.String domainName)
        Check if a given domainName is valid domain. A valid domain is an IP address or a domain name part followed by a TLD as defined in settings.
        Parameters:
        domainName - A name of a domain (netarkivet.dk)
        Returns:
        true if domain is valid; otherwise it returns false.
      • domainNameFromHostname

        public static java.lang.String domainNameFromHostname​(java.lang.String hostname)
        Return a domain name. A domain name is defined as either an IP address if the given host is an IP address, or a postfix of the given host name containing one hostname part and a TLD as defined in settings.

        E.g. if '.dk' and 'co.uk' are valid TLDs, www.netarchive.dk will be become netarchive.dk and news.bbc.co.uk will be come bbc.co.uk

        Parameters:
        hostname - A hostname or IP address. Null hostname is not allowed
        Returns:
        A domain name (foo.bar) or IP address, or null if no valid domain could be obtained from the given hostname. If non-null, the return value is guaranteed to be a valid domain as determined by isValidDomainName().
      • reduceHostname

        public static java.lang.String reduceHostname​(java.lang.String hostname)
                                               throws ArgumentNotValid
        Reduce a hostname to a more readable form.
        Parameters:
        hostname - A host name, should not be null.
        Returns:
        The same host name with all domain parts stripped off.
        Throws:
        ArgumentNotValid - if argument isn't valid.