Example usage for org.apache.commons.validator.routines ISBNValidator isValidISBN10

List of usage examples for org.apache.commons.validator.routines ISBNValidator isValidISBN10

Introduction

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

Prototype

public boolean isValidISBN10(String code) 

Source Link

Document

Check the code is a valid ISBN-10 code.

Usage

From source file:com.github.bfour.fpliteraturecollector.domain.ISBN.java

public ISBN(String v10OrV13String) {

    ISBNValidator validator = ISBNValidator.getInstance();
    String normalizedString = getNormalizedString(v10OrV13String);

    if (validator.isValidISBN13(normalizedString))
        this.v13String = normalizedString;
    else if (validator.isValidISBN10(normalizedString))
        this.v13String = validator.convertToISBN13(normalizedString);
    else//from w  w  w .  j a  va  2 s.c  om
        throw new InvalidParameterException("String passed as ISBN is not a valid v10 or v13 ISBN");

}

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

/**
 * If the specified <code>isbnCode</code> is not a valid one throw an exception.
 * <p/>//from   w w w  .  j a va 2s .c om
 * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-isbn10}
 *
 * @param isbnCode                 ISBN code to validate
 * @param customExceptionClassName Class name of the exception to throw
 * @throws Exception if not valid
 */
@Processor(name = "validate-isbn10")
public void validateISBN10(String isbnCode,
        @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName)
        throws Exception {
    ISBNValidator validator = ISBNValidator.getInstance();

    if (!validator.isValidISBN10(isbnCode)) {
        throw buildException(customExceptionClassName);
    }
}