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

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

Introduction

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

Prototype

public boolean isValidISBN13(String code) 

Source Link

Document

Check the code is a valid ISBN-13 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  ww  w . j  ava2s  .c o  m
        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  v  a 2s.  c  o  m
 * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-isbn13}
 *
 * @param isbnCode                 ISBN code to validate
 * @param customExceptionClassName Class name of the exception to throw
 * @throws Exception if not valid
 */
@Processor(name = "validate-isbn13")
public void validateISBN13(String isbnCode,
        @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName)
        throws Exception {
    ISBNValidator validator = ISBNValidator.getInstance();

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