org.apache.commons.validator.routines
Class DomainValidator

java.lang.Object
  extended by org.apache.commons.validator.routines.DomainValidator
All Implemented Interfaces:
java.io.Serializable

public class DomainValidator
extends java.lang.Object
implements java.io.Serializable

Domain name validation routines.

This validator provides methods for validating Internet domain names and top-level domains.

Domain names are evaluated according to the standards RFC1034, section 3, and RFC1123, section 2.1. No accomodation is provided for the specialized needs of other applications; if the domain name has been URL-encoded, for example, validation will fail even though the equivalent plaintext version of the same name would have passed.

Validation is also provided for top-level domains (TLDs) as defined and maintained by the Internet Assigned Numbers Authority (IANA):

(NOTE: This class does not provide IP address lookup for domain names or methods to ensure that a given domain name matches a specific IP; see InetAddress for that functionality.)

Since:
Validator 1.4
Version:
$Revision: 600231 $ $Date: 2007-12-02 04:39:09 +0100 (So, 02. Dez 2007) $
See Also:
Serialized Form

Field Summary
private static java.util.List COUNTRY_CODE_TLD_LIST
           
private static java.lang.String[] COUNTRY_CODE_TLDS
           
private static java.lang.String DOMAIN_LABEL_REGEX
           
private static java.lang.String DOMAIN_NAME_REGEX
           
private static DomainValidator DOMAIN_VALIDATOR
          Singleton instance of this validator.
private  RegexValidator domainRegex
          RegexValidator for matching domains.
private static java.util.List GENERIC_TLD_LIST
           
private static java.lang.String[] GENERIC_TLDS
           
private static java.util.List INFRASTRUCTURE_TLD_LIST
           
private static java.lang.String[] INFRASTRUCTURE_TLDS
           
private static java.lang.String TOP_LABEL_REGEX
           
 
Constructor Summary
private DomainValidator()
          Private constructor.
 
Method Summary
private  java.lang.String chompLeadingDot(java.lang.String str)
           
static DomainValidator getInstance()
          Returns the singleton instance of this validator.
 boolean isValid(java.lang.String domain)
          Returns true if the specified String parses as a valid domain name with a recognized top-level domain.
 boolean isValidCountryCodeTld(java.lang.String ccTld)
          Returns true if the specified String matches any IANA-defined country code top-level domain.
 boolean isValidGenericTld(java.lang.String gTld)
          Returns true if the specified String matches any IANA-defined generic top-level domain.
 boolean isValidInfrastructureTld(java.lang.String iTld)
          Returns true if the specified String matches any IANA-defined infrastructure top-level domain.
 boolean isValidTld(java.lang.String tld)
          Returns true if the specified String matches any IANA-defined top-level domain.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOMAIN_LABEL_REGEX

private static final java.lang.String DOMAIN_LABEL_REGEX
See Also:
Constant Field Values

TOP_LABEL_REGEX

private static final java.lang.String TOP_LABEL_REGEX
See Also:
Constant Field Values

DOMAIN_NAME_REGEX

private static final java.lang.String DOMAIN_NAME_REGEX
See Also:
Constant Field Values

DOMAIN_VALIDATOR

private static final DomainValidator DOMAIN_VALIDATOR
Singleton instance of this validator.


domainRegex

private final RegexValidator domainRegex
RegexValidator for matching domains.


INFRASTRUCTURE_TLDS

private static final java.lang.String[] INFRASTRUCTURE_TLDS

GENERIC_TLDS

private static final java.lang.String[] GENERIC_TLDS

COUNTRY_CODE_TLDS

private static final java.lang.String[] COUNTRY_CODE_TLDS

INFRASTRUCTURE_TLD_LIST

private static final java.util.List INFRASTRUCTURE_TLD_LIST

GENERIC_TLD_LIST

private static final java.util.List GENERIC_TLD_LIST

COUNTRY_CODE_TLD_LIST

private static final java.util.List COUNTRY_CODE_TLD_LIST
Constructor Detail

DomainValidator

private DomainValidator()
Private constructor.

Method Detail

getInstance

public static DomainValidator getInstance()
Returns the singleton instance of this validator.

Returns:
the singleton instance of this validator

isValid

public boolean isValid(java.lang.String domain)
Returns true if the specified String parses as a valid domain name with a recognized top-level domain. The parsing is case-sensitive.

Parameters:
domain - the parameter to check for domain name syntax
Returns:
true if the parameter is a valid domain name

isValidTld

public boolean isValidTld(java.lang.String tld)
Returns true if the specified String matches any IANA-defined top-level domain. Leading dots are ignored if present. The search is case-sensitive.

Parameters:
tld - the parameter to check for TLD status
Returns:
true if the parameter is a TLD

isValidInfrastructureTld

public boolean isValidInfrastructureTld(java.lang.String iTld)
Returns true if the specified String matches any IANA-defined infrastructure top-level domain. Leading dots are ignored if present. The search is case-sensitive.

Parameters:
iTld - the parameter to check for infrastructure TLD status
Returns:
true if the parameter is an infrastructure TLD

isValidGenericTld

public boolean isValidGenericTld(java.lang.String gTld)
Returns true if the specified String matches any IANA-defined generic top-level domain. Leading dots are ignored if present. The search is case-sensitive.

Parameters:
gTld - the parameter to check for generic TLD status
Returns:
true if the parameter is a generic TLD

isValidCountryCodeTld

public boolean isValidCountryCodeTld(java.lang.String ccTld)
Returns true if the specified String matches any IANA-defined country code top-level domain. Leading dots are ignored if present. The search is case-sensitive.

Parameters:
ccTld - the parameter to check for country code TLD status
Returns:
true if the parameter is a country code TLD

chompLeadingDot

private java.lang.String chompLeadingDot(java.lang.String str)


Copyright (c) 2001-2004 Apache Software Foundation