You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2017/12/09 16:56:43 UTC
svn commit: r1817632 - in
/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement:
CropImage.java FrameImage.java ImageManagementServices.java
ImageUrlServlet.java ReplaceImage.java RotateImage.java
Author: mbrohl
Date: Sat Dec 9 16:56:43 2017
New Revision: 1817632
URL: http://svn.apache.org/viewvc?rev=1817632&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.product.imagemanagement.
(OFBIZ-9777)
Thanks Julian Leichert for reporting and providing the patch.
Modified:
ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/CropImage.java
ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/FrameImage.java
ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageManagementServices.java
ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageUrlServlet.java
ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ReplaceImage.java
ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/RotateImage.java
Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/CropImage.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/CropImage.java?rev=1817632&r1=1817631&r2=1817632&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/CropImage.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/CropImage.java Sat Dec 9 16:56:43 2017
@@ -68,7 +68,7 @@ public class CropImage {
Map<String, Object> contentCtx = new HashMap<String, Object>();
contentCtx.put("contentTypeId", "DOCUMENT");
contentCtx.put("userLogin", userLogin);
- Map<String, Object> contentResult = new HashMap<String, Object>();
+ Map<String, Object> contentResult;
try {
contentResult = dispatcher.runSync("createContent", contentCtx);
} catch (GenericServiceException e) {
@@ -79,7 +79,7 @@ public class CropImage {
Map<String, Object> contentThumb = new HashMap<String, Object>();
contentThumb.put("contentTypeId", "DOCUMENT");
contentThumb.put("userLogin", userLogin);
- Map<String, Object> contentThumbResult = new HashMap<String, Object>();
+ Map<String, Object> contentThumbResult;
try {
contentThumbResult = dispatcher.runSync("createContent", contentThumb);
} catch (GenericServiceException e) {
@@ -102,7 +102,7 @@ public class CropImage {
int h = Integer.parseInt(imageH);
BufferedImage bufNewImg = bufImg.getSubimage(x, y, w, h);
- String mimeType = imageName.substring(imageName.lastIndexOf(".") + 1);
+ String mimeType = imageName.substring(imageName.lastIndexOf('.') + 1);
ImageIO.write(bufNewImg, mimeType, new File(imageServerPath + "/" + productId + "/" + filenameToUse));
double imgHeight = bufNewImg.getHeight();
Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/FrameImage.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/FrameImage.java?rev=1817632&r1=1817631&r2=1817632&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/FrameImage.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/FrameImage.java Sat Dec 9 16:56:43 2017
@@ -69,7 +69,7 @@ public class FrameImage {
public static Map<String, Object> addImageFrame(DispatchContext dctx, Map<String, ? extends Object> context)
throws IOException, JDOMException {
- Map<String, Object> result = new HashMap<String, Object>();
+ Map<String, Object> result;
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
String imageServerPath = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.path", delegator), context);
@@ -159,7 +159,7 @@ public class FrameImage {
Image newImg1 = bufImg1.getScaledInstance(width, height , Image.SCALE_SMOOTH);
Image newImg2 = bufImg2.getScaledInstance(width , height , Image.SCALE_SMOOTH);
BufferedImage bufNewImg = combineBufferedImage(newImg1, newImg2, bufImgType);
- String mimeType = imageName.substring(imageName.lastIndexOf(".") + 1);
+ String mimeType = imageName.substring(imageName.lastIndexOf('.') + 1);
ImageIO.write(bufNewImg, mimeType, new File(imageServerPath + "/" + productId + "/" + filenameToUse));
double imgHeight = bufNewImg.getHeight();
@@ -236,14 +236,14 @@ public class FrameImage {
g.drawImage(image1, null, null);
// Draw Image combine
- Point2D center = new Point2D.Float(bufferedImage.getHeight() / 2, bufferedImage.getWidth() / 2);
- AffineTransform at = AffineTransform.getTranslateInstance(center.getX( ) - (image2.getWidth(null) / 2), center.getY( ) - (image2.getHeight(null) / 2));
+ Point2D center = new Point2D.Float(bufferedImage.getHeight() / 2f, bufferedImage.getWidth() / 2f);
+ AffineTransform at = AffineTransform.getTranslateInstance(center.getX( ) - (image2.getWidth(null) / 2f), center.getY( ) - (image2.getHeight(null) / 2f));
g.transform(at);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.drawImage(image2, 0, 0, null);
Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .35f);
g.setComposite(c);
- at = AffineTransform.getTranslateInstance(center.getX( ) - (bufferedImage.getWidth(null) / 2), center.getY( ) - (bufferedImage.getHeight(null) / 2));
+ at = AffineTransform.getTranslateInstance(center.getX( ) - (bufferedImage.getWidth(null) / 2f), center.getY( ) - (bufferedImage.getHeight(null) / 2f));
g.setTransform(at);
g.drawImage(bufferedImage, 0, 0, null);
g.dispose();
@@ -265,14 +265,14 @@ public class FrameImage {
String mimType = tempFile.get("uploadMimeType").toString();
ByteBuffer imageData = (ByteBuffer) tempFile.get("imageData");
if (UtilValidate.isEmpty(imageName) || UtilValidate.isEmpty(imageData)) {
- session.setAttribute("frameContentId", request.getParameter("frameExistContentId").toString());
- session.setAttribute("frameDataResourceId", request.getParameter("frameExistDataResourceId").toString());
+ session.setAttribute("frameContentId", request.getParameter("frameExistContentId"));
+ session.setAttribute("frameDataResourceId", request.getParameter("frameExistDataResourceId"));
request.setAttribute("_ERROR_MESSAGE_", "There is no frame image, please select the image type *.PNG uploading.");
return "error";
}
if (!"image/png".equals(mimType)) {
- session.setAttribute("frameContentId", request.getParameter("frameExistContentId").toString());
- session.setAttribute("frameDataResourceId", request.getParameter("frameExistDataResourceId").toString());
+ session.setAttribute("frameContentId", request.getParameter("frameExistContentId"));
+ session.setAttribute("frameDataResourceId", request.getParameter("frameExistDataResourceId"));
request.setAttribute("_ERROR_MESSAGE_", "The selected image type is incorrect, please select the image type *.PNG to upload.");
return "error";
}
@@ -386,7 +386,8 @@ public class FrameImage {
}
if (UtilValidate.isNotEmpty(imageName)) {
File file = new File(imageServerPath + "/preview/" +"/previewImage.jpg");
- file.delete();
+ if(!file.delete())
+ Debug.logError("File :" + file.getName() + ", couldn't be loaded", module);
// Image Frame
BufferedImage bufImg1 = ImageIO.read(new File(imageServerPath + "/" + productId + "/" + imageName).getCanonicalFile()); // About Findbugs results, see OFBIZ-9973
BufferedImage bufImg2 = ImageIO.read(new File(imageServerPath + "/frame/" + frameImageName));
@@ -404,7 +405,7 @@ public class FrameImage {
Image newImg1 = bufImg1.getScaledInstance(width, height , Image.SCALE_SMOOTH);
Image newImg2 = bufImg2.getScaledInstance(width , height , Image.SCALE_SMOOTH);
BufferedImage bufNewImg = combineBufferedImage(newImg1, newImg2, bufImgType);
- String mimeType = imageName.substring(imageName.lastIndexOf(".") + 1);
+ String mimeType = imageName.substring(imageName.lastIndexOf('.') + 1);
ImageIO.write(bufNewImg, mimeType, new File(imageServerPath + "/preview/" + "/previewImage.jpg"));
}
@@ -420,8 +421,8 @@ public class FrameImage {
HttpSession session = request.getSession();
if(UtilValidate.isEmpty(request.getParameter("frameContentId"))) {
if (UtilValidate.isNotEmpty(request.getParameter("frameExistContentId")) && UtilValidate.isNotEmpty(request.getParameter("frameExistDataResourceId"))) {
- session.setAttribute("frameExistContentId", request.getParameter("frameExistContentId").toString());
- session.setAttribute("frameDataResourceId", request.getParameter("frameExistDataResourceId").toString());
+ session.setAttribute("frameExistContentId", request.getParameter("frameExistContentId"));
+ session.setAttribute("frameDataResourceId", request.getParameter("frameExistDataResourceId"));
}
request.setAttribute("_ERROR_MESSAGE_", "Required frame image content ID");
return "error";
@@ -451,7 +452,8 @@ public class FrameImage {
String imageServerPath = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.path", (Delegator) context.get("delegator")), context);
File file = new File(imageServerPath + "/preview/" + "/previewImage.jpg").getCanonicalFile();
if (file.exists()) {
- file.delete();
+ if (!file.delete())
+ Debug.logError("File :" + file.getName() + ", couldn't be deleted", module);
}
return "success";
}
Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageManagementServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageManagementServices.java?rev=1817632&r1=1817631&r2=1817632&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageManagementServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageManagementServices.java Sat Dec 9 16:56:43 2017
@@ -28,7 +28,6 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -84,7 +83,6 @@ public class ImageManagementServices {
Locale locale = (Locale) context.get("locale");
if (UtilValidate.isNotEmpty(uploadFileName)) {
- String imageFilenameFormat = EntityUtilProperties.getPropertyValue("catalog", "image.filename.format", delegator);
String imageServerPath = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.path", delegator), context);
String imageServerUrl = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.url", delegator), context);
String rootTargetDirectory = imageServerPath;
@@ -106,7 +104,7 @@ public class ImageManagementServices {
Map<String, Object> contentCtx = new HashMap<String, Object>();
contentCtx.put("contentTypeId", "DOCUMENT");
contentCtx.put("userLogin", userLogin);
- Map<String, Object> contentResult = new HashMap<String, Object>();
+ Map<String, Object> contentResult;
try {
contentResult = dispatcher.runSync("createContent", contentCtx);
} catch (GenericServiceException e) {
@@ -118,14 +116,6 @@ public class ImageManagementServices {
result.put("contentFrameId", contentId);
result.put("contentId", contentId);
- // File to use for original image
- FlexibleStringExpander filenameExpander = FlexibleStringExpander.getInstance(imageFilenameFormat);
- String fileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "type", sizeType, "id", contentId));
- String filenameToUse = fileLocation;
- if (fileLocation.lastIndexOf("/") != -1) {
- filenameToUse = fileLocation.substring(fileLocation.lastIndexOf("/") + 1);
- }
-
String fileContentType = (String) context.get("_uploadedFile_contentType");
if ("image/pjpeg".equals(fileContentType)) {
fileContentType = "image/jpeg";
@@ -133,19 +123,6 @@ public class ImageManagementServices {
fileContentType = "image/png";
}
- List<GenericValue> fileExtension = new LinkedList<GenericValue>();
- try {
- fileExtension = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", fileContentType).queryList();
- } catch (GenericEntityException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
- }
-
- GenericValue extension = EntityUtil.getFirst(fileExtension);
- if (extension != null) {
- filenameToUse += "." + extension.getString("fileExtensionId");
- }
-
// Create folder product id.
String targetDirectory = imageServerPath + "/" + productId;
File targetDir = new File(targetDirectory);
@@ -165,6 +142,8 @@ public class ImageManagementServices {
if (UtilValidate.isNotEmpty(file)) {
imageName = file.getPath();
imageName = imageName.substring(imageName.lastIndexOf(File.separator) + 1);
+ } else {
+ imageName = "";
}
if (UtilValidate.isEmpty(imageResize)) {
@@ -187,7 +166,6 @@ public class ImageManagementServices {
if (UtilValidate.isNotEmpty(imageResize)) {
File fileOriginal = new File(imageServerPath + "/" + productId + "/" + imageName);
fileOriginal = checkExistsImage(fileOriginal);
- uploadFileName = fileOriginal.getName();
try {
RandomAccessFile outFile = new RandomAccessFile(fileOriginal, "rw");
@@ -207,11 +185,15 @@ public class ImageManagementServices {
try {
resultResize.putAll(scaleImageMangementInAllSize(dctx, context, imageName, sizeType, productId));
} catch (IOException e) {
- String errMsg = UtilProperties.getMessage(resourceError, "ProductScaleAdditionalImageInAllDifferentSizesIsImpossible", UtilMisc.toMap("errorString", e.toString()), locale);
+ String errMsg = UtilProperties.getMessage(resourceError,
+ "ProductScaleAdditionalImageInAllDifferentSizesIsImpossible", UtilMisc.toMap("errorString",
+ e.toString()), locale);
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
} catch (JDOMException e) {
- String errMsg = UtilProperties.getMessage(resourceError, "ProductErrorsOccurInParsingImageProperties.xml", UtilMisc.toMap("errorString", e.toString()), locale);
+ String errMsg = UtilProperties.getMessage(resourceError,
+ "ProductErrorsOccurInParsingImageProperties.xml", UtilMisc.toMap("errorString", e
+ .toString()), locale);
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
}
@@ -291,7 +273,8 @@ public class ImageManagementServices {
if (UtilValidate.isNotEmpty(contentId)) {
String imageServerPath = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.path", delegator), context);
File file = new File(imageServerPath + "/" + productId + "/" + dataResourceName);
- file.delete();
+ if (!file.delete())
+ Debug.logError("File :" + file.getName() + ", couldn't be deleted", module);
}
} catch (Exception e) {
return ServiceUtil.returnError(e.getMessage());
@@ -336,7 +319,7 @@ public class ImageManagementServices {
/* IMAGE */
// get Name and Extension
- index = filenameToUse.lastIndexOf(".");
+ index = filenameToUse.lastIndexOf('.');
String imgExtension = filenameToUse.substring(index + 1);
// paths
String imageServerPath = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.path", dctx.getDelegator()), context);
@@ -383,7 +366,8 @@ public class ImageManagementServices {
try {
ImageIO.write(bufNewImg, imgExtension, new File(imageServerPath + "/" + productId + "/" + filenameToUse));
File deleteFile = new File(imageServerPath + "/" + filenameToUse);
- deleteFile.delete();
+ if (!deleteFile.delete())
+ Debug.logError("File :" + deleteFile.getName() + ", couldn't be deleted", module);
} catch (IllegalArgumentException e) {
String errMsg = UtilProperties.getMessage(resourceError, "ScaleImage.one_parameter_is_null", locale) + e.toString();
Debug.logError(errMsg, module);
@@ -430,7 +414,7 @@ public class ImageManagementServices {
dataResourceCtx.put("mimeTypeId", fileContentType);
dataResourceCtx.put("isPublic", "Y");
- Map<String, Object> dataResourceResult = new HashMap<String, Object>();
+ Map<String, Object> dataResourceResult;
try {
dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx);
} catch (GenericServiceException e) {
@@ -496,7 +480,7 @@ public class ImageManagementServices {
Map<String, Object> contentThumb = new HashMap<String, Object>();
contentThumb.put("contentTypeId", "DOCUMENT");
contentThumb.put("userLogin", userLogin);
- Map<String, Object> contentThumbResult = new HashMap<String, Object>();
+ Map<String, Object> contentThumbResult;
try {
contentThumbResult = dispatcher.runSync("createContent", contentThumb);
} catch (GenericServiceException e) {
@@ -506,7 +490,7 @@ public class ImageManagementServices {
String contentIdThumb = (String) contentThumbResult.get("contentId");
result.put("contentIdThumb", contentIdThumb);
- String filenameToUseThumb = imageName.substring(0 , imageName.indexOf(".")) + nameOfThumb;
+ String filenameToUseThumb = imageName.substring(0 , imageName.indexOf('.')) + nameOfThumb;
String fileContentType = (String) context.get("_uploadedFile_contentType");
if ("image/pjpeg".equals(fileContentType)) {
fileContentType = "image/jpeg";
@@ -514,7 +498,7 @@ public class ImageManagementServices {
fileContentType = "image/png";
}
- List<GenericValue> fileExtensionThumb = new LinkedList<GenericValue>();
+ List<GenericValue> fileExtensionThumb;
try {
fileExtensionThumb = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", fileContentType).queryList();
} catch (GenericEntityException e) {
@@ -546,18 +530,6 @@ public class ImageManagementServices {
UtilMisc.toMap("fileName", fileOriginalThumb.getAbsolutePath()), locale));
}
- Map<String, Object> resultResizeThumb = new HashMap<String, Object>();
- try {
- resultResizeThumb.putAll(scaleImageMangementInAllSize(dctx, context, filenameToUseThumb, "thumbnail", productId));
- } catch (IOException e) {
- String errMsg = UtilProperties.getMessage(resourceError, "ProductScaleAdditionalImageInAllDifferentSizesIsImpossible", UtilMisc.toMap("errorString", e.toString()), locale);
- Debug.logError(e, errMsg, module);
- return ServiceUtil.returnError(errMsg);
- } catch (JDOMException e) {
- String errMsg = UtilProperties.getMessage(resourceError, "ProductErrorsOccurInParsingImageProperties.xml", UtilMisc.toMap("errorString", e.toString()), locale);
- Debug.logError(e, errMsg, module);
- return ServiceUtil.returnError(errMsg);
- }
return result;
}
@@ -614,8 +586,8 @@ public class ImageManagementServices {
return file;
}
imageCount++;
- String filePath = imagePath.substring(0, imagePath.lastIndexOf("."));
- String type = imagePath.substring(imagePath.lastIndexOf(".") + 1);
+ String filePath = imagePath.substring(0, imagePath.lastIndexOf('.'));
+ String type = imagePath.substring(imagePath.lastIndexOf('.') + 1);
file = new File(filePath + "(" + imageCount + ")." + type);
return checkExistsImage(file);
}
@@ -685,8 +657,8 @@ public class ImageManagementServices {
BufferedImage bufImg = ImageIO.read(new File(imageServerPath + "/" + productId + "/" + dataResourceName));
double imgHeight = bufImg.getHeight();
double imgWidth = bufImg.getWidth();
- if (dataResourceName.lastIndexOf(".") > 0 && dataResourceName.lastIndexOf(".") < dataResourceName.length()) {
- imageType = dataResourceName.substring(dataResourceName.lastIndexOf("."));
+ if (dataResourceName.lastIndexOf('.') > 0 && dataResourceName.lastIndexOf('.') < dataResourceName.length()) {
+ imageType = dataResourceName.substring(dataResourceName.lastIndexOf('.'));
}
String filenameToUse = dataResourceName.substring(0, dataResourceName.length() - 4) + "-" + resizeWidth + imageType;
@@ -699,7 +671,7 @@ public class ImageManagementServices {
Map<String, Object> contentThumb = new HashMap<String, Object>();
contentThumb.put("contentTypeId", "DOCUMENT");
contentThumb.put("userLogin", userLogin);
- Map<String, Object> contentThumbResult = new HashMap<String, Object>();
+ Map<String, Object> contentThumbResult;
try {
contentThumbResult = dispatcher.runSync("createContent", contentThumb);
} catch (GenericServiceException e) {
@@ -724,7 +696,7 @@ public class ImageManagementServices {
return ServiceUtil.returnError(e.getMessage());
}
}
- } catch (Exception e) {
+ } catch (IOException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
@@ -768,21 +740,22 @@ public class ImageManagementServices {
String productId = (String) context.get("productId");
String contentId = (String) context.get("contentId");
String filenameToUse = (String) context.get("drDataResourceName");
- String imageType = filenameToUse.substring(filenameToUse.lastIndexOf("."));
+ String imageType = filenameToUse.substring(filenameToUse.lastIndexOf('.'));
String imgExtension = filenameToUse.substring(filenameToUse.length() - 3, filenameToUse.length());
String imageUrl = imageServerUrl + "/" + productId + "/" + filenameToUse;
try {
GenericValue productContent = EntityQuery.use(delegator).from("ProductContentAndInfo").where("productId", productId, "contentId", contentId, "productContentTypeId", "IMAGE").queryFirst();
String dataResourceName = (String) productContent.get("drDataResourceName");
- String mimeType = filenameToUse.substring(filenameToUse.lastIndexOf("."));
+ String mimeType = filenameToUse.substring(filenameToUse.lastIndexOf('.'));
if (imageType.equals(mimeType)) {
BufferedImage bufImg = ImageIO.read(new File(imageServerPath + "/" + productId + "/" + dataResourceName));
ImageIO.write(bufImg, imgExtension, new File(imageServerPath + "/" + productId + "/" + filenameToUse));
File file = new File(imageServerPath + "/" + productId + "/" + dataResourceName);
- file.delete();
+ if (!file.delete())
+ Debug.logError("File :" + file.getName() + ", couldn't be deleted", module);
Map<String, Object> contentUp = new HashMap<String, Object>();
contentUp.put("contentId", contentId);
@@ -841,7 +814,8 @@ public class ImageManagementServices {
ImageIO.write(bufImgAssoc, imgExtension, new File(imageServerPath + "/" + productId + "/" + filenameToUseAssoc));
File fileAssoc = new File(imageServerPath + "/" + productId + "/" + drDataResourceNameAssoc);
- fileAssoc.delete();
+ if (!fileAssoc.delete())
+ Debug.logError("File :" + fileAssoc.getName() + ", couldn't be deleted", module);
Map<String, Object> contentAssocMap = new HashMap<String, Object>();
contentAssocMap.put("contentId", contentAssoc.get("contentIdTo"));
@@ -886,7 +860,7 @@ public class ImageManagementServices {
}
}
}
- } catch (Exception e) {
+ } catch (IOException | IllegalArgumentException | GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageUrlServlet.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageUrlServlet.java?rev=1817632&r1=1817631&r2=1817632&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageUrlServlet.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ImageUrlServlet.java Sat Dec 9 16:56:43 2017
@@ -23,7 +23,6 @@ import java.util.LinkedList;
import java.util.List;
import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -49,14 +48,6 @@ public class ImageUrlServlet extends Htt
}
/**
- * @see javax.servlet.http.HttpServlet#init(javax.servlet.ServletConfig)
- */
- @Override
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
- }
-
- /**
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
@@ -80,7 +71,7 @@ public class ImageUrlServlet extends Htt
}
String lastTagElement = tagElements.get(tagElements.size() - 1);
- String contentId = lastTagElement.substring(0, lastTagElement.lastIndexOf("."));
+ String contentId = lastTagElement.substring(0, lastTagElement.lastIndexOf('.'));
String sizeTagElement = null;
if(tagElements.size() > 2){
sizeTagElement = tagElements.get(tagElements.size() - 2);
@@ -112,13 +103,4 @@ public class ImageUrlServlet extends Htt
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Image not found with ID [" + contentId + "]");
}
}
-
- /**
- * @see javax.servlet.http.HttpServlet#destroy()
- */
- @Override
- public void destroy() {
- super.destroy();
- }
-
}
Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ReplaceImage.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ReplaceImage.java?rev=1817632&r1=1817631&r2=1817632&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ReplaceImage.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/ReplaceImage.java Sat Dec 9 16:56:43 2017
@@ -20,6 +20,7 @@ package org.apache.ofbiz.product.imagema
import java.awt.image.BufferedImage;
import java.io.File;
+import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -120,7 +121,7 @@ public class ReplaceImage{
String errMsg = UtilProperties.getMessage(resourceError, "ProductCannotReplaceImage", locale);
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
- } catch (Exception e) {
+ } catch (IOException | IllegalArgumentException e) {
String errMsg = UtilProperties.getMessage(resourceError, "ProductCannotReplaceImage", locale);
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg);
Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/RotateImage.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/RotateImage.java?rev=1817632&r1=1817631&r2=1817632&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/RotateImage.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/imagemanagement/RotateImage.java Sat Dec 9 16:56:43 2017
@@ -66,7 +66,7 @@ public class RotateImage {
Map<String, Object> contentCtx = new HashMap<String, Object>();
contentCtx.put("contentTypeId", "DOCUMENT");
contentCtx.put("userLogin", userLogin);
- Map<String, Object> contentResult = new HashMap<String, Object>();
+ Map<String, Object> contentResult;
try {
contentResult = dispatcher.runSync("createContent", contentCtx);
} catch (GenericServiceException e) {
@@ -77,7 +77,7 @@ public class RotateImage {
Map<String, Object> contentThumb = new HashMap<String, Object>();
contentThumb.put("contentTypeId", "DOCUMENT");
contentThumb.put("userLogin", userLogin);
- Map<String, Object> contentThumbResult = new HashMap<String, Object>();
+ Map<String, Object> contentThumbResult;
try {
contentThumbResult = dispatcher.runSync("createContent", contentThumb);
} catch (GenericServiceException e) {
@@ -105,11 +105,11 @@ public class RotateImage {
int h = bufImg.getHeight(null);
BufferedImage bufNewImg = new BufferedImage(w, h, bufImgType);
Graphics2D g = bufNewImg.createGraphics();
- g.rotate(Math.toRadians(Double.parseDouble(angle)), w/2, h/2);
+ g.rotate(Math.toRadians(Double.parseDouble(angle)), w / 2.0, h / 2.0);
g.drawImage(bufImg,0,0,null);
g.dispose();
- String mimeType = imageName.substring(imageName.lastIndexOf(".") + 1);
+ String mimeType = imageName.substring(imageName.lastIndexOf('.') + 1);
ImageIO.write(bufNewImg, mimeType, new File(imageServerPath + "/" + productId + "/" + filenameToUse));
double imgHeight = bufNewImg.getHeight();