Example usage for org.apache.commons.validator.routines DomainValidator isValidTld

List of usage examples for org.apache.commons.validator.routines DomainValidator isValidTld

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines DomainValidator isValidTld.

Prototype

public boolean isValidTld(String tld) 

Source Link

Document

Returns true if the specified String matches any IANA-defined top-level domain.

Usage

From source file:org.mule.modules.validation.ValidationModule.java

/**
 * If if the specified <code>topLevelDomain</code> does not matches any IANA-defined top-level domain throw an exception.
 * Leading dots are ignored if present. The search is case-sensitive.
 * <p/>//from  www.j a  va 2  s  .  co  m
 * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-top-level-domain}
 *
 * @param topLevelDomain           Domain name to validate
 * @param customExceptionClassName Class name of the exception to throw
 * @throws Exception if not valid
 */
@Processor
public void validateTopLevelDomain(String topLevelDomain,
        @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName)
        throws Exception {
    DomainValidator validator = DomainValidator.getInstance();

    if (!validator.isValidTld(topLevelDomain)) {
        throw buildException(customExceptionClassName);
    }
}