Author: mbrohl
Date: Sat Oct 7 14:10:50 2017 New Revision: 1811427 URL: http://svn.apache.org/viewvc?rev=1811427&view=rev Log: Improved: Fixing defects reported by FindBugs, package org.apache.ofbiz.common.qrcode. (OFBIZ-9633) Thanks Dennis Balkir for reporting and providing the patch. Modified: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeEvents.java ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeServices.java Modified: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeEvents.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeEvents.java?rev=1811427&r1=1811426&r2=1811427&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeEvents.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeEvents.java Sat Oct 7 14:10:50 2017 @@ -47,7 +47,7 @@ public class QRCodeEvents { /** Streams QR Code to the output. */ public static String serveQRCodeImage(HttpServletRequest request, HttpServletResponse response) { - HttpSession session = ((HttpServletRequest) request).getSession(); + HttpSession session = request.getSession(); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); Map<String, Object> parameters = UtilHttp.getParameterMap(request); String message = (String) parameters.get("message"); @@ -72,9 +72,7 @@ public class QRCodeEvents { String logoImageMaxHeight = (String) parameters.get("logoImageMaxHeight"); try { - if (mimeType != null) { - response.setContentType(mimeType); - } + response.setContentType(mimeType); OutputStream os = response.getOutputStream(); Map<String, Object> context = UtilMisc.<String, Object>toMap("message", message, "format", format, "userLogin", userLogin, "locale", locale); if (UtilValidate.isNotEmpty(width)) { Modified: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeServices.java?rev=1811427&r1=1811426&r2=1811427&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeServices.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeServices.java Sat Oct 7 14:10:50 2017 @@ -71,11 +71,11 @@ public class QRCodeServices { public static final String QRCODE_DEFAULT_LOGOIMAGE = UtilProperties.getPropertyValue("qrcode", "qrcode.default.logoimage"); - public static BufferedImage defaultLogoImage; + public static final BufferedImage defaultLogoImage; - public static final String[] FORMAT_NAMES = StringUtil.split(QRCODE_FORMAT_SUPPORTED, '|'); + private static final String[] FORMAT_NAMES = StringUtil.split(QRCODE_FORMAT_SUPPORTED, '|'); - public static final List<String> FORMATS_SUPPORTED = Arrays.asList(FORMAT_NAMES); + private static final List<String> FORMATS_SUPPORTED = Arrays.asList(FORMAT_NAMES); public static final int MIN_SIZE = 20; @@ -87,17 +87,21 @@ public class QRCodeServices { static { if (UtilValidate.isNotEmpty(QRCODE_DEFAULT_LOGOIMAGE)) { - try { - Map<String, Object> 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; + defaultLogoImage = getLogoImageResult(); + } else { + defaultLogoImage = null; + } + } + + private static BufferedImage getLogoImageResult() { + try { + Map<String, Object> logoImageResult = ImageTransform.getBufferedImage(FileUtil.getFile(QRCODE_DEFAULT_LOGOIMAGE).getAbsolutePath(), Locale.getDefault()); + if (UtilValidate.isEmpty(logoImageResult.get("bufferedImage"))) { + 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); } + return (BufferedImage) logoImageResult.get("bufferedImage"); + } catch (IllegalArgumentException | IOException e) { + return null; } } @@ -164,10 +168,10 @@ public class QRCodeServices { BufferedImage newBufferedImage = null; if (UtilValidate.isNotEmpty(logoBufferedImage)) { if (UtilValidate.isNotEmpty(logoImageMaxWidth) && UtilValidate.isNotEmpty(logoImageMaxHeight) && (logoBufferedImage.getWidth() > logoImageMaxWidth.intValue() || logoBufferedImage.getHeight() > logoImageMaxHeight.intValue())) { - Map<String, String> typeMap = new HashMap<String, String>(); + Map<String, String> typeMap = new HashMap<>(); typeMap.put("width", logoImageMaxWidth.toString()); typeMap.put("height", logoImageMaxHeight.toString()); - Map<String, Map<String, String>> dimensionMap = new HashMap<String, Map<String, String>>(); + Map<String, Map<String, String>> dimensionMap = new HashMap<>(); dimensionMap.put("QRCode", typeMap); Map<String, Object> logoImageResult = ImageTransform.scaleImage(logoBufferedImage, (double) logoBufferedImage.getWidth(), (double) logoBufferedImage.getHeight(), dimensionMap, "QRCode", locale); logoBufferedImage = (BufferedImage) logoImageResult.get("bufferedImage"); @@ -248,7 +252,7 @@ public class QRCodeServices { int width = matrix.getWidth(); int height = matrix.getHeight(); BufferedImage image = null; - String osName = System.getProperty("os.name").toLowerCase(); + String osName = System.getProperty("os.name").toLowerCase(Locale.getDefault()); 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); |
Free forum by Nabble | Edit this page |