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

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

Introduction

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

Prototype

public boolean isValidCountryCodeTld(String ccTld) 

Source Link

Document

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

Usage

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

/**
 * If if the specified <code>countryCode</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/>/* w w w  .j  av  a  2 s.c  om*/
 * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-top-level-domain-country}
 *
 * @param countryCode              Country code to validate
 * @param customExceptionClassName Class name of the exception to throw
 * @throws Exception if not valid
 */
@Processor
public void validateTopLevelDomainCountry(String countryCode,
        @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName)
        throws Exception {
    DomainValidator validator = DomainValidator.getInstance();

    if (!validator.isValidCountryCodeTld(countryCode)) {
        throw buildException(customExceptionClassName);
    }
}