You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2009/02/23 18:06:58 UTC

svn commit: r747085 - in /ofbiz/trunk: ./ applications/product/src/org/ofbiz/image/ applications/product/src/org/ofbiz/product/product/ framework/webapp/lib/

Author: jleroux
Date: Mon Feb 23 17:06:57 2009
New Revision: 747085

URL: http://svn.apache.org/viewvc?rev=747085&view=rev
Log:
A bit of refactoring + update of Jdom

Added:
    ofbiz/trunk/framework/webapp/lib/jdom-1.1.jar   (with props)
Removed:
    ofbiz/trunk/framework/webapp/lib/jdom-1.0.jar
Modified:
    ofbiz/trunk/.classpath
    ofbiz/trunk/LICENSE
    ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java

Modified: ofbiz/trunk/.classpath
URL: http://svn.apache.org/viewvc/ofbiz/trunk/.classpath?rev=747085&r1=747084&r2=747085&view=diff
==============================================================================
--- ofbiz/trunk/.classpath (original)
+++ ofbiz/trunk/.classpath Mon Feb 23 17:06:57 2009
@@ -144,7 +144,7 @@
 	<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.0.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/LICENSE
URL: http://svn.apache.org/viewvc/ofbiz/trunk/LICENSE?rev=747085&r1=747084&r2=747085&view=diff
==============================================================================
--- ofbiz/trunk/LICENSE (original)
+++ ofbiz/trunk/LICENSE Mon Feb 23 17:06:57 2009
@@ -366,7 +366,7 @@
 =========================================================================
 The following libraries distributed with Apache OFBiz are licensed under the
 JDOM (Modified Apache)  License:
-ofbiz/trunk/framework/webapp/lib/jdom-1.0.jar
+ofbiz/trunk/framework/webapp/lib/jdom-1.1.jar
 =========================================================================
 The JDOM License
  Copyright (C) 2000-2004 Jason Hunter & Brett McLaughlin.

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java?rev=747085&r1=747084&r2=747085&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java Mon Feb 23 17:06:57 2009
@@ -18,54 +18,43 @@
  *******************************************************************************/
 package org.ofbiz.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.awt.RenderingHints;
-import java.awt.RenderingHints.Key;
 import java.io.File;
 import java.io.IOException;
-import java.lang.IllegalArgumentException;
-import java.lang.Double;
-import java.lang.Object;
-import java.lang.String;
-import java.lang.System;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.imageio.ImageIO;
 
-import javolution.util.FastList;
 import javolution.util.FastMap;
 
 import org.jdom.Document;
 import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
-import org.jdom.filter.Filter;
 import org.jdom.JDOMException;
-
+import org.jdom.input.SAXBuilder;
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.service.ServiceUtil;
 
 
 /**
  * ImageTransform Class
  * <p>
- * Services to apply tranformation for images
+ * Services to apply transformation to images
  */
 public class ImageTransform {
 
     public static final String module = ImageTransform.class.getName();
-//    public static final String err_resource = "ContentErrorUiLabels";
+    public static final String err_resource = "ProductErrorUiLabels";
 
-    public ImageTransform() {}
-    
+    public ImageTransform() {}    
 
     /**
      * getBufferedImage
@@ -73,17 +62,17 @@
      * Set a buffered image
      *
      * @param   context
-     * @param   fileLocation    Full file Path or Url
-     * @return                  Url images for all different size types
+     * @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 getBufferedImage(String fileLocation)
+    public Map<String, Object> getBufferedImage(String fileLocation)
         throws IllegalArgumentException, IOException {
         
         /* VARIABLES */
         BufferedImage bufImg;
-        FastMap result = new FastMap();
+        Map<String, Object> result = FastMap.newInstance();
         
         /* BUFFERED IMAGE */
         try{
@@ -104,7 +93,7 @@
         result.put("bufferedImage", bufImg); 
         return result;        
     
-    } // getBufferedImage
+    }
     
     
     /**
@@ -116,34 +105,34 @@
      * @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
      * @throws  JDOMException               Errors occur in parsing
      */
-    public Map scaleImageInAllSize(Map<String, ? extends Object> context, String filenameToUse, String viewType, String viewNumber)
+    public Map<String, Object> scaleImageInAllSize(Map<String, ? extends Object> context, String filenameToUse, String viewType, String viewNumber)
         throws IllegalArgumentException, ImagingOpException, IOException, JDOMException {
     
         /* VARIABLES */
         List<String> sizeTypeList = UtilMisc.toList("small", "medium", "large", "detail");
         List<String> extensionList = UtilMisc.toList("jpeg", "jpg", "png");
         int index;
-        LinkedHashMap<String, LinkedHashMap<String, String>> imgPropertyMap = new LinkedHashMap<String, LinkedHashMap<String, String>>();
+        Map<String, Map<String, String>> imgPropertyMap = FastMap.newInstance();
         BufferedImage bufImg, bufNewImg;
-        double imgHeight, imgWidth, defaultHeight, defaultWidth, scaleFactor;
+        double imgHeight, imgWidth, scaleFactor;
         AffineTransformOp op;
-        LinkedHashMap<String, String> imgUrlMap = new LinkedHashMap<String, String>(); 
-        LinkedHashMap resultXMLMap = new LinkedHashMap(); 
-        LinkedHashMap resultBufImgMap = new LinkedHashMap();
-        LinkedHashMap resultScaleImgMap = new LinkedHashMap();
-        FastMap result = new FastMap();
+        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(getXMLValue(imgPropertyFullPath));
+        resultXMLMap.putAll((Map<String, Object>) getXMLValue(imgPropertyFullPath));
         if(resultXMLMap.containsKey("responseMessage") && resultXMLMap.get("responseMessage").equals("success")){
-            imgPropertyMap.putAll((LinkedHashMap) resultXMLMap.get("xml"));
+            imgPropertyMap.putAll((Map<String, Map<String, String>>) resultXMLMap.get("xml"));
         }else{
             String errMsg = "Impossible to parse ImageProperties.xml ";
             Debug.logError(errMsg, module);
@@ -161,8 +150,8 @@
         String imageServerPath = FlexibleStringExpander.expandString(UtilProperties.getPropertyValue("catalog", "image.server.path"), context);
         String imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix");
         
-        String id = new String();
-        String type = new String();
+        String id = null;
+        String type = null;
         if(viewType.toLowerCase().contains("main")){
             type = "original";
             id = imgName;
@@ -217,7 +206,7 @@
                     scaleFactor = scaleFactorDb.doubleValue();
         
                     // define Interpolation
-                    LinkedHashMap<RenderingHints.Key, Object> rhMap = new LinkedHashMap<RenderingHints.Key, Object>();
+                    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);
@@ -244,7 +233,7 @@
                     }
         
                     // write the New Scaled Image
-                    String newFileLocation = new String();
+                    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")){
@@ -256,7 +245,7 @@
                     }
                     
                     // choose final extension
-                    String finalExtension = new String();
+                    String finalExtension = null;
                     if(!extensionList.contains(imgExtension.toLowerCase())){
                         finalExtension = imgPropertyMap.get("format").get("extension");
                     }else{
@@ -307,7 +296,7 @@
             return ServiceUtil.returnError(errMsg);
         }    
         
-    } // scaleImageInAllSize 
+    } 
 
     
     /**
@@ -322,12 +311,12 @@
      * @param   sizeType        Size type to scale
      * @return                  New scaled buffered image 
      */
-    private Map scaleImage(BufferedImage bufImg, double imgHeight, double imgWidth, LinkedHashMap<String, LinkedHashMap<String, String>> dimensionMap, String sizeType){
+    private Map<String, Object> scaleImage(BufferedImage bufImg, double imgHeight, double imgWidth, Map<String, Map<String, String>> dimensionMap, String sizeType){
     
         /* VARIABLES */
         BufferedImage bufNewImg;
         double defaultHeight, defaultWidth, scaleFactor;
-        FastMap result = new FastMap();
+        Map<String, Object> result = FastMap.newInstance();
        
         /* DIMENSIONS from ImageProperties */     
         defaultHeight = Double.parseDouble(dimensionMap.get(sizeType).get("height").toString());
@@ -381,7 +370,7 @@
         result.put("scaleFactor", scaleFactor);
         return result;
 
-    } // scaleImage
+    }
     
     
     /**
@@ -392,15 +381,14 @@
      * @param fileFullPath      File path to parse
      * @return Map contains asked attribute values by attribute name
      */
-    private Map getXMLValue(String fileFullPath)
+    private Map<String, Object> getXMLValue(String fileFullPath)
         throws IllegalStateException, IOException, JDOMException {
 
         /* VARIABLES */
         Document document;
         Element rootElt;
-        List<Element> eltList;
-        LinkedHashMap<String, LinkedHashMap> valueMap = new LinkedHashMap<String, LinkedHashMap>();
-        FastMap result = new FastMap();
+        Map<String, Map<String, String>> valueMap = FastMap.newInstance();
+        Map<String, Object> result = FastMap.newInstance();
         
         /* PARSING */
         SAXBuilder sxb = new SAXBuilder();
@@ -429,16 +417,14 @@
         } 
            
         /* get NAME and VALUE */
-        Iterator<Element> eltIter = rootElt.getChildren().iterator();
-        while(eltIter.hasNext()){
-            Element currentElt = eltIter.next();              
-            LinkedHashMap<String, String> eltMap = new LinkedHashMap<String, String>();
+        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){
-                LinkedHashMap<String, String> childMap = new LinkedHashMap<String, String>();
+                Map<String, String> childMap = FastMap.newInstance();
                 // loop over Children 1st level
-                Iterator<Element> childrenIter = currentElt.getChildren().iterator();
-                while(childrenIter.hasNext()){
-                    Element currentChild = childrenIter.next(); 
+                List<Element> children2 = currentElt.getChildren();
+                for (Element currentChild : children2) {
                     childMap.put(currentChild.getAttributeValue("name"), currentChild.getAttributeValue("value"));  
                 }    
                 valueMap.put(currentElt.getAttributeValue("name"), childMap);
@@ -446,12 +432,11 @@
                 eltMap.put(currentElt.getAttributeValue("name"), currentElt.getAttributeValue("value"));
                 valueMap.put(currentElt.getName(), eltMap);   
             }
-        } // eltIter  
+        }  
         
         result.put("responseMessage", "success");
         result.put("xml", valueMap);
         return result; 
         
-    } // getXMLValue
-    
-} // ImageTransform Class
+    }    
+}

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=747085&r1=747084&r2=747085&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 Mon Feb 23 17:06:57 2009
@@ -960,10 +960,9 @@
             }
             
             /* scale Image in different sizes */
-            String viewNumber = new String(); 
-            viewNumber = String.valueOf(productContentTypeId.charAt(productContentTypeId.length() - 1));
+            String viewNumber = String.valueOf(productContentTypeId.charAt(productContentTypeId.length() - 1));
             ImageTransform imageTransform = new ImageTransform();
-            FastMap resultResize = new FastMap();
+            Map<String, Object> resultResize = FastMap.newInstance();
             try{
                 resultResize.putAll(imageTransform.scaleImageInAllSize(context, filenameToUse, "additional", viewNumber));
             }catch(IOException e){

Added: ofbiz/trunk/framework/webapp/lib/jdom-1.1.jar
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/lib/jdom-1.1.jar?rev=747085&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ofbiz/trunk/framework/webapp/lib/jdom-1.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream