Package dk.netarkivet.common.utils
Class DomainUtils
- java.lang.Object
-
- dk.netarkivet.common.utils.DomainUtils
-
public final class DomainUtils extends Object
Utilities for working with domain names.
-
-
Field Summary
Fields Modifier and Type Field Description static 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 String
domainNameFromHostname(String hostname)
Return a domain name.static boolean
isValidDomainName(String domainName)
Check if a given domainName is valid domain.static String
reduceHostname(String hostname)
Reduce a hostname to a more readable form.
-
-
-
Field Detail
-
DOMAINNAME_CHAR_REGEX_STRING
public static final String DOMAINNAME_CHAR_REGEX_STRING
Valid characters in a domain name, according to RFC3490.- See Also:
- Constant Field Values
-
-
Method Detail
-
isValidDomainName
public static boolean isValidDomainName(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 String domainNameFromHostname(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 String reduceHostname(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.
-
-