svn commit: r750018 - in /ofbiz/trunk: ./ applications/product/config/ applications/product/src/org/ofbiz/image/ applications/product/src/org/ofbiz/product/image/ applications/product/src/org/ofbiz/product/product/ applications/product/webapp/catalog/W...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r750018 - in /ofbiz/trunk: ./ applications/product/config/ applications/product/src/org/ofbiz/image/ applications/product/src/org/ofbiz/product/image/ applications/product/src/org/ofbiz/product/product/ applications/product/webapp/catalog/W...

jleroux@apache.org
Author: jleroux
Date: Wed Mar  4 14:22:55 2009
New Revision: 750018

URL: http://svn.apache.org/viewvc?rev=750018&view=rev
Log:
Refactoring of ImageTransform, mostly
* Split into 2 classes one in framework/common : ImageTransform, one remains in product : ScaleImage.java
* Moved some labels used by ImageTransformCreated from ProductErrorUiLabels.xml in new CommonErrorUiLabels.xml  
* Moved Jdom from webapp/lib to base/lib, updated .classpath

Added:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/image/
      - copied from r749960, ofbiz/trunk/applications/product/src/org/ofbiz/image/
    ofbiz/trunk/applications/product/src/org/ofbiz/product/image/ScaleImage.java
      - copied, changed from r749960, ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java
    ofbiz/trunk/framework/base/lib/jdom-1.1.jar
      - copied unchanged from r749960, ofbiz/trunk/framework/webapp/lib/jdom-1.1.jar
    ofbiz/trunk/framework/common/config/CommonErrorUiLabels.xml
    ofbiz/trunk/framework/common/src/org/ofbiz/common/image/
      - copied from r749549, ofbiz/trunk/applications/product/src/org/ofbiz/image/
Removed:
    ofbiz/trunk/applications/product/src/org/ofbiz/image/
    ofbiz/trunk/applications/product/src/org/ofbiz/product/image/ImageTransform.java
    ofbiz/trunk/framework/webapp/lib/jdom-1.1.jar
Modified:
    ofbiz/trunk/.classpath
    ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy
    ofbiz/trunk/framework/common/src/org/ofbiz/common/image/ImageTransform.java

Modified: ofbiz/trunk/.classpath
URL: http://svn.apache.org/viewvc/ofbiz/trunk/.classpath?rev=750018&r1=750017&r2=750018&view=diff
==============================================================================
--- ofbiz/trunk/.classpath (original)
+++ ofbiz/trunk/.classpath Wed Mar  4 14:22:55 2009
@@ -133,7 +133,8 @@
  <classpathentry kind="lib" path="framework/base/lib/scripting/asm-tree-2.2.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/scripting/asm-util-2.2.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/scripting/groovy-1.5.6.jar"/>
- <classpathentry kind="lib" path="framework/base/lib/jpim-0.1.jar"/>
+    <classpathentry kind="lib" path="framework/base/lib/jdom-1.1.jar"/>
+    <classpathentry kind="lib" path="framework/base/lib/jpim-0.1.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/freemarker-2.3.15.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/owasp-esapi-full-java-1.4.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/json-lib-2.2.3-jdk15.jar"/>
@@ -144,7 +145,6 @@
  <classpathentry kind="lib" path="specialpurpose/ldap/lib/cas-server-core-3.3.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/xmlgraphics-commons-1.2.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/rome-0.9.jar"/>
- <classpathentry kind="lib" path="framework/webapp/lib/jdom-1.1.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/barcode4j-fop-ext-0.93.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/ws-commons-java5-1.0.1.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/ws-commons-util-1.0.1.jar"/>

Modified: ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml?rev=750018&r1=750017&r2=750018&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml (original)
+++ ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml Wed Mar  4 14:22:55 2009
@@ -19,50 +19,18 @@
     under the License.
 -->
 <resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-    <property key="ImageTransform.error_occurs_during_reading">
-        <value xml:lang="en">An error occurs during reading</value>
-        <value xml:lang="fr">Une erreur est survenue lors de la lecture</value>
-    </property>
     <property key="ImageTransform.error_occurs_during_writing">
         <value xml:lang="en">An error occurs during writing</value>
         <value xml:lang="fr">Une erreur est survenue lors de l'écriture</value>
     </property>
-    <property key="ImageTransform.error_prevents_the document_from_being_fully_parsed">
-        <value xml:lang="en">Error prevents the document from being fully parsed</value>
-        <value xml:lang="fr">Une erreur empêche que le document soit entièrement analysé</value>
-    </property>
-    <property key="ImageTransform.errors_occurs_in_parsing">
-        <value xml:lang="en">Errors occur in parsing</value>
-        <value xml:lang="fr">Des erreurs sont survenues lors de l'analyse</value>
-    </property>
-    <property key="ImageTransform.final_scale_factor_is_null">
-        <value xml:lang="en">Final scale factor is null</value>
-        <value xml:lang="fr">Le facteur final de redimensionnement est nul</value>
-    </property>
-    <property key="ImageTransform.height_scale_factor_is_null">
-        <value xml:lang="en">Height scale factor is null</value>
-        <value xml:lang="fr">Le facteur 'hauteur' de redimensionnement est nul</value>
-    </property>
-    <property key="ImageTransform.input_is_null">
-        <value xml:lang="en">Input is null</value>
-        <value xml:lang="fr">L'entrée est nulle</value>
-    </property>
     <property key="ImageTransform.one_current_image_dimension_is_null">
         <value xml:lang="en">One current image dimension is null</value>
         <value xml:lang="fr">Une des dimensions de l'image courrante est nulle</value>
     </property>
-    <property key="ImageTransform.one_default_dimension_is_null">
-        <value xml:lang="en">One default dimension is null</value>
-        <value xml:lang="fr">Une des dimensions par défaut est nulle</value>
-    </property>
     <property key="ImageTransform.one_parameter_is_null">
         <value xml:lang="en">One parameter is null</value>
         <value xml:lang="fr">Un des paramètres est nul</value>
     </property>
-    <property key="ImageTransform.root_element_has_not_been_set">
-        <value xml:lang="en">Root element has not been set</value>
-        <value xml:lang="fr">L'élement racine n'a pas pu être chargé</value>
-    </property>
     <property key="ImageTransform.transform_is_non_invertible">
         <value xml:lang="en">Transform is non-invertible</value>
         <value xml:lang="fr">La transformation n'est pas réversible</value>
@@ -79,14 +47,6 @@
         <value xml:lang="en">Unable to scale original image</value>
         <value xml:lang="fr">Impossible de redimensionner l'image originale</value>
     </property>
-    <property key="ImageTransform.unknown_buffered_image_type">
-        <value xml:lang="en">Unknown buffered image type</value>
-        <value xml:lang="fr">Le type d'image bufferisée est inconnu</value>
-    </property>
-    <property key="ImageTransform.width_scale_factor_is_null">
-        <value xml:lang="en">Width scale factor is null</value>
-        <value xml:lang="fr">Le facteur 'largeur' de redimensionnement est nul</value>
-    </property>
     <property key="ProductCreateCommunicationEventProductPermissionError">
         <value xml:lang="en">Create Communication Event Product Permission Error</value>
         <value xml:lang="it">Errore di permesso durante la creazione evento comunicazione prodotto</value>

Copied: ofbiz/trunk/applications/product/src/org/ofbiz/product/image/ScaleImage.java (from r749960, ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java)
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/image/ScaleImage.java?p2=ofbiz/trunk/applications/product/src/org/ofbiz/product/image/ScaleImage.java&p1=ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java&r1=749960&r2=750018&rev=750018&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/image/ScaleImage.java Wed Mar  4 14:22:55 2009
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  *******************************************************************************/
-package org.ofbiz.image;
+package org.ofbiz.product.image;
 
 import java.awt.RenderingHints;
 import java.awt.geom.AffineTransform;
@@ -34,67 +34,25 @@
 
 import javolution.util.FastMap;
 
-import org.jdom.Document;
-import org.jdom.Element;
 import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.service.ServiceUtil;
-
+import org.ofbiz.common.image.ImageTransform;
 
 /**
- * ImageTransform Class
+ * ScaleImage Class
  * <p>
- * Services to apply transformation to images
+ * Scale the original image into 4 different size Types (small, medium, large, detail)
  */
-public class ImageTransform {
+public class ScaleImage {
 
-    public static final String module = ImageTransform.class.getName();
+    public static final String module = ScaleImage.class.getName();
     public static final String resource = "ProductErrorUiLabels";
 
-    public ImageTransform() {
-    }
-
-    /**
-     * getBufferedImage
-     * <p>
-     * Set a buffered image
-     *
-     * @param   context
-     * @param   fileLocation    Full file Path or URL
-     * @return                  URL images for all different size types
-     * @throws  IOException Error prevents the document from being fully parsed
-     * @throws  JDOMException Errors occur in parsing
-     */
-    public Map<String, Object> getBufferedImage(String fileLocation, Locale locale)
-        throws IllegalArgumentException, IOException {
-
-        /* VARIABLES */
-        BufferedImage bufImg;
-        Map<String, Object> result = FastMap.newInstance();
-
-        /* BUFFERED IMAGE */
-        try {
-            bufImg = ImageIO.read(new File(fileLocation));
-        } catch(IllegalArgumentException e) {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.input_is_null", locale) + " : " + fileLocation + " ; " + e.toString();
-            Debug.logError(errMsg, module);
-            result.put("errorMessage", errMsg);
-            return result;
-        } catch(IOException e) {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.error_occurs_during_reading", locale) + " : " + fileLocation + " ; " + e.toString();
-            Debug.logError(errMsg, module);
-            result.put("errorMessage", errMsg);
-            return result;
-        }
-
-        result.put("responseMessage", "success");
-        result.put("bufferedImage", bufImg);
-        return result;
-
+    public ScaleImage() {
     }
 
     /**
@@ -112,13 +70,12 @@
      * @throws  IOException                 Error prevents the document from being fully parsed
      * @throws  JDOMException               Errors occur in parsing
      */
-    public Map<String, Object> scaleImageInAllSize(Map<String, ? extends Object> context, String filenameToUse, String viewType, String viewNumber)
+    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");
-        List<String> extensionList = UtilMisc.toList("jpeg", "jpg", "png");
         int index;
         Map<String, Map<String, String>> imgPropertyMap = FastMap.newInstance();
         BufferedImage bufImg, bufNewImg;
@@ -132,7 +89,7 @@
 
         /* ImageProperties.xml */
         String imgPropertyFullPath = System.getProperty("ofbiz.home") + "/applications/product/config/ImageProperties.xml";
-        resultXMLMap.putAll((Map<String, Object>) getXMLValue(imgPropertyFullPath, locale));
+        resultXMLMap.putAll((Map<String, Object>) ImageTransform.getXMLValue(imgPropertyFullPath, locale));
         if(resultXMLMap.containsKey("responseMessage") && resultXMLMap.get("responseMessage").equals("success")) {
             imgPropertyMap.putAll((Map<String, Map<String, String>>) resultXMLMap.get("xml"));
         } else {
@@ -173,7 +130,7 @@
 
 
         /* get original BUFFERED IMAGE */
-        resultBufImgMap.putAll(this.getBufferedImage(imageServerPath + "/" + filePathPrefix + filenameToUse, locale));
+        resultBufImgMap.putAll(ImageTransform.getBufferedImage(imageServerPath + "/" + filePathPrefix + filenameToUse, locale));
 
         if (resultBufImgMap.containsKey("responseMessage") && resultBufImgMap.get("responseMessage").equals("success")) {
             bufImg = (BufferedImage) resultBufImgMap.get("bufferedImage");
@@ -200,7 +157,7 @@
             while (sizeIter.hasNext()) {
                 String sizeType = sizeIter.next();
 
-                resultScaleImgMap.putAll(this.scaleImage(bufImg, imgHeight, imgWidth, imgPropertyMap, sizeType, locale));
+                resultScaleImgMap.putAll(ImageTransform.scaleImage(bufImg, imgHeight, imgWidth, imgPropertyMap, sizeType, locale));
 
                 if (resultScaleImgMap.containsKey("responseMessage") && resultScaleImgMap.get("responseMessage").equals("success")) {
                     bufNewImg = (BufferedImage) resultScaleImgMap.get("bufferedImage");
@@ -246,14 +203,6 @@
                         newFilePathPrefix = newFileLocation.substring(0, newFileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
                     }
 
-                    // choose final extension
-                    String finalExtension = null;
-                    if (!extensionList.contains(imgExtension.toLowerCase())) {
-                        finalExtension = imgPropertyMap.get("format").get("extension");
-                    } else {
-                        finalExtension = imgExtension;
-                    }
-
                     String targetDirectory = imageServerPath + "/" + newFilePathPrefix;
                     File targetDir = new File(targetDirectory);
                     if (!targetDir.exists()) {
@@ -292,164 +241,11 @@
             result.put("original", resultBufImgMap);
             return result;
 
-
         } else {
             String errMsg = UtilProperties.getMessage(resource, "ImageTransform.unable_to_scale_original_image", locale) + " : " + filenameToUse;
             Debug.logError(errMsg, module);
             result.put("errorMessage", errMsg);
             return ServiceUtil.returnError(errMsg);
         }
-
-
-    }
-
-
-    /**
-     * scaleImage
-     * <p>
-     * scale original image related to the ImageProperties.xml dimensions
-     *
-     * @param   bufImg          Buffered image to scale
-     * @param   imgHeight       Original image height
-     * @param   imgwidth        Original image width
-     * @param   dimensionMap    Image dimensions by size type
-     * @param   sizeType        Size type to scale
-     * @return                  New scaled buffered image
-     */
-    private Map<String, Object> scaleImage(BufferedImage bufImg, double imgHeight, double imgWidth, Map<String, Map<String, String>> dimensionMap, String sizeType, Locale locale) {
-
-        /* VARIABLES */
-        BufferedImage bufNewImg;
-        double defaultHeight, defaultWidth, scaleFactor;
-        Map<String, Object> result = FastMap.newInstance();
-
-        /* DIMENSIONS from ImageProperties */
-        defaultHeight = Double.parseDouble(dimensionMap.get(sizeType).get("height").toString());
-        defaultWidth = Double.parseDouble(dimensionMap.get(sizeType).get("width").toString());
-        if (defaultHeight == 0.0 || defaultWidth == 0.0) {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.one_default_dimension_is_null", locale) + " : defaultHeight = " + defaultHeight + " ; defaultWidth = " + defaultWidth;
-            Debug.logError(errMsg, module);
-            result.put("errorMessage", errMsg);
-            return result;
-        }
-
-        /* SCALE FACTOR */
-        // find the right Scale Factor related to the Image Dimensions
-        if (imgHeight > imgWidth) {
-            scaleFactor = defaultHeight / imgHeight;
-            if (scaleFactor == 0.0) {
-                String errMsg = UtilProperties.getMessage(resource, "ImageTransform.height_scale_factor_is_null", locale) + "  (defaultHeight = " + defaultHeight + "; imgHeight = " + imgHeight;
-                Debug.logError(errMsg, module);
-                result.put("errorMessage", errMsg);
-                return result;
-            }
-            // get scaleFactor from the smallest width
-            if (defaultWidth < (imgWidth * scaleFactor)) {
-                scaleFactor = defaultWidth / imgWidth;
-            }
-        } else {
-            scaleFactor = defaultWidth / imgWidth;
-            if (scaleFactor == 0.0) {
-                String errMsg = UtilProperties.getMessage(resource, "ImageTransform.width_scale_factor_is_null", locale) + "  (defaultWidth = " + defaultWidth + "; imgWidth = " + imgWidth;
-                Debug.logError(errMsg, module);
-                result.put("errorMessage", errMsg);
-                return result;
-            }
-            // get scaleFactor from the smallest height
-            if (defaultHeight < (imgHeight * scaleFactor)) {
-                scaleFactor = defaultHeight / imgHeight;
-            }
-        }
-
-        if (scaleFactor == 0.0) {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.final_scale_factor_is_null", locale) + " = " + scaleFactor;
-            Debug.logError(errMsg, module);
-            result.put("errorMessage", errMsg);
-            return result;
-        }
-        int bufImgType;
-        if (BufferedImage.TYPE_CUSTOM == bufImg.getType()) {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.unknown_buffered_image_type", locale);
-            Debug.logWarning(errMsg, module);
-            // apply a type for image majority
-            bufImgType = BufferedImage.TYPE_INT_ARGB_PRE;
-        } else {
-            bufImgType = bufImg.getType();
-        }
-
-        bufNewImg = new BufferedImage( (int) (imgWidth * scaleFactor), (int) (imgHeight * scaleFactor), bufImgType);
-
-        result.put("responseMessage", "success");
-        result.put("bufferedImage", bufNewImg);
-        result.put("scaleFactor", scaleFactor);
-        return result;
-
-    }
-
-    /**
-     * getXMLValue
-     * <p>
-     * From a XML element, get a values map
-     *
-     * @param fileFullPath      File path to parse
-     * @return Map contains asked attribute values by attribute name
-     */
-    private Map<String, Object> getXMLValue(String fileFullPath, Locale locale)
-        throws IllegalStateException, IOException, JDOMException {
-
-        /* VARIABLES */
-        Document document;
-        Element rootElt;
-        Map<String, Map<String, String>> valueMap = FastMap.newInstance();
-        Map<String, Object> result = FastMap.newInstance();
-
-        /* PARSING */
-        SAXBuilder sxb = new SAXBuilder();
-        try {
-            // JDOM
-            document = sxb.build(new File(fileFullPath));
-        } catch(JDOMException e) {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.errors_occur_in parsing", locale) +  " ImageProperties.xml " + e.toString();
-            Debug.logError(errMsg, module);
-            result.put("errorMessage", "error");
-            return result;
-        } catch(IOException e) {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.error_prevents_the document_from_being_fully_parsed", locale) + e.toString();
-            Debug.logError(errMsg, module);
-            result.put("errorMessage", "error");
-            return result;
-        }
-        // set Root Element
-        try {
-            rootElt = document.getRootElement();
-        } catch(IllegalStateException e) {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.root_element_has_not_been_set", locale) + e.toString();
-            Debug.logError(errMsg, module);
-            result.put("errorMessage", "error");
-            return result;
-        }
-
-        /* get NAME and VALUE */
-        List<Element> children = rootElt.getChildren(); // FIXME : despite upgrading to jdom 1.1, it seems that getChildren is pre 1.5 java code (ie getChildren does not retun List<Element> but only List)
-        for (Element currentElt : children) {
-            Map<String, String> eltMap = FastMap.newInstance();
-            if (currentElt.getContentSize() > 0) {
-                Map<String, String> childMap = FastMap.newInstance();
-                // loop over Children 1st level
-                List<Element> children2 = currentElt.getChildren();
-                for (Element currentChild : children2) {
-                    childMap.put(currentChild.getAttributeValue("name"), currentChild.getAttributeValue("value"));
-                }
-                valueMap.put(currentElt.getAttributeValue("name"), childMap);
-            } else {
-                eltMap.put(currentElt.getAttributeValue("name"), currentElt.getAttributeValue("value"));
-                valueMap.put(currentElt.getName(), eltMap);
-            }
-        }
-
-        result.put("responseMessage", "success");
-        result.put("xml", valueMap);
-        return result;
-
     }
 }

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java?rev=750018&r1=750017&r2=750018&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java Wed Mar  4 14:22:55 2009
@@ -44,7 +44,7 @@
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityUtil;
-import org.ofbiz.image.ImageTransform;
+import org.ofbiz.product.image.ScaleImage;
 import org.ofbiz.product.catalog.CatalogWorker;
 import org.ofbiz.product.category.CategoryWorker;
 import org.ofbiz.service.DispatchContext;
@@ -79,7 +79,6 @@
         // * Map selectedFeatures  -- Selected features
         GenericDelegator delegator = dctx.getDelegator();
         Locale locale = (Locale) context.get("locale");
-        String productId = (String) context.get("productId");
         Map selectedFeatures = UtilGenerics.checkMap(context.get("selectedFeatures"));
         List<GenericValue> products = FastList.newInstance();
         // All the variants for this products are retrieved
@@ -961,7 +960,7 @@
             
             /* scale Image in different sizes */
             String viewNumber = String.valueOf(productContentTypeId.charAt(productContentTypeId.length() - 1));
-            ImageTransform imageTransform = new ImageTransform();
+            ScaleImage imageTransform = new ScaleImage();
             Map<String, Object> resultResize = FastMap.newInstance();
             try{
                 resultResize.putAll(imageTransform.scaleImageInAllSize(context, filenameToUse, "additional", viewNumber));

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy?rev=750018&r1=750017&r2=750018&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy Wed Mar  4 14:22:55 2009
@@ -20,7 +20,7 @@
 import org.ofbiz.entity.*;
 import org.ofbiz.base.util.*;
 import org.ofbiz.base.util.string.*;
-import org.ofbiz.image.ImageTransform;
+import org.ofbiz.product.image.ScaleImage;
 
 context.nowTimestampString = UtilDateTime.nowTimestamp().toString();
 
@@ -125,8 +125,7 @@
             
             // call scaleImageInAllSize
             if(fileType.equals("original")){
-                ImageTransform imageTransform = new ImageTransform();
-                result = imageTransform.scaleImageInAllSize(context, filenameToUse, "main", "0");
+                result = ScaleImage.scaleImageInAllSize(context, filenameToUse, "main", "0");
                 
                 if(result.containsKey("responseMessage") && result.get("responseMessage").equals("success")){
                     imgMap = result.get("imageUrlMap");

Added: ofbiz/trunk/framework/common/config/CommonErrorUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/CommonErrorUiLabels.xml?rev=750018&view=auto
==============================================================================
--- ofbiz/trunk/framework/common/config/CommonErrorUiLabels.xml (added)
+++ ofbiz/trunk/framework/common/config/CommonErrorUiLabels.xml Wed Mar  4 14:22:55 2009
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    
+    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.
+-->
+<resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <property key="ImageTransform.errors_occured_during_parsing">
+        <value xml:lang="en">Errors occured during parsing</value>
+        <value xml:lang="fr">Des erreurs sont survenues lors de l'analyse</value>
+    </property>
+    <property key="ImageTransform.error_occurs_during_reading">
+        <value xml:lang="en">An error occurs during reading</value>
+        <value xml:lang="fr">Une erreur est survenue lors de la lecture</value>
+    </property>
+    <property key="ImageTransform.final_scale_factor_is_null">
+        <value xml:lang="en">Final scale factor is null</value>
+        <value xml:lang="fr">Le facteur final de redimensionnement est nul</value>
+    </property>
+    <property key="ImageTransform.height_scale_factor_is_null">
+        <value xml:lang="en">Height scale factor is null</value>
+        <value xml:lang="fr">Le facteur 'hauteur' de redimensionnement est nul</value>
+    </property>
+    <property key="ImageTransform.input_is_null">
+        <value xml:lang="en">Input is null</value>
+        <value xml:lang="fr">La valeur saisie est nulle</value>
+    </property>
+    <property key="ImageTransform.error_prevents_the document_from_being_fully_parsed">
+        <value xml:lang="en">Error prevents the document from being fully parsed</value>
+        <value xml:lang="fr">Une erreur empêche que le document soit entièrement analysé</value>
+    </property>
+    <property key="ImageTransform.one_default_dimension_is_null">
+        <value xml:lang="en">One default dimension is null</value>
+        <value xml:lang="fr">Une des dimensions par défaut est nulle</value>
+    </property>
+    <property key="ImageTransform.root_element_has_not_been_set">
+        <value xml:lang="en">Root element has not been set</value>
+        <value xml:lang="fr">L'élement racine n'a pas pu être chargé</value>
+    </property>
+    <property key="ImageTransform.unknown_buffered_image_type">
+        <value xml:lang="en">Unknown buffered image type</value>
+        <value xml:lang="fr">Le type d'image bufferisée est inconnu</value>
+    </property>
+    <property key="ImageTransform.width_scale_factor_is_null">
+        <value xml:lang="en">Width scale factor is null</value>
+        <value xml:lang="fr">Le facteur 'largeur' de redimensionnement est nul</value>
+    </property>
+</resource>
+

Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/image/ImageTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/image/ImageTransform.java?rev=750018&r1=749549&r2=750018&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/image/ImageTransform.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/image/ImageTransform.java Wed Mar  4 14:22:55 2009
@@ -16,16 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  *******************************************************************************/
-package org.ofbiz.image;
+package org.ofbiz.common.image;
 
-import java.awt.RenderingHints;
-import java.awt.geom.AffineTransform;
-import java.awt.image.AffineTransformOp;
 import java.awt.image.BufferedImage;
-import java.awt.image.ImagingOpException;
 import java.io.File;
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -39,10 +34,7 @@
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
-import org.ofbiz.base.util.string.FlexibleStringExpander;
-import org.ofbiz.service.ServiceUtil;
 
 
 /**
@@ -53,7 +45,7 @@
 public class ImageTransform {
 
     public static final String module = ImageTransform.class.getName();
-    public static final String resource = "ProductErrorUiLabels";
+    public static final String resource = "CommonErrorUiLabels";
 
     public ImageTransform() {
     }
@@ -69,7 +61,7 @@
      * @throws  IOException Error prevents the document from being fully parsed
      * @throws  JDOMException Errors occur in parsing
      */
-    public Map<String, Object> getBufferedImage(String fileLocation, Locale locale)
+    public static  Map<String, Object> getBufferedImage(String fileLocation, Locale locale)
         throws IllegalArgumentException, IOException {
 
         /* VARIABLES */
@@ -98,213 +90,6 @@
     }
 
     /**
-     * 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   viewType                    "Main" view or "additional" view
-     * @param   viewNumber                  If it's the main view, viewNumber = "0"
-     * @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
-     * @throws  JDOMException               Errors occur in parsing
-     */
-    public 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");
-        List<String> extensionList = UtilMisc.toList("jpeg", "jpg", "png");
-        int index;
-        Map<String, Map<String, String>> imgPropertyMap = FastMap.newInstance();
-        BufferedImage bufImg, bufNewImg;
-        double imgHeight, imgWidth, scaleFactor;
-        AffineTransformOp op;
-        Map<String, String> imgUrlMap = FastMap.newInstance();
-        Map<String, Object> resultXMLMap = FastMap.newInstance();
-        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>) getXMLValue(imgPropertyFullPath, locale));
-        if(resultXMLMap.containsKey("responseMessage") && resultXMLMap.get("responseMessage").equals("success")) {
-            imgPropertyMap.putAll((Map<String, Map<String, String>>) resultXMLMap.get("xml"));
-        } else {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.unable_to_parse", locale) + " : ImageProperties.xml";
-            Debug.logError(errMsg, module);
-            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
-        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")) {
-            type = "original";
-            id = imgName;
-        } else if(viewType.toLowerCase().contains("additional") && viewNumber != null && !viewNumber.equals("0")) {
-            type = "additional";
-            id = imgName + "_View_" + viewNumber;
-        } else {
-            return ServiceUtil.returnError("View Type : " + type + " is wrong");
-        }
-        FlexibleStringExpander mainFilenameExpander = FlexibleStringExpander.getInstance(mainFilenameFormat);
-        String fileLocation = mainFilenameExpander.expandString(UtilMisc.toMap("location", "products", "type", type, "id", filenameToUse));
-        String filePathPrefix = "";
-        if (fileLocation.lastIndexOf("/") != -1) {
-            filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
-        }
-
-
-
-        /* get original BUFFERED IMAGE */
-        resultBufImgMap.putAll(this.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();
-            if (imgHeight == 0.0 || imgWidth == 0.0) {
-                String errMsg = UtilProperties.getMessage(resource, "ImageTransform.one_current_image_dimension_is_null", locale) + " : imgHeight = " + imgHeight + " ; imgWidth = " + imgWidth;
-                Debug.logError(errMsg, module);
-                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(this.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);
-                        rhMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-                        rhMap.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
-                        rhMap.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
-                        rhMap.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
-                        rhMap.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
-                        rhMap.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
-                        //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) {
-                        String errMsg = UtilProperties.getMessage(resource, "ImageTransform.transform_is_non_invertible", locale)  + e.toString();
-                        Debug.logError(errMsg, module);
-                        result.put("errorMessage", errMsg);
-                        return result;
-                    }
-
-                    // write the New Scaled Image
-                    String newFileLocation = null;
-                    if (viewType.toLowerCase().contains("main")) {
-                        newFileLocation = mainFilenameExpander.expandString(UtilMisc.toMap("location", "products", "type", sizeType, "id", id));
-                    } else if(viewType.toLowerCase().contains("additional")) {
-                        newFileLocation = addFilenameExpander.expandString(UtilMisc.toMap("location", "products", "viewtype", viewType, "sizetype", sizeType,"id", id));
-                    }
-                    String newFilePathPrefix = "";
-                    if (newFileLocation.lastIndexOf("/") != -1) {
-                        newFilePathPrefix = newFileLocation.substring(0, newFileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
-                    }
-
-                    // choose final extension
-                    String finalExtension = null;
-                    if (!extensionList.contains(imgExtension.toLowerCase())) {
-                        finalExtension = imgPropertyMap.get("format").get("extension");
-                    } else {
-                        finalExtension = imgExtension;
-                    }
-
-                    String targetDirectory = imageServerPath + "/" + newFilePathPrefix;
-                    File targetDir = new File(targetDirectory);
-                    if (!targetDir.exists()) {
-                        boolean created = targetDir.mkdirs();
-                        if (!created) {
-                            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.unable_to_create_target_directory", locale) + " - " + targetDirectory;
-                            Debug.logFatal(errMsg, module);
-                            return ServiceUtil.returnError(errMsg);
-                        }
-                    }
-
-                    // write new image
-                    try {
-                        ImageIO.write(op.filter(bufImg, bufNewImg), imgExtension, new File(imageServerPath + "/" + newFilePathPrefix + filenameToUse));
-                    } catch(IllegalArgumentException e) {
-                        String errMsg = UtilProperties.getMessage(resource, "ImageTransform.one_parameter_is_null", locale) + e.toString();
-                        Debug.logError(errMsg, module);
-                        result.put("errorMessage", errMsg);
-                        return result;
-                    } catch(IOException e) {
-                        String errMsg = UtilProperties.getMessage(resource, "ImageTransform.error_occurs_during_writing", locale) + e.toString();
-                        Debug.logError(errMsg, module);
-                        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, "ImageTransform.unable_to_scale_original_image", locale) + " : " + filenameToUse;
-            Debug.logError(errMsg, module);
-            result.put("errorMessage", errMsg);
-            return ServiceUtil.returnError(errMsg);
-        }
-
-
-    }
-
-
-    /**
      * scaleImage
      * <p>
      * scale original image related to the ImageProperties.xml dimensions
@@ -316,7 +101,7 @@
      * @param   sizeType        Size type to scale
      * @return                  New scaled buffered image
      */
-    private Map<String, Object> scaleImage(BufferedImage bufImg, double imgHeight, double imgWidth, Map<String, Map<String, String>> dimensionMap, String sizeType, Locale locale) {
+    public static Map<String, Object> scaleImage(BufferedImage bufImg, double imgHeight, double imgWidth, Map<String, Map<String, String>> dimensionMap, String sizeType, Locale locale) {
 
         /* VARIABLES */
         BufferedImage bufNewImg;
@@ -394,7 +179,7 @@
      * @param fileFullPath      File path to parse
      * @return Map contains asked attribute values by attribute name
      */
-    private Map<String, Object> getXMLValue(String fileFullPath, Locale locale)
+    public static  Map<String, Object> getXMLValue(String fileFullPath, Locale locale)
         throws IllegalStateException, IOException, JDOMException {
 
         /* VARIABLES */
@@ -409,7 +194,7 @@
             // JDOM
             document = sxb.build(new File(fileFullPath));
         } catch(JDOMException e) {
-            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.errors_occur_in parsing", locale) +  " ImageProperties.xml " + e.toString();
+            String errMsg = UtilProperties.getMessage(resource, "ImageTransform.errors_occured_during_parsing", locale) +  " ImageProperties.xml " + e.toString();
             Debug.logError(errMsg, module);
             result.put("errorMessage", "error");
             return result;