Author: lektran
Date: Tue Sep 1 01:47:46 2009 New Revision: 809792 URL: http://svn.apache.org/viewvc?rev=809792&view=rev Log: Fix inconsistent new lines reported by André Herbst Modified: ofbiz/branches/release09.04/applications/product/src/org/ofbiz/product/image/ScaleImage.java Modified: ofbiz/branches/release09.04/applications/product/src/org/ofbiz/product/image/ScaleImage.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/applications/product/src/org/ofbiz/product/image/ScaleImage.java?rev=809792&r1=809791&r2=809792&view=diff ============================================================================== --- ofbiz/branches/release09.04/applications/product/src/org/ofbiz/product/image/ScaleImage.java (original) +++ ofbiz/branches/release09.04/applications/product/src/org/ofbiz/product/image/ScaleImage.java Tue Sep 1 01:47:46 2009 @@ -13,11 +13,11 @@ * 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 + * specific language governing permissions and limitations * under the License. *******************************************************************************/ package org.ofbiz.product.image; - + import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; @@ -29,11 +29,11 @@ import java.util.List; import java.util.Locale; import java.util.Map; - + import javax.imageio.ImageIO; - + import javolution.util.FastMap; - + import org.jdom.JDOMException; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilMisc; @@ -41,30 +41,30 @@ import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.service.ServiceUtil; import org.ofbiz.common.image.ImageTransform; - + /** - * ScaleImage Class + * ScaleImage Class * <p> * Scale the original image into 4 different size Types (small, medium, large, detail) */ public class ScaleImage { - + public static final String module = ScaleImage.class.getName(); public static final String resource = "ProductErrorUiLabels"; - + public ScaleImage() { } - + /** * scaleImageInAllSize * <p> * Scale the original image into all different size Types (small, medium, large, detail) * * @param context Context - * @param filenameToUse Filename of future image files + * @param filenameToUse Filename of future image files * @param viewType "Main" view or "additional" view * @param viewNumber If it's the main view, viewNumber = "0" - * @return URL images for all different size types + * @return URL images for all different size types * @throws IllegalArgumentException Any parameter is null * @throws ImagingOpException The transform is non-invertible * @throws IOException Error prevents the document from being fully parsed @@ -72,7 +72,7 @@ */ public static Map<String, Object> scaleImageInAllSize(Map<String, ? extends Object> context, String filenameToUse, String viewType, String viewNumber) throws IllegalArgumentException, ImagingOpException, IOException, JDOMException { - + /* VARIABLES */ Locale locale = (Locale) context.get("locale"); List<String> sizeTypeList = UtilMisc.toList("small", "medium", "large", "detail"); @@ -86,7 +86,7 @@ Map<String, Object> resultBufImgMap = FastMap.newInstance(); Map<String, Object> resultScaleImgMap = FastMap.newInstance(); Map<String, Object> result = FastMap.newInstance(); - + /* ImageProperties.xml */ String imgPropertyFullPath = System.getProperty("ofbiz.home") + "/applications/product/config/ImageProperties.xml"; resultXMLMap.putAll((Map<String, Object>) ImageTransform.getXMLValue(imgPropertyFullPath, locale)); @@ -98,17 +98,17 @@ result.put("errorMessage", errMsg); return result; } - + /* IMAGE */ // get Name and Extension index = filenameToUse.lastIndexOf("."); String imgName = filenameToUse.substring(0, index - 1); String imgExtension = filenameToUse.substring(index + 1); - // paths + // paths String mainFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format"); String imageServerPath = FlexibleStringExpander.expandString(UtilProperties.getPropertyValue("catalog", "image.server.path"), context); String imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix"); - + String id = null; String type = null; if (viewType.toLowerCase().contains("main")) { @@ -126,15 +126,15 @@ if (fileLocation.lastIndexOf("/") != -1) { filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash } - - - + + + /* get original BUFFERED IMAGE */ resultBufImgMap.putAll(ImageTransform.getBufferedImage(imageServerPath + "/" + filePathPrefix + filenameToUse, locale)); - + if (resultBufImgMap.containsKey("responseMessage") && resultBufImgMap.get("responseMessage").equals("success")) { bufImg = (BufferedImage) resultBufImgMap.get("bufferedImage"); - + // get Dimensions imgHeight = (double) bufImg.getHeight(); imgWidth = (double) bufImg.getWidth(); @@ -144,26 +144,26 @@ result.put("errorMessage", errMsg); return result; } - + // new Filename Format FlexibleStringExpander addFilenameExpander = mainFilenameExpander; if (viewType.toLowerCase().contains("additional")) { String addFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.additionalviewsize.format"); addFilenameExpander = FlexibleStringExpander.getInstance(addFilenameFormat); } - + /* scale Image for each Size Type */ Iterator<String> sizeIter = sizeTypeList.iterator(); while (sizeIter.hasNext()) { String sizeType = sizeIter.next(); - + resultScaleImgMap.putAll(ImageTransform.scaleImage(bufImg, imgHeight, imgWidth, imgPropertyMap, sizeType, locale)); - + if (resultScaleImgMap.containsKey("responseMessage") && resultScaleImgMap.get("responseMessage").equals("success")) { bufNewImg = (BufferedImage) resultScaleImgMap.get("bufferedImage"); Double scaleFactorDb = (Double) resultScaleImgMap.get("scaleFactor"); scaleFactor = scaleFactorDb.doubleValue(); - + // define Interpolation Map<RenderingHints.Key, Object> rhMap = FastMap.newInstance(); rhMap.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); @@ -176,12 +176,12 @@ //rhMap.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); rhMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); RenderingHints rh = new RenderingHints(rhMap); - + /* IMAGE TRANFORMATION */ AffineTransform tx = new AffineTransform(); tx.scale(scaleFactor, scaleFactor); - - + + try { op = new AffineTransformOp(tx, rh); } catch (ImagingOpException e) { @@ -190,7 +190,7 @@ result.put("errorMessage", errMsg); return result; } - + // write the New Scaled Image String newFileLocation = null; if (viewType.toLowerCase().contains("main")) { @@ -202,7 +202,7 @@ if (newFileLocation.lastIndexOf("/") != -1) { newFilePathPrefix = newFileLocation.substring(0, newFileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash } - + String targetDirectory = imageServerPath + "/" + newFilePathPrefix; File targetDir = new File(targetDirectory); if (!targetDir.exists()) { @@ -213,7 +213,7 @@ return ServiceUtil.returnError(errMsg); } } - + // write new image try { ImageIO.write(op.filter(bufImg, bufNewImg), imgExtension, new File(imageServerPath + "/" + newFilePathPrefix + filenameToUse)); @@ -228,19 +228,19 @@ result.put("errorMessage", errMsg); return result; } - + /* write Return Result */ String imageUrl = imageUrlPrefix + "/" + newFilePathPrefix + filenameToUse; imgUrlMap.put(sizeType, imageUrl); - + } // scaleImgMap } // sizeIter - + result.put("responseMessage", "success"); result.put("imageUrlMap", imgUrlMap); result.put("original", resultBufImgMap); return result; - + } else { String errMsg = UtilProperties.getMessage(resource, "ScaleImage.unable_to_scale_original_image", locale) + " : " + filenameToUse; Debug.logError(errMsg, module); |
Free forum by Nabble | Edit this page |