You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mr...@apache.org on 2008/05/29 21:47:53 UTC

svn commit: r661449 - in /ofbiz/trunk/applications/product: webapp/catalog/WEB-INF/actions/product/EditProductContent.bsh webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy widget/catalog/ProductScreens.xml

Author: mrisaliti
Date: Thu May 29 12:47:53 2008
New Revision: 661449

URL: http://svn.apache.org/viewvc?rev=661449&view=rev
Log:
Converted EditProductContent.bsh to groovy (Part of issue OFBIZ-1801)

Added:
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy
      - copied, changed from r661437, ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.bsh
Removed:
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.bsh
Modified:
    ofbiz/trunk/applications/product/widget/catalog/ProductScreens.xml

Copied: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy (from r661437, ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.bsh)
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy?p2=ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy&p1=ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.bsh&r1=661437&r2=661449&rev=661449&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.bsh (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy Thu May 29 12:47:53 2008
@@ -17,94 +17,95 @@
  * under the License.
  */
 
-import java.util.*;
-import java.sql.*;
-import java.io.*;
-import org.ofbiz.entity.*;
-import org.ofbiz.base.util.*;
-import org.ofbiz.base.util.string.*;
-import org.ofbiz.widget.html.*;
+import org.ofbiz.entity.*
+import org.ofbiz.base.util.*
+import org.ofbiz.base.util.string.*
 
-nowTimestamp = UtilDateTime.nowTimestamp();
-context.put("nowTimestamp", nowTimestamp);
-
-String nowTimestampString = nowTimestamp.toString();
-context.put("nowTimestampString", nowTimestampString);
+context.nowTimestampString = UtilDateTime.nowTimestamp().toString();
 
 // make the image file formats
-String imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format");
-String imageServerPath = UtilProperties.getPropertyValue("catalog", "image.server.path");
-String imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix");
-context.put("imageFilenameFormat", imageFilenameFormat);
-context.put("imageServerPath", imageServerPath);
-context.put("imageUrlPrefix", imageUrlPrefix);
-
-FlexibleStringExpander filenameExpander = new FlexibleStringExpander(imageFilenameFormat);
-context.put("imageNameSmall", imageUrlPrefix + "/" + filenameExpander.expandString(UtilMisc.toMap("location","products", "type", "small", "id", productId)));
-context.put("imageNameMedium", imageUrlPrefix + "/" + filenameExpander.expandString(UtilMisc.toMap("location","products","type", "medium", "id", productId)));
-context.put("imageNameLarge", imageUrlPrefix + "/" + filenameExpander.expandString(UtilMisc.toMap("location","products","type", "large", "id", productId)));
-context.put("imageNameDetail", imageUrlPrefix + "/" + filenameExpander.expandString(UtilMisc.toMap("location","products","type", "detail", "id", productId)));
+imageFilenameFormat = UtilProperties.getPropertyValue('catalog', 'image.filename.format');
+imageServerPath = UtilProperties.getPropertyValue('catalog', 'image.server.path');
+imageUrlPrefix = UtilProperties.getPropertyValue('catalog', 'image.url.prefix');
+context.imageFilenameFormat = imageFilenameFormat;
+context.imageServerPath = imageServerPath;
+context.imageUrlPrefix = imageUrlPrefix;
+
+filenameExpander = new FlexibleStringExpander(imageFilenameFormat);
+context.imageNameSmall = imageUrlPrefix + "/" + filenameExpander.expandString(['location' : 'products', 'type' : 'small' , 'id' : productId]);
+context.imageNameMedium = imageUrlPrefix + "/" + filenameExpander.expandString(['location' : 'products', 'type' : 'medium', 'id' : productId]);
+context.imageNameLarge = imageUrlPrefix + "/" + filenameExpander.expandString(['location' : 'products', 'type' : 'large' , 'id' : productId]);
+context.imageNameDetail = imageUrlPrefix + "/" + filenameExpander.expandString(['location' : 'products', 'type' : 'detail', 'id' : productId]);
 
 // Start ProductContent stuff
 productContent = null;
-if (product != null) productContent = product.getRelated("ProductContent", null, UtilMisc.toList("productContentTypeId"));
-context.put("productContent", productContent);
-
+if (product) {
+    productContent = product.getRelated('ProductContent', null, ['productContentTypeId']);
+}
+context.productContent = productContent;
 // End ProductContent stuff
 
 boolean tryEntity = true;
-if (request.getAttribute("_ERROR_MESSAGE_") != null) tryEntity = false;
-if (product == null) tryEntity = false;
-if("true".equalsIgnoreCase((String) request.getParameter("tryEntity"))) tryEntity = true;
-context.put("tryEntity", tryEntity);
+if (request.getAttribute("_ERROR_MESSAGE_")) {
+    tryEntity = false;
+}
+if (!product) {
+    tryEntity = false;
+}
 
-// UPLOADING STUFF
+if("true".equalsIgnoreCase((String) request.getParameter("tryEntity"))) {
+    tryEntity = true;
+}
+context.tryEntity = tryEntity;
 
-Object forLock = new Object();
-String contentType = null;
+// UPLOADING STUFF
+forLock = new Object();
+contentType = null;
 String fileType = request.getParameter("upload_file_type");
-if (fileType != null) {
-    context.put("fileType", fileType);
-
-    String fileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "type", fileType, "id", productId));
-    String filePathPrefix = "";
-    String filenameToUse = fileLocation;
+if (fileType) {
+    context.fileType = fileType;
+    
+    fileLocation = filenameExpander.expandString(['location' : 'products', 'type' : fileType, 'id' : productId]);
+    filePathPrefix = "";
+    filenameToUse = fileLocation;
     if (fileLocation.lastIndexOf("/") != -1) {
         filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
         filenameToUse = fileLocation.substring(fileLocation.lastIndexOf("/") + 1);
     }
     
     int i1;
-    if (contentType != null && (i1 = contentType.indexOf("boundary=")) != -1) {
+    if (contentType && (i1 = contentType.indexOf("boundary=")) != -1) {
         contentType = contentType.substring(i1 + 9);
         contentType = "--" + contentType;
     }
-        
-    String defaultFileName = filenameToUse + "_temp";
-    HttpRequestFileUpload uploadObject = new HttpRequestFileUpload();
+    
+    defaultFileName = filenameToUse + "_temp";
+    uploadObject = new HttpRequestFileUpload();
     uploadObject.setOverrideFilename(defaultFileName);
     uploadObject.setSavePath(imageServerPath + "/" + filePathPrefix);
     uploadObject.doUpload(request);
     
-    String clientFileName = uploadObject.getFilename();
-    if (clientFileName != null) context.put("clientFileName", clientFileName);
+    clientFileName = uploadObject.getFilename();
+    if (clientFileName) {
+        context.clientFileName = clientFileName;
+    }
     
-    if (clientFileName != null && clientFileName.length() > 0) {
+    if (clientFileName && clientFileName.length() > 0) {
         if (clientFileName.lastIndexOf(".") > 0 && clientFileName.lastIndexOf(".") < clientFileName.length()) {
             filenameToUse += clientFileName.substring(clientFileName.lastIndexOf("."));
         } else {
             filenameToUse += ".jpg";
         }
-    
-        context.put("clientFileName", clientFileName);        
-        context.put("filenameToUse", filenameToUse);
         
-        String characterEncoding = request.getCharacterEncoding();
-        String imageUrl = imageUrlPrefix + "/" + filePathPrefix + java.net.URLEncoder.encode(filenameToUse, characterEncoding);
+        context.clientFileName = clientFileName;
+        context.filenameToUse = filenameToUse;
+        
+        characterEncoding = request.getCharacterEncoding();
+        imageUrl = imageUrlPrefix + "/" + filePathPrefix + java.net.URLEncoder.encode(filenameToUse, characterEncoding);
         
         try {
-            File file = new File(imageServerPath + "/" + filePathPrefix, defaultFileName);
-            File file1 = new File(imageServerPath + "/" + filePathPrefix, filenameToUse);
+            file = new File(imageServerPath + "/" + filePathPrefix, defaultFileName);
+            file1 = new File(imageServerPath + "/" + filePathPrefix, filenameToUse);
             try {
                 file1.delete();
             } catch(Exception e) { 
@@ -114,12 +115,11 @@
         } catch(Exception e) { 
             e.printStackTrace();
         }
-    
-        if (imageUrl != null && imageUrl.length() > 0) {
-            context.put("imageUrl", imageUrl);
+        
+        if (imageUrl && imageUrl.length() > 0) {
+            context.imageUrl = imageUrl;
             product.set(fileType + "ImageUrl", imageUrl);
             product.store();
         }
     }
-}
-
+}
\ No newline at end of file

Modified: ofbiz/trunk/applications/product/widget/catalog/ProductScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/widget/catalog/ProductScreens.xml?rev=661449&r1=661448&r2=661449&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/widget/catalog/ProductScreens.xml (original)
+++ ofbiz/trunk/applications/product/widget/catalog/ProductScreens.xml Thu May 29 12:47:53 2008
@@ -1210,7 +1210,7 @@
 
                 <set field="productId" from-field="parameters.productId"/>
                 <entity-one entity-name="Product" value-name="product"/>
-                <script location="component://product/webapp/catalog/WEB-INF/actions/product/EditProductContent.bsh"/>   
+                <script location="component://product/webapp/catalog/WEB-INF/actions/product/EditProductContent.groovy"/>
             </actions>
             <widgets>
                 <decorator-screen name="CommonProductDecorator" location="${parameters.mainDecoratorLocation}">