@Test public void testCreateBarcode() { Barcode barcode = SimpleBarcodesUtility.createBarcode( INCORRECT_DATA, INCORRECT_TYPE, false ); assertThat( barcode, is( nullValue() ) ); for ( BarcodeTypeInfo info : barcodeTypes ) { barcode = SimpleBarcodesUtility.createBarcode( info.getValue(), info.getType(), false ); assertThat( barcode, is( instanceOf( info.getClazz() ) ) ); if ( info.isCheckIncorrect() ) { barcode = SimpleBarcodesUtility.createBarcode( StringUtils.EMPTY, info.getType(), false ); assertThat( barcode, is( nullValue() ) ); } } }
public static Barcode createBarcode( final String data, final String type, final boolean checksum ) { if ( data == null || type == null ) { throw new IllegalArgumentException( "Barcode type or data must not be null" ); } if ( BARCODE_CODE39.equals( type ) ) { try { return new Code39Barcode( data, checksum, false ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODE39EXT.equals( type ) ) { try { return new Code39Barcode( data, checksum, true ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODABAR.equals( type ) ) { try { return new CodabarBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong codabar data supplied", e ); return null; } } if ( BARCODE_EAN13.equals( type ) ) { try { return new EAN13Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong ean13 data supplied", e ); return null; } } if ( BARCODE_UPCA.equals( type ) ) { try { return new UPCABarcode( data, false ); } catch ( BarcodeException e ) { logger.error( "Wrong upca data supplied", e ); return null; } } if ( BARCODE_ISBN.equals( type ) ) { try { return new BooklandBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong isbn data supplied", e ); return null; } } if ( BARCODE_CODE128.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.O ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128A.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.A ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128B.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.B ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128C.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.C ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_UCCEAN128.equals( type ) ) { try { return new UCCEAN128Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong uccean128 data supplied", e ); return null; } } if ( BARCODE_2OF5.equals( type ) ) { try { return new Std2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong std2of5 data supplied", e ); return null; } } if ( BARCODE_2OF5INT.equals( type ) ) { try { return new Int2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong int2of5 data supplied", e ); return null; } } if ( BARCODE_POSTNET.equals( type ) ) { try { if ( checksum ) { logger.info( "Checkum property is not usable on barcode " + type ); } return new PostNetBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } if ( BARCODE_PDF417.equals( type ) ) { try { return new PDF417Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } logger.warn( "Unknown barcode type '" + type + "'." ); return null; }
SimpleBarcodesUtility { public static Barcode createBarcode( final String data, final String type, final boolean checksum ) { if ( data == null || type == null ) { throw new IllegalArgumentException( "Barcode type or data must not be null" ); } if ( BARCODE_CODE39.equals( type ) ) { try { return new Code39Barcode( data, checksum, false ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODE39EXT.equals( type ) ) { try { return new Code39Barcode( data, checksum, true ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODABAR.equals( type ) ) { try { return new CodabarBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong codabar data supplied", e ); return null; } } if ( BARCODE_EAN13.equals( type ) ) { try { return new EAN13Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong ean13 data supplied", e ); return null; } } if ( BARCODE_UPCA.equals( type ) ) { try { return new UPCABarcode( data, false ); } catch ( BarcodeException e ) { logger.error( "Wrong upca data supplied", e ); return null; } } if ( BARCODE_ISBN.equals( type ) ) { try { return new BooklandBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong isbn data supplied", e ); return null; } } if ( BARCODE_CODE128.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.O ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128A.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.A ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128B.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.B ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128C.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.C ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_UCCEAN128.equals( type ) ) { try { return new UCCEAN128Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong uccean128 data supplied", e ); return null; } } if ( BARCODE_2OF5.equals( type ) ) { try { return new Std2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong std2of5 data supplied", e ); return null; } } if ( BARCODE_2OF5INT.equals( type ) ) { try { return new Int2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong int2of5 data supplied", e ); return null; } } if ( BARCODE_POSTNET.equals( type ) ) { try { if ( checksum ) { logger.info( "Checkum property is not usable on barcode " + type ); } return new PostNetBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } if ( BARCODE_PDF417.equals( type ) ) { try { return new PDF417Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } logger.warn( "Unknown barcode type '" + type + "'." ); return null; } }
SimpleBarcodesUtility { public static Barcode createBarcode( final String data, final String type, final boolean checksum ) { if ( data == null || type == null ) { throw new IllegalArgumentException( "Barcode type or data must not be null" ); } if ( BARCODE_CODE39.equals( type ) ) { try { return new Code39Barcode( data, checksum, false ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODE39EXT.equals( type ) ) { try { return new Code39Barcode( data, checksum, true ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODABAR.equals( type ) ) { try { return new CodabarBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong codabar data supplied", e ); return null; } } if ( BARCODE_EAN13.equals( type ) ) { try { return new EAN13Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong ean13 data supplied", e ); return null; } } if ( BARCODE_UPCA.equals( type ) ) { try { return new UPCABarcode( data, false ); } catch ( BarcodeException e ) { logger.error( "Wrong upca data supplied", e ); return null; } } if ( BARCODE_ISBN.equals( type ) ) { try { return new BooklandBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong isbn data supplied", e ); return null; } } if ( BARCODE_CODE128.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.O ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128A.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.A ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128B.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.B ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128C.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.C ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_UCCEAN128.equals( type ) ) { try { return new UCCEAN128Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong uccean128 data supplied", e ); return null; } } if ( BARCODE_2OF5.equals( type ) ) { try { return new Std2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong std2of5 data supplied", e ); return null; } } if ( BARCODE_2OF5INT.equals( type ) ) { try { return new Int2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong int2of5 data supplied", e ); return null; } } if ( BARCODE_POSTNET.equals( type ) ) { try { if ( checksum ) { logger.info( "Checkum property is not usable on barcode " + type ); } return new PostNetBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } if ( BARCODE_PDF417.equals( type ) ) { try { return new PDF417Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } logger.warn( "Unknown barcode type '" + type + "'." ); return null; } private  SimpleBarcodesUtility(); }
SimpleBarcodesUtility { public static Barcode createBarcode( final String data, final String type, final boolean checksum ) { if ( data == null || type == null ) { throw new IllegalArgumentException( "Barcode type or data must not be null" ); } if ( BARCODE_CODE39.equals( type ) ) { try { return new Code39Barcode( data, checksum, false ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODE39EXT.equals( type ) ) { try { return new Code39Barcode( data, checksum, true ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODABAR.equals( type ) ) { try { return new CodabarBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong codabar data supplied", e ); return null; } } if ( BARCODE_EAN13.equals( type ) ) { try { return new EAN13Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong ean13 data supplied", e ); return null; } } if ( BARCODE_UPCA.equals( type ) ) { try { return new UPCABarcode( data, false ); } catch ( BarcodeException e ) { logger.error( "Wrong upca data supplied", e ); return null; } } if ( BARCODE_ISBN.equals( type ) ) { try { return new BooklandBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong isbn data supplied", e ); return null; } } if ( BARCODE_CODE128.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.O ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128A.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.A ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128B.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.B ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128C.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.C ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_UCCEAN128.equals( type ) ) { try { return new UCCEAN128Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong uccean128 data supplied", e ); return null; } } if ( BARCODE_2OF5.equals( type ) ) { try { return new Std2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong std2of5 data supplied", e ); return null; } } if ( BARCODE_2OF5INT.equals( type ) ) { try { return new Int2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong int2of5 data supplied", e ); return null; } } if ( BARCODE_POSTNET.equals( type ) ) { try { if ( checksum ) { logger.info( "Checkum property is not usable on barcode " + type ); } return new PostNetBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } if ( BARCODE_PDF417.equals( type ) ) { try { return new PDF417Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } logger.warn( "Unknown barcode type '" + type + "'." ); return null; } private  SimpleBarcodesUtility(); static Barcode createBarcode( final String data, final String type, final boolean checksum ); static BarcodeGenerator createBarcode4J( final String type, final boolean showText, final boolean checksum,
      final Number barHeight ); static String getBarcodeSampleData( final String type ); }
SimpleBarcodesUtility { public static Barcode createBarcode( final String data, final String type, final boolean checksum ) { if ( data == null || type == null ) { throw new IllegalArgumentException( "Barcode type or data must not be null" ); } if ( BARCODE_CODE39.equals( type ) ) { try { return new Code39Barcode( data, checksum, false ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODE39EXT.equals( type ) ) { try { return new Code39Barcode( data, checksum, true ); } catch ( BarcodeException e ) { logger.error( "Wrong code39(ext) data supplied", e ); return null; } } if ( BARCODE_CODABAR.equals( type ) ) { try { return new CodabarBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong codabar data supplied", e ); return null; } } if ( BARCODE_EAN13.equals( type ) ) { try { return new EAN13Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong ean13 data supplied", e ); return null; } } if ( BARCODE_UPCA.equals( type ) ) { try { return new UPCABarcode( data, false ); } catch ( BarcodeException e ) { logger.error( "Wrong upca data supplied", e ); return null; } } if ( BARCODE_ISBN.equals( type ) ) { try { return new BooklandBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong isbn data supplied", e ); return null; } } if ( BARCODE_CODE128.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.O ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128A.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.A ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128B.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.B ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_CODE128C.equals( type ) ) { try { return new Code128Barcode( data, Code128Barcode.C ); } catch ( BarcodeException e ) { logger.error( "Wrong code128 data supplied", e ); return null; } } if ( BARCODE_UCCEAN128.equals( type ) ) { try { return new UCCEAN128Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong uccean128 data supplied", e ); return null; } } if ( BARCODE_2OF5.equals( type ) ) { try { return new Std2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong std2of5 data supplied", e ); return null; } } if ( BARCODE_2OF5INT.equals( type ) ) { try { return new Int2of5Barcode( data, checksum ); } catch ( BarcodeException e ) { logger.error( "Wrong int2of5 data supplied", e ); return null; } } if ( BARCODE_POSTNET.equals( type ) ) { try { if ( checksum ) { logger.info( "Checkum property is not usable on barcode " + type ); } return new PostNetBarcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } if ( BARCODE_PDF417.equals( type ) ) { try { return new PDF417Barcode( data ); } catch ( BarcodeException e ) { logger.error( "Wrong postnet data supplied", e ); return null; } } logger.warn( "Unknown barcode type '" + type + "'." ); return null; } private  SimpleBarcodesUtility(); static Barcode createBarcode( final String data, final String type, final boolean checksum ); static BarcodeGenerator createBarcode4J( final String type, final boolean showText, final boolean checksum,
      final Number barHeight ); static String getBarcodeSampleData( final String type ); static final String BARCODE_CODE39; static final String BARCODE_CODE39EXT; static final String BARCODE_CODABAR; static final String BARCODE_CODE128; static final String BARCODE_CODE128A; static final String BARCODE_CODE128B; static final String BARCODE_CODE128C; static final String BARCODE_EAN13; static final String BARCODE_UPCA; static final String BARCODE_ISBN; static final String BARCODE_UCCEAN128; static final String BARCODE_2OF5; static final String BARCODE_2OF5INT; static final String BARCODE_POSTNET; static final String BARCODE_PDF417; static final String BARCODE_EAN8; static final String BARCODE_EAN128; static final String BARCODE_UPCE; static final String BARCODE_DATAMATRIX; static final String BARCODE_ROYALMAIL; static final String BARCODE_USPSINTELLIGENTMAIL; }