1 /***********************************************************************************************************************
2 * Copyright (c) 2003, International Barcode Consortium
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this list of
11 * conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 * Neither the name of the International Barcode Consortium nor the names of any contributors may be used to endorse
14 * or promote products derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 ***********************************************************************************************************************/
26
27
28
29 package net.sourceforge.barbecue;
30
31 import net.sourceforge.barbecue.linear.codabar.CodabarBarcode;
32 import net.sourceforge.barbecue.linear.code128.Code128Barcode;
33 import net.sourceforge.barbecue.linear.code39.Code39Barcode;
34 import net.sourceforge.barbecue.linear.ean.BooklandBarcode;
35 import net.sourceforge.barbecue.linear.ean.EAN13Barcode;
36 import net.sourceforge.barbecue.linear.ean.UCCEAN128Barcode;
37 import net.sourceforge.barbecue.linear.postnet.PostNetBarcode;
38 import net.sourceforge.barbecue.linear.twoOfFive.Int2of5Barcode;
39 import net.sourceforge.barbecue.linear.twoOfFive.Std2of5Barcode;
40 import net.sourceforge.barbecue.linear.upc.UPCABarcode;
41 import net.sourceforge.barbecue.twod.pdf417.PDF417Barcode;
42
43 /**
44 * This factory provides a standard way of creating barcodes.
45 *
46 * @author <a href="mailto:opensource@ianbourke.com">Ian Bourke</a>
47 */
48 public final class BarcodeFactory {
49
50 /**
51 * You can't construct one of these.
52 */
53 private BarcodeFactory() {
54 }
55
56 /**
57 * Creates a Code 128 barcode that dynamically switches between character sets
58 * to give the smallest possible encoding. This will encode
59 * all numeric characters, upper and lower case alpha characters and control characters
60 * from the standard ASCII character set. The size of the barcode created will be the
61 * smallest possible for the given data, and use of this "optimal" encoding will
62 * generally give smaller barcodes than any of the other 3 "vanilla" encodings.
63 *
64 * @param data The data to encode
65 * @return The barcode
66 * @throws BarcodeException If the data to be encoded is invalid
67 */
68 public static Barcode createCode128(String data) throws BarcodeException {
69 return new Code128Barcode(data, Code128Barcode.O);
70 }
71
72 /**
73 * Creates a Code 128 barcode using the A character set. This will encode
74 * all numeric characters, upper case alpha characters and control characters
75 * from the standard ASCII character set. The Code 128 barcode supports on-the-fly
76 * character set changes using the appropriate code change symbol. The type A barcode
77 * also supports a one character 'shift' to set B.
78 *
79 * @param data The data to encode
80 * @return The barcode
81 * @throws BarcodeException If the data to be encoded is invalid
82 */
83 public static Barcode createCode128A(String data) throws BarcodeException {
84 return new Code128Barcode(data, Code128Barcode.A);
85 }
86
87 /**
88 * Creates a Code 128 barcode using the B character set. This will encode
89 * all numeric characters and upper and lower case alpha characters
90 * from the standard ASCII character set. The Code 128 barcode supports on-the-fly
91 * character set changes using the appropriate code change symbol. The type B barcode
92 * also supports a one character 'shift' to set A.
93 *
94 * @param data The data to encode
95 * @return The barcode
96 * @throws BarcodeException If the data to be encoded is invalid
97 */
98 public static Barcode createCode128B(String data) throws BarcodeException {
99 return new Code128Barcode(data, Code128Barcode.B);
100 }
101
102 /**
103 * Creates a Code 128 barcode using the C character set. This will encode
104 * only numeric characters in a double density format (e.g. 1 digit in the barcode
105 * encodes two digits in the data). The Code 128 barcode supports on-the-fly
106 * character set changes using the appropriate code change symbol. No shifts are
107 * possible with the type C barcode.
108 *
109 * @param data The data to encode
110 * @return The barcode
111 * @throws BarcodeException If the data to be encoded is invalid
112 */
113 public static Barcode createCode128C(String data) throws BarcodeException {
114 return new Code128Barcode(data, Code128Barcode.C);
115 }
116
117 /**
118 * Creates a UCC 128 barcode. This will encode numeric characters and must
119 * include the correct application identifier for the application domain in which
120 * you wish to use the barcode.
121 *
122 * @param applicationIdentifier The application identifier for the domain
123 * @param data The data to encode
124 * @return The barcode
125 * @throws BarcodeException If the data to be encoded is invalid
126 */
127 public static Barcode createUCC128(String applicationIdentifier, String data) throws BarcodeException {
128 return new UCCEAN128Barcode(applicationIdentifier, data);
129 }
130
131 /**
132 * Creates a EAN 128 barcode.
133 *
134 * @param data The data to encode
135 * @return The barcode
136 * @throws BarcodeException If the data to be encoded is invalid
137 */
138 public static Barcode createEAN128(String data) throws BarcodeException {
139 return new UCCEAN128Barcode(UCCEAN128Barcode.EAN128_AI, data);
140 }
141
142 /**
143 * Creates a US Postal Service barcode based on the UCC/EAN 128 symbology.
144 *
145 * @param data The data to encode
146 * @return The barcode
147 * @throws BarcodeException If the data to be encoded is invalid
148 */
149 public static Barcode createUSPS(String data) throws BarcodeException {
150 return new UCCEAN128Barcode(UCCEAN128Barcode.USPS_AI, data);
151 }
152
153 /**
154 * Creates a shipment identification number based on the UCC/EAN 128 symbology.
155 *
156 * @param data The data to encode
157 * @return The barcode
158 * @throws BarcodeException If the data to be encoded is invalid
159 */
160 public static Barcode createShipmentIdentificationNumber(String data) throws BarcodeException {
161 return new UCCEAN128Barcode(UCCEAN128Barcode.SHIPMENT_ID_AI, data);
162 }
163
164 /**
165 * Create an EAN128 barcode with multiple application identifiers (AI's). The data is
166 * specified in a string of the form (ai) data (ai) data. For example
167 * (01)0941919600001(10)012004(21)000001 will create a barcode consisting
168 * of a GTIN AI (01) and the data '0941919600001' (note: the
169 * GTIN check digit is calculated automatically.), then a lot AI (10)
170 * followed by the lot number '012004', and an item AI (21) with item
171 * number 000001.
172 */
173 public static Barcode parseEAN128(String encoded_data) throws BarcodeException {
174 return new UCCEAN128Barcode(encoded_data);
175 }
176
177 /**
178 * Creates an SSCC-18 number based on the UCC/EAN 128 symbology.
179 *
180 * @param data The data to encode
181 * @return The barcode
182 * @throws BarcodeException If the data to be encoded is invalid
183 */
184 public static Barcode createSSCC18(String data) throws BarcodeException {
185 return new UCCEAN128Barcode(UCCEAN128Barcode.SSCC_18_AI, data);
186 }
187
188 /**
189 * Creates an SCC-14 shipping code number based on the UCC/EAN 128 symbology.
190 *
191 * @param data The data to encode
192 * @return The barcode
193 * @throws BarcodeException If the data to be encoded is invalid
194 */
195 public static Barcode createSCC14ShippingCode(String data) throws BarcodeException {
196 return new UCCEAN128Barcode(UCCEAN128Barcode.SCC_14_AI, data);
197 }
198
199 /**
200 * Creates a Global Trade Item Number (GTIN) based on the UCC/EAN 128 symbology.
201 *
202 * @param data The data to encode
203 * @return The barcode
204 * @throws BarcodeException If the data to be encoded is invalid
205 */
206 public static Barcode createGlobalTradeItemNumber(String data) throws BarcodeException {
207 return new UCCEAN128Barcode(UCCEAN128Barcode.GTIN_AI, data);
208 }
209
210 /**
211 * Creates a barcode based on the EAN 13 Symbology.
212 *
213 * @param data The data to encode
214 * @return The barcode
215 * @throws BarcodeException If the data to be encoded is invalid
216 */
217 public static Barcode createEAN13(String data) throws BarcodeException {
218 return new EAN13Barcode(data);
219 }
220
221 /**
222 * Creates a Bookland barcode, which is based on the EAN 13 Symbology.
223 * For example, if you createBookland("968-26-1240-3") you will receive
224 * an EAN 13 barcode of 9789682612404.
225 * Note that only the '-' character will be automaticaly removed from the
226 * ISBN data.
227 *
228 * @param isbn The ISBN of the book to encode
229 * @return The barcode
230 * @throws BarcodeException If the data to be encoded is invalid
231 */
232 public static Barcode createBookland(String isbn) throws BarcodeException {
233 return new BooklandBarcode(isbn);
234 }
235
236 /**
237 * Creates a barcode based on the UPC-A Symbology.
238 *
239 * @param data The data to encode
240 * @return The barcode
241 * @throws BarcodeException If the data to be encoded is invalid
242 */
243 public static Barcode createUPCA(String data) throws BarcodeException {
244 return new UPCABarcode(data);
245 }
246
247 /**
248 * Creates a barcode based on the UPC-A Symbology signifying a random weight.
249 *
250 * @param data The data to encode
251 * @return The barcode
252 * @throws BarcodeException If the data to be encoded is invalid
253 */
254 public static Barcode createRandomWeightUPCA(String data) throws BarcodeException {
255 return new UPCABarcode(data, true);
256 }
257
258 /**
259 * Creates a barcode based on the Standard 2 of 5 Symbology.
260 *
261 * @param data The data to encode
262 * @return The barcode
263 * @throws BarcodeException If the data to be encoded is invalid
264 * @see #createStd2of5(String, boolean)
265 */
266 public static Barcode createStd2of5(String data) throws BarcodeException {
267 return new Std2of5Barcode(data);
268 }
269
270 /**
271 * Creates a barcode based on the Standard 2 of 5 Symbology.
272 *
273 * @param data The data to encode
274 * @param checkDigit if true then a check digit is appended automatically
275 * @return The barcode
276 * @throws BarcodeException If the data to be encoded is invalid
277 * @see #createStd2of5(String)
278 */
279 public static Barcode createStd2of5(String data, boolean checkDigit) throws BarcodeException {
280 return new Std2of5Barcode(data, checkDigit);
281 }
282
283 /**
284 * Creates a barcode based on the Interleave 2 of 5 Symbology.
285 *
286 * @param data The data to encode
287 * @return The barcode
288 * @throws BarcodeException If the data to be encoded is invalid
289 * @see #createInt2of5(String, boolean)
290 */
291 public static Barcode createInt2of5(String data) throws BarcodeException {
292 return new Int2of5Barcode(data);
293 }
294
295 /**
296 * Creates a barcode based on the Interleave 2 of 5 Symbology.
297 *
298 * @param data The data to encode
299 * @param checkDigit if true then a check digit is appended automatically
300 * @return The barcode
301 * @throws BarcodeException If the data to be encoded is invalid
302 * @see #createInt2of5(String)
303 */
304 public static Barcode createInt2of5(String data, boolean checkDigit) throws BarcodeException {
305 return new Int2of5Barcode(data, checkDigit);
306 }
307
308 /**
309 * Creates a PDF417 two dimensional barcode.
310 *
311 * @param data The data to encode
312 * @return The barcode
313 * @throws BarcodeException If the data to be encoded is invalid
314 */
315 public static Barcode createPDF417(String data) throws BarcodeException {
316 return new PDF417Barcode(data);
317 }
318
319 /**
320 * Creates a Code 39 linear barcode.
321 *
322 * @param data The data to encode
323 * @param requiresChecksum True if a check digit is required, false if not
324 * @return The barcode
325 * @throws BarcodeException If the data to be encoded is invalid
326 */
327 public static Barcode createCode39(String data, boolean requiresChecksum) throws BarcodeException {
328 return new Code39Barcode(data, requiresChecksum);
329 }
330
331 /**
332 * Creates a Code 3 of 9 (Code 39) linear barcode.
333 *
334 * @param data The data to encode
335 * @param requiresChecksum True if a check digit is required, false if not
336 * @return The barcode
337 * @throws BarcodeException If the data to be encoded is invalid
338 */
339 public static Barcode create3of9(String data, boolean requiresChecksum) throws BarcodeException {
340 return new Code39Barcode(data, requiresChecksum);
341 }
342
343 /**
344 * Creates a USD3 (Code 39) linear barcode.
345 *
346 * @param data The data to encode
347 * @param requiresChecksum True if a check digit is required, false if not
348 * @return The barcode
349 * @throws BarcodeException If the data to be encoded is invalid
350 */
351 public static Barcode createUSD3(String data, boolean requiresChecksum) throws BarcodeException {
352 return new Code39Barcode(data, requiresChecksum);
353 }
354
355 /**
356 * Creates a Codabar linear barcode.
357 *
358 * @param data The data to encode
359 * @return The barcode
360 * @throws BarcodeException If the data to be encoded is invalid
361 */
362 public static Barcode createCodabar(String data) throws BarcodeException {
363 return new CodabarBarcode(data);
364 }
365
366 /**
367 * Creates a USD-4 (Codabar) linear barcode.
368 *
369 * @param data The data to encode
370 * @return The barcode
371 * @throws BarcodeException If the data to be encoded is invalid
372 */
373 public static Barcode createUSD4(String data) throws BarcodeException {
374 return new CodabarBarcode(data);
375 }
376
377 /**
378 * Creates a NW-7 (Codabar) linear barcode.
379 *
380 * @param data The data to encode
381 * @return The barcode
382 * @throws BarcodeException If the data to be encoded is invalid
383 */
384 public static Barcode createNW7(String data) throws BarcodeException {
385 return new CodabarBarcode(data);
386 }
387
388 /**
389 * Creates a Monarch (Codabar) linear barcode.
390 *
391 * @param data The data to encode
392 * @return The barcode
393 * @throws BarcodeException If the data to be encoded is invalid
394 */
395 public static Barcode createMonarch(String data) throws BarcodeException {
396 return new CodabarBarcode(data);
397 }
398
399 /**
400 * Creates a 2 of 7 (Codabar) linear barcode.
401 *
402 * @param data The data to encode
403 * @return The barcode
404 * @throws BarcodeException If the data to be encoded is invalid
405 */
406 public static Barcode create2of7(String data) throws BarcodeException {
407 return new CodabarBarcode(data);
408 }
409
410 /**
411 * Creates a <a href="http://en.wikipedia.org/wiki/POSTNET">PostNet</a> linear barcode.
412 *
413 * @param data The data to encode
414 * @return The barcode
415 * @throws BarcodeException If the data to be encoded is invalid
416 *
417 *
418 *
419 */
420 public static Barcode createPostNet(String data) throws BarcodeException {
421 return new PostNetBarcode(data);
422 }
423 }
424
425
426