dk.netarkivet.common.utils
Class DomainUtils

java.lang.Object
  extended by dk.netarkivet.common.utils.DomainUtils

public final class DomainUtils
extends java.lang.Object

Utilities for working with domain names.


Field Summary
static java.lang.String DOMAINNAME_CHAR_REGEX_STRING
          Valid characters in a domain name, according to RFC3490.
static java.lang.String TLD_REGEX_STRING
          A string for a regexp recognising a TLD read from settings.
static java.util.regex.Pattern VALID_DOMAIN_MATCHER
          Regexp for matching a valid domain, that is a single domainnamepart followed by a TLD from settings, or an IP address.
 
Method Summary
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
 

Field Detail

DOMAINNAME_CHAR_REGEX_STRING

public static final java.lang.String DOMAINNAME_CHAR_REGEX_STRING
Valid characters in a domain name, according to RFC3490.

See Also:
Constant Field Values

TLD_REGEX_STRING

public static final java.lang.String TLD_REGEX_STRING
A string for a regexp recognising a TLD read from settings.


VALID_DOMAIN_MATCHER

public static final java.util.regex.Pattern VALID_DOMAIN_MATCHER
Regexp for matching a valid domain, that is a single domainnamepart followed by a TLD from settings, or an IP address.

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 hostnamepart 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.