View Javadoc

1   package net.sourceforge.barbecue.linear.ean;
2   
3   import net.sourceforge.barbecue.BarcodeException;
4   
5   public class BooklandBarcode extends EAN13Barcode {
6   
7       public BooklandBarcode(String isbn) throws BarcodeException {
8           super(processIsbn(isbn));
9       }
10  
11      private static String processIsbn(String isbn) throws BarcodeException {
12          // remove any '-' characters, used in ISBN formatting
13          if (isbn.indexOf('-') > -1) {
14              StringBuffer sb = new StringBuffer();
15  
16              for (int i = 0; i < isbn.length(); i++) {
17                  if (isbn.charAt(i) != '-') {
18                      sb.append(isbn.charAt(i));
19                  }
20              }
21              isbn = sb.toString();
22          }
23  
24          // check the length of the value of the ISBN
25          if (isbn.length() != EAN13Barcode.ISBN_SIZE) {
26              throw new BarcodeException("ISBN is an invalid length");
27          }
28  
29          // trim off the check digit
30          // check digit will be created automaticaly as the size is only 11
31          return EAN13Barcode.ISBN_NUMBER_SYSTEM + isbn.substring(0, isbn.length() - 1);        // check digit will be created automaticaly as the size is only 11
32      }
33  }