001 /*
002 * This library is free software; you can redistribute it and/or modify it
003 * under the terms of the GNU Lesser General Public License (LGPL) as
004 * published by the Free Software Foundation; either version 3.0 of the
005 * License, or (at your option) any later version.
006 *
007 * This library is distributed in the hope that it will be useful, but
008 * WITHOUT ANY WARRANTY; without even the implied warranty of
009 * MERCHANTABILITY of FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010 * Lesser General Public License for more details.
011 *
012 * This file was contributed to JBarcodeBean by Jose Gaonac'h.
013 * Copyright (C) 2004 Jose Gaonac'h.
014 */
015
016 package net.sourceforge.jbarcodebean.model;
017
018 /**
019 * EAN-8 barcode implementation.
020 * If less than 7 digits are supplied, the symbol is invalid
021 * Only the first 7 digits are considered: the checksum (8th digit) is
022 * always generated (MANDATORY_CHECKSUM).
023 *
024 * @author Jose Gaonac'h
025 */
026 public class Ean8 extends Ean13 {
027
028 protected String preprocess(String text) {
029 if (text.length() < 7) return text;
030 text = text.substring(0, 7);
031
032 computeChecksum(text, 7);
033 char[] t = (text.substring(0, 4) + "C" + text.substring(4)).toCharArray();
034 return new String(t);
035 }
036
037 protected String getBarcodeLabelText(String text) {
038 if (text.length() < 7) return text;
039 return text.substring(0, 7) + checkSum;
040 }
041 }