diff --git a/.classpath b/.classpath
index 186375e622..6322410b21 100644
--- a/.classpath
+++ b/.classpath
@@ -1,186 +1,187 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework/base/lib/zxing-core-3.2.0.jar b/framework/base/lib/zxing-core-3.2.0.jar
new file mode 100644
index 0000000000..6af9c6299c
Binary files /dev/null and b/framework/base/lib/zxing-core-3.2.0.jar differ
diff --git a/framework/common/config/QRCodeUiLabels.xml b/framework/common/config/QRCodeUiLabels.xml
new file mode 100644
index 0000000000..8ab8c4e1a7
--- /dev/null
+++ b/framework/common/config/QRCodeUiLabels.xml
@@ -0,0 +1,35 @@
+
+
+
+ The QRCode type {0} is not supported!
+ 二维码不支持{0}类型!
+
+
+ The {0} parameter cannot be empty in generateQRCodeImage service!
+ 在generateQRCodeImage服务中,参数{0}不能为空!
+
+
+ Error: the value of {0} parameter is {1}, it is not between {2} and {3}!
+ 错误:参数{0}的值是{1},不在{2}和{3}之间的范围内!
+
+
+ Error while generating QRCode: {0}
+ 生成二维码时出错:{0}
+
+
+ Error: format {0} is not supported.
+ 错误:不支持格式{0}。
+
+
+ Could not write an image of format {0}.
+ 无法写格式为{0}的图片。
+
+
+ Error while verifying QR code: {0}
+ 验证二维码时出错:{0}
+
+
+ The text in generated QR code doesn't match the original:
[Text in QR code]{0}
[Original text]{1}
+ 二维码中的文字信息与原信息不一致:
[二维码中文字]{0}
[原信息文字]{1}
+
+
diff --git a/framework/common/config/qrcode.properties b/framework/common/config/qrcode.properties
new file mode 100644
index 0000000000..968017d7a6
--- /dev/null
+++ b/framework/common/config/qrcode.properties
@@ -0,0 +1,29 @@
+###############################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+###############################################################################
+
+# QRCode default size
+qrcode.default.width=200
+qrcode.default.height=200
+
+# QRCode default format
+qrcode.default.format=png
+qrcode.formats.supported=jpg|png|bmp
+
+# default logo image to put in the center of a QRCode
+qrcode.default.logoimage=component://images/webapp/images/ofbiz.png
diff --git a/framework/common/ofbiz-component.xml b/framework/common/ofbiz-component.xml
index 511098d9d3..f51e6ea122 100644
--- a/framework/common/ofbiz-component.xml
+++ b/framework/common/ofbiz-component.xml
@@ -65,6 +65,7 @@ under the License.
+
diff --git a/framework/common/servicedef/services_qrcode.xml b/framework/common/servicedef/services_qrcode.xml
new file mode 100644
index 0000000000..21fe723630
--- /dev/null
+++ b/framework/common/servicedef/services_qrcode.xml
@@ -0,0 +1,43 @@
+
+
+
+
+ QRCode Services
+ OFBiz
+ 1.0
+
+
+ Generate a QRCode image according to
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework/common/src/org/ofbiz/common/qrcode/QRCodeEvents.java b/framework/common/src/org/ofbiz/common/qrcode/QRCodeEvents.java
new file mode 100644
index 0000000000..f1ede87db2
--- /dev/null
+++ b/framework/common/src/org/ofbiz/common/qrcode/QRCodeEvents.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.common.qrcode;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Locale;
+import java.util.Map;
+import java.lang.Integer;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.ofbiz.base.util.UtilHttp;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ServiceUtil;
+
+/**
+ * Events for QRCode.
+ */
+public class QRCodeEvents {
+
+ public static final String module = QRCodeEvents.class.getName();
+
+ /** Streams QR Code to the output. */
+ public static String serveQRCodeImage(HttpServletRequest request, HttpServletResponse response) {
+ HttpSession session = ((HttpServletRequest) request).getSession();
+ LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
+ Map parameters = UtilHttp.getParameterMap(request);
+ String message = (String) parameters.get("message");
+ GenericValue userLogin = (GenericValue) request.getAttribute("userLogin");
+ if (userLogin == null) userLogin = (GenericValue) session.getAttribute("userLogin");
+ if (userLogin == null) userLogin = (GenericValue) session.getAttribute("autoUserLogin");
+ Locale locale = UtilHttp.getLocale(request);
+
+ if (UtilValidate.isEmpty(message)) {
+ message = "Error get message parameter.";
+ }
+ String format = (String) parameters.get("format");
+ if (UtilValidate.isEmpty(format)) {
+ format = "jpg";
+ }
+ String mimeType = "image/" + format;
+ String width = (String) parameters.get("width");
+ String height = (String) parameters.get("height");
+ String encoding = (String) parameters.get("encoding");
+ Boolean verifyOutput = Boolean.valueOf((String) parameters.get("verifyOutput"));
+ String logoImageMaxWidth = (String) parameters.get("logoImageMaxWidth");
+ String logoImageMaxHeight = (String) parameters.get("logoImageMaxHeight");
+
+ try {
+ if (mimeType != null) {
+ response.setContentType(mimeType);
+ }
+ OutputStream os = response.getOutputStream();
+ Map context = UtilMisc.toMap("message", message, "format", format, "userLogin", userLogin, "locale", locale);
+ if (UtilValidate.isNotEmpty(width)) {
+ try {
+ context.put("width", Integer.parseInt(width));
+ } catch (NumberFormatException e) {
+ // do nothing
+ }
+ if (UtilValidate.isEmpty(height)) {
+ try {
+ context.put("height", Integer.parseInt(width));
+ } catch (NumberFormatException e) {
+ // do nothing
+ }
+ }
+ }
+ if (UtilValidate.isNotEmpty(height)) {
+ try {
+ context.put("height", Integer.parseInt(height));
+ } catch (NumberFormatException e) {
+ // do nothing
+ }
+ if (UtilValidate.isEmpty(width)) {
+ try {
+ context.put("width", Integer.parseInt(height));
+ } catch (NumberFormatException e) {
+ // do nothing
+ }
+ }
+ }
+ if (UtilValidate.isNotEmpty(encoding)) {
+ context.put("encoding", encoding);
+ }
+ if (UtilValidate.isNotEmpty(verifyOutput) && verifyOutput.booleanValue()) {
+ context.put("verifyOutput", verifyOutput);
+ }
+ if (UtilValidate.isNotEmpty(logoImageMaxWidth)) {
+ try {
+ context.put("logoImageMaxWidth", Integer.parseInt(logoImageMaxWidth));
+ } catch (NumberFormatException e) {
+ // do nothing
+ }
+ }
+ if (UtilValidate.isNotEmpty(logoImageMaxHeight)) {
+ try {
+ context.put("logoImageMaxHeight", Integer.parseInt(logoImageMaxHeight));
+ } catch (NumberFormatException e) {
+ // do nothing
+ }
+ }
+ Map results = dispatcher.runSync("generateQRCodeImage", context);
+ if (!ServiceUtil.isError(results)) {
+ BufferedImage bufferedImage = (BufferedImage) results.get("bufferedImage");
+ if (!ImageIO.write(bufferedImage, format, os)) {
+ String errMsg = UtilProperties.getMessage("QRCodeUiLabels", "ErrorWriteFormatToFile", new Object[] { format }, locale);
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+ os.flush();
+ } else {
+ String errMsg = ServiceUtil.getErrorMessage(results);
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+ } catch (IOException e) {
+ String errMsg = UtilProperties.getMessage("QRCodeUiLabels", "ErrorGenerateQRCode", new Object[] { e.getMessage() }, locale);
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ } catch (GenericServiceException e) {
+ String errMsg = UtilProperties.getMessage("QRCodeUiLabels", "ErrorGenerateQRCode", new Object[] { e.getMessage() }, locale);
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+ return "success";
+ }
+}
diff --git a/framework/common/src/org/ofbiz/common/qrcode/QRCodeServices.java b/framework/common/src/org/ofbiz/common/qrcode/QRCodeServices.java
new file mode 100644
index 0000000000..cea32e6984
--- /dev/null
+++ b/framework/common/src/org/ofbiz/common/qrcode/QRCodeServices.java
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.common.qrcode;
+
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.image.AffineTransformOp;
+import java.awt.image.BufferedImage;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.io.IOException;
+import java.lang.Integer;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.FileUtil;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.common.image.ImageTransform;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.ServiceUtil;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.ChecksumException;
+import com.google.zxing.DecodeHintType;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.FormatException;
+import com.google.zxing.MultiFormatWriter;
+import com.google.zxing.NotFoundException;
+import com.google.zxing.WriterException;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.common.DecoderResult;
+import com.google.zxing.common.DetectorResult;
+import com.google.zxing.qrcode.decoder.Decoder;
+import com.google.zxing.qrcode.detector.Detector;
+
+import freemarker.template.utility.StringUtil;
+
+/**
+ * Services for QRCode.
+ */
+public class QRCodeServices {
+
+ public static final String module = QRCodeServices.class.getName();
+
+ public static final String QRCODE_DEFAULT_WIDTH = UtilProperties.getPropertyValue("qrcode.properties", "qrcode.default.width", "200");
+
+ public static final String QRCODE_DEFAULT_HEIGHT = UtilProperties.getPropertyValue("qrcode.properties", "qrcode.default.height", "200");
+
+ public static final String QRCODE_DEFAULT_FORMAT = UtilProperties.getPropertyValue("qrcode.properties", "qrcode.default.format", "jpg");
+
+ public static final String QRCODE_FORMAT_SUPPORTED = UtilProperties.getPropertyValue("qrcode.properties", "qrcode.format.supported", "jpg|png|bmp");
+
+ public static final String QRCODE_DEFAULT_LOGOIMAGE = UtilProperties.getPropertyValue("qrcode.properties", "qrcode.default.logoimage");
+
+ public static BufferedImage defaultLogoImage;
+
+ public static final String[] FORMAT_NAMES = StringUtil.split(QRCODE_FORMAT_SUPPORTED, '|');
+
+ public static final List FORMATS_SUPPORTED = Arrays.asList(FORMAT_NAMES);
+
+ public static final int MIN_SIZE = 20;
+
+ public static final int MAX_SIZE = 500;
+
+ private static final int BLACK = 0xFF000000;
+
+ private static final int WHITE = 0xFFFFFFFF;
+
+ static {
+ if (UtilValidate.isNotEmpty(QRCODE_DEFAULT_LOGOIMAGE)) {
+ try {
+ Map logoImageResult = ImageTransform.getBufferedImage(FileUtil.getFile(QRCODE_DEFAULT_LOGOIMAGE).getAbsolutePath(), Locale.getDefault());
+ defaultLogoImage = (BufferedImage) logoImageResult.get("bufferedImage");
+ if (UtilValidate.isEmpty(defaultLogoImage)) {
+ Debug.logError("Your logo image file(" + QRCODE_DEFAULT_LOGOIMAGE + ") cannot be read by javax.imageio.ImageIO. Please use png, jpeg formats instead of ico and etc.", module);
+ }
+ } catch (IllegalArgumentException e) {
+ defaultLogoImage = null;
+ } catch (IOException e) {
+ defaultLogoImage = null;
+ }
+ }
+ }
+
+ /** Streams QR Code to the result. */
+ public static Map generateQRCodeImage(DispatchContext ctx,Map context) {
+ Locale locale = (Locale) context.get("locale");
+ String message = (String) context.get("message");
+ Integer width = (Integer) context.get("width");
+ Integer height = (Integer) context.get("height");
+ String format = (String) context.get("format");
+ String encoding = (String) context.get("encoding");
+ Boolean verifyOutput = (Boolean) context.get("verifyOutput");
+ String logoImage = (String) context.get("logoImage");
+ Integer logoImageMaxWidth = (Integer) context.get("logoImageMaxWidth");
+ Integer logoImageMaxHeight = (Integer) context.get("logoImageMaxHeight");
+
+ if (UtilValidate.isEmpty(message)) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "ParameterCannotEmpty", new Object[] { "message" }, locale));
+ }
+ if (width == null) {
+ width = Integer.parseInt(QRCODE_DEFAULT_WIDTH);
+ }
+ if (width.intValue() < MIN_SIZE || width.intValue() > MAX_SIZE) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "SizeOutOfBorderError", new Object[] {"width", String.valueOf(width), String.valueOf(MIN_SIZE), String.valueOf(MAX_SIZE)}, locale));
+ }
+ if (height == null) {
+ height = Integer.parseInt(QRCODE_DEFAULT_HEIGHT);
+ }
+ if (height.intValue() < MIN_SIZE || height.intValue() > MAX_SIZE) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "SizeOutOfBorderError",
+ new Object[] { "height", String.valueOf(height), String.valueOf(MIN_SIZE), String.valueOf(MAX_SIZE) }, locale));
+ }
+ if (UtilValidate.isEmpty(format)) {
+ format = QRCODE_DEFAULT_FORMAT;
+ }
+ if (!FORMATS_SUPPORTED.contains(format)) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "ErrorFormatNotSupported", new Object[] { format }, locale));
+ }
+ Map encodeHints = null;
+ if (UtilValidate.isNotEmpty(encoding)) {
+ encodeHints = new EnumMap<>(EncodeHintType.class);
+ encodeHints.put(EncodeHintType.CHARACTER_SET, encoding);
+ }
+
+ try {
+ BitMatrix bitMatrix = new MultiFormatWriter().encode(message, BarcodeFormat.QR_CODE, width, height, encodeHints);
+ BufferedImage bufferedImage = toBufferedImage(bitMatrix, format);
+ BufferedImage logoBufferedImage = null;
+ if (UtilValidate.isNotEmpty(logoImage)) {
+ Map logoImageResult;
+ try {
+ logoImageResult = ImageTransform.getBufferedImage(FileUtil.getFile(logoImage).getAbsolutePath(), locale);
+ logoBufferedImage = (BufferedImage) logoImageResult.get("bufferedImage");
+ } catch (IllegalArgumentException e) {
+ // do nothing
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ if (UtilValidate.isEmpty(logoBufferedImage)) {
+ logoBufferedImage = defaultLogoImage;
+ }
+
+ BufferedImage newBufferedImage = null;
+ if (UtilValidate.isNotEmpty(logoBufferedImage)) {
+ if (UtilValidate.isNotEmpty(logoImageMaxWidth) && UtilValidate.isNotEmpty(logoImageMaxHeight) && (logoBufferedImage.getWidth() > logoImageMaxWidth.intValue() || logoBufferedImage.getHeight() > logoImageMaxHeight.intValue())) {
+ Map typeMap = new HashMap();
+ typeMap.put("width", logoImageMaxWidth.toString());
+ typeMap.put("height", logoImageMaxHeight.toString());
+ Map> dimensionMap = new HashMap>();
+ dimensionMap.put("QRCode", typeMap);
+ Map logoImageResult = ImageTransform.scaleImage(logoBufferedImage, (double) logoBufferedImage.getWidth(), (double) logoBufferedImage.getHeight(), dimensionMap, "QRCode", locale);
+ logoBufferedImage = (BufferedImage) logoImageResult.get("bufferedImage");
+ }
+ BitMatrix newBitMatrix = bitMatrix.clone();
+ newBufferedImage = toBufferedImage(newBitMatrix, format);
+ Graphics2D graphics = newBufferedImage.createGraphics();
+ graphics.drawImage(logoBufferedImage, new AffineTransformOp(AffineTransform.getTranslateInstance(1, 1), null), (newBufferedImage.getWidth() - logoBufferedImage.getWidth())/2, (newBufferedImage.getHeight() - logoBufferedImage.getHeight())/2);
+ graphics.dispose();
+ }
+
+ if (UtilValidate.isNotEmpty(verifyOutput) && verifyOutput.booleanValue()) {
+ // Debug.logInfo("Original Message:[" + message + "]", module);
+ Decoder decoder = new Decoder();
+ Map decodeHints = new EnumMap<>(DecodeHintType.class);
+ decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
+ if (UtilValidate.isNotEmpty(encoding)) {
+ decodeHints.put(DecodeHintType.CHARACTER_SET, encoding);
+ }
+ DetectorResult detectorResult = null;
+ if (UtilValidate.isNotEmpty(newBufferedImage)) {
+ BitMatrix newBitMatrix = createMatrixFromImage(newBufferedImage);
+ DecoderResult result = null;
+ try {
+ detectorResult = new Detector(newBitMatrix).detect(decodeHints);
+ result = decoder.decode(detectorResult.getBits(), decodeHints);
+ } catch (ChecksumException e) {
+ // do nothing
+ } catch (FormatException e) {
+ // do nothing
+ } catch (NotFoundException e) {
+ // do nothing
+ }
+ // Debug.logInfo("Text in QR Code with logo:[" + result.getText() + "]", module);
+ if (UtilValidate.isNotEmpty(result) && !result.getText().equals(message)) {
+ detectorResult = new Detector(bitMatrix).detect(decodeHints);
+ result = decoder.decode(detectorResult.getBits(), decodeHints);
+ // Debug.logInfo("Text in QR Code without logo:[" + result.getText() + "]", module);
+ if (!result.getText().equals(message)) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "GeneratedTextNotMatchOriginal", new Object[]{result.getText(), message}, locale));
+ }
+ } else {
+ bufferedImage = newBufferedImage;
+ }
+ } else {
+ detectorResult = new Detector(bitMatrix).detect(decodeHints);
+ DecoderResult result = decoder.decode(detectorResult.getBits(), decodeHints);
+ // Debug.logInfo("Text in QR Code:[" + result.getText() + "]", module);
+ if (!result.getText().equals(message)) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "GeneratedTextNotMatchOriginal", new Object[]{result.getText(), message}, locale));
+ }
+ }
+ } else if (UtilValidate.isNotEmpty(newBufferedImage)) {
+ bufferedImage = newBufferedImage;
+ }
+
+ Map result = ServiceUtil.returnSuccess();
+ result.put("bufferedImage", bufferedImage);
+ return result;
+ } catch (WriterException e) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "ErrorGenerateQRCode", new Object[] { e.toString() }, locale));
+ } catch (ChecksumException e) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "ErrorVerifyQRCode", new Object[] { e.toString() }, locale));
+ } catch (FormatException e) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "ErrorVerifyQRCode", new Object[] { e.toString() }, locale));
+ } catch (NotFoundException e) {
+ return ServiceUtil.returnError(UtilProperties.getMessage("QRCodeUiLabels", "ErrorVerifyQRCode", new Object[] { e.toString() }, locale));
+ }
+ }
+
+ /**
+ * Renders a {@link BitMatrix} as an image, where "false" bits are rendered
+ * as white, and "true" bits are rendered as black.
+ *
+ * This is to replace MatrixToImageWriter.toBufferedImage(bitMatrix) if you
+ * find the output image is not right, you can change BufferedImage image =
+ * new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); to
+ * BufferedImage image = new BufferedImage(width, height,
+ * BufferedImage.TYPE_INT_RGB); or others to make it work correctly.
+ */
+ private static BufferedImage toBufferedImage(BitMatrix matrix, String format) {
+ int width = matrix.getWidth();
+ int height = matrix.getHeight();
+ BufferedImage image = null;
+ String osName = System.getProperty("os.name").toLowerCase();
+ image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ if (osName.startsWith("mac os") && format.equals("png")) {
+ image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ }
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
+ }
+ }
+ return image;
+ }
+
+ private static BitMatrix createMatrixFromImage(BufferedImage image) {
+ int width = image.getWidth();
+ int height = image.getHeight();
+ int[] pixels = new int[width * height];
+ image.getRGB(0, 0, width, height, pixels, 0, width);
+
+ BitMatrix matrix = new BitMatrix(width, height);
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int pixel = pixels[y * width + x];
+ int luminance = (306 * ((pixel >> 16) & 0xFF) +
+ 601 * ((pixel >> 8) & 0xFF) +
+ 117 * (pixel & 0xFF)) >> 10;
+ if (luminance <= 0x7F) {
+ matrix.set(x, y);
+ }
+ }
+ }
+ return matrix;
+ }
+}
diff --git a/framework/common/webcommon/WEB-INF/common-controller.xml b/framework/common/webcommon/WEB-INF/common-controller.xml
index ea87682e81..4698db3828 100644
--- a/framework/common/webcommon/WEB-INF/common-controller.xml
+++ b/framework/common/webcommon/WEB-INF/common-controller.xml
@@ -255,6 +255,13 @@ under the License.
+
+
+
+
+
+
+
diff --git a/framework/images/webapp/images/icons/famfamfam/ofbiz_barcode.png b/framework/images/webapp/images/icons/famfamfam/ofbiz_barcode.png
new file mode 100644
index 0000000000..5ed50c1370
Binary files /dev/null and b/framework/images/webapp/images/icons/famfamfam/ofbiz_barcode.png differ
diff --git a/framework/images/webapp/images/ofbiz.png b/framework/images/webapp/images/ofbiz.png
new file mode 100644
index 0000000000..d766744833
Binary files /dev/null and b/framework/images/webapp/images/ofbiz.png differ
diff --git a/specialpurpose/example/config/ExampleUiLabels.xml b/specialpurpose/example/config/ExampleUiLabels.xml
index d1ee8503d4..e96355f1a5 100644
--- a/specialpurpose/example/config/ExampleUiLabels.xml
+++ b/specialpurpose/example/config/ExampleUiLabels.xml
@@ -1112,6 +1112,20 @@
PDF With Password
有密码的PDF
+
+ Barcode
+ Barcode
+ Código de barra
+ Code barre
+ Codice a barre
+ バーコード
+ Cod bara
+ Баркод
+ บาร์โคด
+ Mã vạch (Barcode)
+ 条形码
+ 條形碼
+
Set PDF Protected By Password
设置有密码保护的PDF
diff --git a/specialpurpose/example/webapp/example/WEB-INF/controller.xml b/specialpurpose/example/webapp/example/WEB-INF/controller.xml
index eac5a1a4c8..18ee59a78d 100644
--- a/specialpurpose/example/webapp/example/WEB-INF/controller.xml
+++ b/specialpurpose/example/webapp/example/WEB-INF/controller.xml
@@ -231,6 +231,12 @@ under the License.
+
+
+
+
+
+
@@ -243,6 +249,7 @@ under the License.
+
diff --git a/specialpurpose/example/webapp/example/reports/BarCode.fo.ftl b/specialpurpose/example/webapp/example/reports/BarCode.fo.ftl
new file mode 100644
index 0000000000..3f315857c1
--- /dev/null
+++ b/specialpurpose/example/webapp/example/reports/BarCode.fo.ftl
@@ -0,0 +1,63 @@
+<#--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<#escape x as x?xml>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${example.exampleName!}
+
+
+
+
+
+ 0.75in
+ .375mm
+
+
+ bottom
+ Helvetica
+ 18pt
+ false
+ false
+
+
+
+
+
+
+ <#setting url_escaping_charset='UTF-8'>
+
+
+
+
+
+#escape>
diff --git a/specialpurpose/example/widget/example/CommonScreens.xml b/specialpurpose/example/widget/example/CommonScreens.xml
index cb233b9ec1..3fe08b9071 100644
--- a/specialpurpose/example/widget/example/CommonScreens.xml
+++ b/specialpurpose/example/widget/example/CommonScreens.xml
@@ -107,6 +107,10 @@ under the License.
+
+
+
+
diff --git a/specialpurpose/example/widget/example/ExampleScreens.xml b/specialpurpose/example/widget/example/ExampleScreens.xml
index 700aac0a81..e87d2a7b6c 100644
--- a/specialpurpose/example/widget/example/ExampleScreens.xml
+++ b/specialpurpose/example/widget/example/ExampleScreens.xml
@@ -511,4 +511,22 @@ under the License.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+