Browse Source

Better processing of CSV lines, minor refactoring.

Matt Clark 1 year ago
parent
commit
d10c65873e

+ 2 - 0
.gitignore

@@ -2,3 +2,5 @@
 target/
 cache/
 logs/
+resources/blacklist.conf
+

+ 1 - 1
resources/bulk.html

@@ -121,7 +121,7 @@
 					or download the generated images for free. BarcodeAPI.org is an
 					open source barcode server capable of generating a wide range of
 					barcodes over a RESTful HTTP server.
-					<a href="/licenses.html">licenses</a>
+					<a href="/license.html">license</a>
 				</p>
 			</div>
 			<div class="col-xs-12 col-sm-4">

+ 1 - 1
resources/index.html

@@ -160,7 +160,7 @@
 				<p>Generate barcodes of nearly any type, scan it in the web
 					browser, or download the generated images for free. BarcodeAPI.org
 					is an open source barcode server capable of generating a wide range
-					of barcodes over a RESTful HTTP server. <a href="/licenses.html">licenses</a></p>
+					of barcodes over a RESTful HTTP server. <a href="/license.html">license</a></p>
 			</div>
 			<div class="col-xs-12 col-sm-4">
 				<div class="docs-link row start-xs end-sm">

+ 3 - 3
resources/licenses.html → resources/license.html

@@ -12,14 +12,14 @@
 <link rel="icon" type="image/png" href="/static/favicon.png" />
 
 <script src="/static/index.js"></script>
-<script src="/static/licenses.js"></script>
+<script src="/static/license.js"></script>
 
 <link rel="stylesheet" type="text/css"
 	href="/static/flexboxgrid.min.css" />
 <link rel="stylesheet" type="text/css" href="/static/index.css" />
 </head>
 
-<body onload="loadLicenses();">
+<body onload="loadLicense();">
 	<div class="wrap container-fluid">
 
 		<div class="header row middle-xs between-xs">
@@ -62,7 +62,7 @@
 								Licenses
 							</h2>
 						</div>
-						<pre id="licenses"></pre>
+						<pre id="license"></pre>
 					</div>
 				</div>
 			</div>

+ 4 - 4
resources/static/licenses.js → resources/static/license.js

@@ -1,12 +1,12 @@
-function loadLicenses() {
+function loadLicense() {
 
 	var url = "/static/license.txt";
-	loadFile(url, onloadLicenses);
+	loadFile(url, onloadLicense);
 }
 
-function onloadLicenses(data) {
+function onloadLicense(data) {
 
-	document.getElementById("licenses").innerHTML = data;
+	document.getElementById("license").innerHTML = data;
 }
 
 function loadFile(path, callback) {

+ 26 - 2
src/main/java/org/barcodeapi/core/utils/BulkUtils.java

@@ -29,7 +29,7 @@ public class BulkUtils {
 			String[] record;
 			while ((record = reader.readNext()) != null) {
 				if (requests.size() < max) {
-					requests.add(BarcodeRequest.fromCSV(record));
+					requests.add(buildBarcodeRequest(record));
 				} else {
 					break;
 				}
@@ -58,7 +58,31 @@ public class BulkUtils {
 		}
 	}
 
-	public static ArrayList<CachedBarcode> generateBarcodes(ArrayList<BarcodeRequest> requests)
+	private static BarcodeRequest buildBarcodeRequest(String[] record) throws GenerationException {
+
+		String params = "";
+		String type = "auto";
+		if (record.length >= 2 && !record[1].equals("")) {
+			type = record[1];
+		}
+
+		// size
+		if (record.length >= 3 && !record[2].equals("")) {
+			params += "size=" + record[2] + "&";
+		}
+
+		// dpi
+		if (record.length >= 4 && !record[3].equals("")) {
+			params += "dpi=" + record[3] + "&";
+		}
+
+		String uri = String.format(//
+				"/api/%s/%s?", type, record[0], params);
+
+		return new BarcodeRequest(uri);
+	}
+
+	private static ArrayList<CachedBarcode> generateBarcodes(ArrayList<BarcodeRequest> requests)
 			throws GenerationException {
 
 		ArrayList<CachedBarcode> barcodes = new ArrayList<>();

+ 0 - 11
src/main/java/org/barcodeapi/server/gen/BarcodeRequest.java

@@ -98,15 +98,4 @@ public class BarcodeRequest {
 	public JSONObject getOptions() {
 		return options;
 	}
-
-	public static BarcodeRequest fromCSV(String[] record) throws GenerationException {
-
-		String type = "auto";
-		if (record.length > 1) {
-			type = record[1];
-		}
-
-		return new BarcodeRequest(String.format(//
-				"/api/%s/%s", type, record[0]));
-	}
 }

+ 27 - 3
src/main/java/org/barcodeapi/server/gen/CodeType.java

@@ -8,7 +8,8 @@ public enum CodeType {
 	UPC_E(new String[] { "e", "upc-e", "upce" }, //
 			"^(?=.*0)[0-9]{8}$", //
 			"^(?=.*0)[0-9]{7,8}$", //
-			""),
+			"01023459", //
+			"A compact version of UPC-A which removes unneeded '0's."),
 
 	/**
 	 * UPC-A type UPC code;
@@ -16,7 +17,8 @@ public enum CodeType {
 	UPC_A(new String[] { "a", "upc-a", "upca", "upc" }, //
 			"^(?=.*0)[0-9]{12}$", //
 			"^(?=.*0)[0-9]{11,12}$", //
-			""),
+			"123456789012", //
+			"Used as a product identifier in many countries, the 12 digit barcode allows information about manufacturer, product, variant, and additional store use codes."),
 
 	/**
 	 * EAN-8 type UPC code;
@@ -26,6 +28,7 @@ public enum CodeType {
 	EAN8(new String[] { "8", "ean-8", "ean8" }, //
 			"^[0-9]{8}$", //
 			"^[0-9]{7,8}$", //
+			"01023459", //
 			""),
 
 	/**
@@ -36,6 +39,7 @@ public enum CodeType {
 	EAN13(new String[] { "13", "ean-13", "ean13" }, //
 			"^[0-9]{13}$", //
 			"^[0-9]{12,13}$", //
+			"1234567890128", //
 			""),
 
 	/**
@@ -44,6 +48,7 @@ public enum CodeType {
 	CODABAR(new String[] { "codabar" }, //
 			"^[0-9:$]{4,12}$", //
 			"^[0-9-:$\\/.+]+$", //
+			"1234567890", //
 			""),
 
 	/**
@@ -54,6 +59,7 @@ public enum CodeType {
 	Code39(new String[] { "39", "code-39", "code39" }, //
 			"^[A-Z0-9 $.\\/]{1,12}$", //
 			"^[A-Z*0-9 -$%.\\/+]+$", //
+			"TRY 39 ME", //
 			""),
 
 	/**
@@ -64,6 +70,7 @@ public enum CodeType {
 	Code128(new String[] { "128", "code-128", "code128" }, //
 			"^[ !#$()*.\\/0-9=?A-Z_a-z~]{1,16}$", //
 			"^[ !\"#$%&'()*+,-.\\/0-9:;<=>?@A-Z\\[\\\\\\]^_`a-z{|}~]+$", //
+			"Try Me!", //
 			""),
 
 	/**
@@ -74,6 +81,7 @@ public enum CodeType {
 	Aztec(new String[] { "aztec" }, //
 			"^[ !#$()*.\\/0-9=?A-Z_a-z~]{1,16}$", //
 			"^[ !\"#$%&'()*+,-.\\/0-9:;<=>?@A-Z\\[\\\\\\]^_`a-z{|}~]+$", //
+			"", //
 			""),
 
 	/**
@@ -84,6 +92,7 @@ public enum CodeType {
 	QRCode(new String[] { "qr", "qr-code", "qrcode" }, //
 			"^.{1,64}$", //
 			"^.{1,65535}$", //
+			"", //
 			""),
 
 	/**
@@ -94,6 +103,7 @@ public enum CodeType {
 	DataMatrix(new String[] { "dm", "data-matrix", "datamatrix", "matrix", "data" }, //
 			"^[ !\"#$%&'()*+,-.\\/0-9:;<=>?@A-Z\\[\\\\\\]^_`a-z{|}~]{1,2335}$", //
 			"^[ !\"#$%&'()*+,-.\\/0-9:;<=>?@A-Z\\[\\\\\\]^_`a-z{|}~]{1,2335}$", //
+			"", //
 			""),
 
 	/**
@@ -104,6 +114,7 @@ public enum CodeType {
 	PDF417(new String[] { "417", "pdf417", "pdf" }, //
 			"^[ !\"#$%&'()*+,-.\\/0-9:;<=>?@A-Z\\[\\\\\\]^_`a-z{|}~]{1,2335}$", //
 			"^[ !\"#$%&'()*+,-.\\/0-9:;<=>?@A-Z\\[\\\\\\]^_`a-z{|}~]{1,2335}$", //
+			"", //
 			"");
 
 	/**
@@ -114,6 +125,7 @@ public enum CodeType {
 	private final String autoPattern;
 	private final String formatPattern;
 
+	private final String example;
 	private final String description;
 
 	/**
@@ -121,13 +133,15 @@ public enum CodeType {
 	 * 
 	 * @param typeStrings
 	 */
-	CodeType(String[] typeStrings, String automatchPattern, String extendedPattern, String description) {
+	CodeType(String[] typeStrings, String automatchPattern, //
+			String extendedPattern, String example, String description) {
 
 		this.types = typeStrings;
 
 		this.autoPattern = automatchPattern;
 		this.formatPattern = extendedPattern;
 
+		this.example = example;
 		this.description = description;
 	}
 
@@ -162,6 +176,16 @@ public enum CodeType {
 	}
 
 	/**
+	 * Get an example barcode format.
+	 * 
+	 * @return
+	 */
+	public String getExample() {
+
+		return example;
+	}
+
+	/**
 	 * Get the description of the specific barcode type.
 	 * 
 	 * @return