dk.netarkivet.common.utils
Class DomainUtils

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

public 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)
          Method mathcing valid domains.
 
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)
Method mathcing valid domains. A valid domain is an IP address or a domainname part followed by a TLD as defined in settings.


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.
Returns:
A domain name (foo.bar) or IP address, or null if no valid hostname could be obtained from the given hostname. If non-null, the return value is guaranteed to be a valid hostname as determined by isValidDomainName().