Example usage for org.apache.commons.validator.routines.checkdigit EAN13CheckDigit EAN13CheckDigit

List of usage examples for org.apache.commons.validator.routines.checkdigit EAN13CheckDigit EAN13CheckDigit

Introduction

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

Prototype

public EAN13CheckDigit() 

Source Link

Document

Construct a modulus 10 Check Digit routine for EAN/UPC.

Usage

From source file:mobi.nordpos.catalog.action.ProductCreateActionBean.java

@ValidationMethod(priority = 1)
public void validateProductBarcode(ValidationErrors errors) {

    String prefix = getBarcodePrefix();

    if (!prefix.matches("\\d\\d\\d")) {
        prefix = DEFAULT_BARCODE_PREFIX;
    }//from   w  w  w  .j av  a 2s  .c  o  m

    try {
        String plu = getPLU(getProduct().getProductCategory().getCode());
        String code = getShortCode();
        String barcode = prefix.concat(plu).concat(code);
        getProduct().setCode(barcode.concat(new EAN13CheckDigit().calculate(barcode)));
    } catch (CheckDigitException ex) {
        getContext().getValidationErrors().addGlobalError(new SimpleError(ex.getMessage()));
    } catch (SQLException ex) {
        getContext().getValidationErrors().addGlobalError(new SimpleError(ex.getMessage()));
    }
}