Improved: Fixing defects reported by FindBugs, package

org.apache.ofbiz.common.qrcode.
(OFBIZ-9633)

Thanks Dennis Balkir for reporting and providing the patch.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1811427 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Brohl
2017-10-07 14:10:50 +00:00
parent 404139505e
commit 2a66a06aef
2 changed files with 22 additions and 20 deletions
@@ -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)) {
@@ -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);