Author: jleroux
Date: Sat Oct 15 17:30:12 2016
New Revision: 1765096

URL: http://svn.apache.org/viewvc?rev=1765096&view=rev
Log:
Backports r1765094 (editing by hand)
========================================================================================
Fixed: You cannot edit an image in content
(OFBIZ-7000)

If you get to
content/control/EditLayout?drDataResourceId=NOCONTENTFOUND&contentId=NOCONTENTFOUND
When trying to editing you get an error

Mohammed Rehan Khan explored the issue and found that there is a condition in 
DataResourceWorker method to render content of 'text' mime type only, for others
 it returns exception.

We can fix this by setting up mimeTypeID as null in request param

Question: Why setting up mimeTypeTypeId as 'null' is fixing this issue?
Answer: As we don't have image specific worker method for rendering these type 
of contents, so we are using DataResourceWorker.renderDataResourceAsText() 
to render image type content as well. Due to following condition, 
targetMimeTypeId is setting up as "text/html" if sent null and hence not 
throwing the exception reported in the ticket.

Thanks: Mohammed Rehan Khan for the patch
========================================================================================

Modified:
    
ofbiz/branches/release13.07/applications/content/src/org/ofbiz/content/ContentManagementServices.java
    
ofbiz/branches/release13.07/applications/content/template/mime-type/image.ftl
    
ofbiz/branches/release13.07/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
    
ofbiz/branches/release14.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java
    
ofbiz/branches/release14.12/applications/content/template/mime-type/image.ftl
    
ofbiz/branches/release14.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
    
ofbiz/branches/release15.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java
    
ofbiz/branches/release15.12/applications/content/template/mime-type/image.ftl
    
ofbiz/branches/release15.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy

Modified: 
ofbiz/branches/release13.07/applications/content/src/org/ofbiz/content/ContentManagementServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/content/src/org/ofbiz/content/ContentManagementServices.java?rev=1765096&r1=1765095&r2=1765096&view=diff
==============================================================================
--- 
ofbiz/branches/release13.07/applications/content/src/org/ofbiz/content/ContentManagementServices.java
 (original)
+++ 
ofbiz/branches/release13.07/applications/content/src/org/ofbiz/content/ContentManagementServices.java
 Sat Oct 15 17:30:12 2016
@@ -21,15 +21,12 @@ package org.ofbiz.content;
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
 import java.sql.Timestamp;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
-import javolution.util.FastList;
-import javolution.util.FastMap;
-import javolution.util.FastSet;
-
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.StringUtil;
 import org.ofbiz.base.util.UtilDateTime;
@@ -59,6 +56,10 @@ import org.ofbiz.service.ServiceUtil;
 
 import com.ibm.icu.util.Calendar;
 
+import javolution.util.FastList;
+import javolution.util.FastMap;
+import javolution.util.FastSet;
+
 /**
  * ContentManagementServices Class
  */
@@ -669,6 +670,16 @@ public class ContentManagementServices {
               }
           } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
           } else if (dataResourceTypeId.startsWith("SURVEY")) {
+          } else if (dataResourceTypeId.indexOf("_FILE") >=0) {
+              Map<String, Object> uploadImage = new HashMap<String, Object>();
+              uploadImage.put("userLogin", userLogin);
+              uploadImage.put("dataResourceId", dataResourceId);
+              uploadImage.put("dataResourceTypeId", dataResourceTypeId);
+              uploadImage.put("rootDir", context.get("objectInfo"));
+              uploadImage.put("uploadedFile", imageDataBytes);
+              uploadImage.put("_uploadedFile_fileName", (String) 
context.get("_imageData_fileName"));
+              uploadImage.put("_uploadedFile_contentType", (String) 
context.get("_imageData_contentType"));
+              dispatcher.runSync("attachUploadToDataResource", uploadImage);
           } else {
               // assume ELECTRONIC_TEXT
               if (UtilValidate.isNotEmpty(textData)) {
@@ -702,6 +713,16 @@ public class ContentManagementServices {
               }
           } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
           } else if (dataResourceTypeId.startsWith("SURVEY")) {
+          } else if (dataResourceTypeId.indexOf("_FILE") >=0) {
+              Map<String, Object> uploadImage = new HashMap<String, Object>();
+              uploadImage.put("userLogin", userLogin);
+              uploadImage.put("dataResourceId", dataResourceId);
+              uploadImage.put("dataResourceTypeId", dataResourceTypeId);
+              uploadImage.put("rootDir", context.get("objectInfo"));
+              uploadImage.put("uploadedFile", imageDataBytes);
+              uploadImage.put("_uploadedFile_fileName", (String) 
context.get("_imageData_fileName"));
+              uploadImage.put("_uploadedFile_contentType", (String) 
context.get("_imageData_contentType"));
+              dispatcher.runSync("attachUploadToDataResource", uploadImage);
           } else {
               if (UtilValidate.isNotEmpty(textData) || 
"true".equalsIgnoreCase(forceElectronicText)) {
                   fileContext.put("dataResourceId", dataResourceId);
@@ -714,17 +735,6 @@ public class ContentManagementServices {
               }
           }
       }
-      if (dataResourceTypeId.indexOf("_FILE") >=0) {
-          Map<String, Object> uploadImage = FastMap.newInstance();
-          uploadImage.put("userLogin", userLogin);
-          uploadImage.put("dataResourceId", dataResourceId);
-          uploadImage.put("dataResourceTypeId", dataResourceTypeId);
-          uploadImage.put("rootDir", context.get("objectInfo"));
-          uploadImage.put("uploadedFile", imageDataBytes);
-          uploadImage.put("_uploadedFile_fileName", (String) 
context.get("_imageData_fileName"));
-          uploadImage.put("_uploadedFile_contentType", (String) 
context.get("_imageData_contentType"));
-          dispatcher.runSync("attachUploadToDataResource", uploadImage);
-      }
       result.put("dataResourceId", dataResourceId);
       result.put("drDataResourceId", dataResourceId);
       context.put("dataResourceId", dataResourceId);

Modified: 
ofbiz/branches/release13.07/applications/content/template/mime-type/image.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/content/template/mime-type/image.ftl?rev=1765096&r1=1765095&r2=1765096&view=diff
==============================================================================
--- 
ofbiz/branches/release13.07/applications/content/template/mime-type/image.ftl 
(original)
+++ 
ofbiz/branches/release13.07/applications/content/template/mime-type/image.ftl 
Sat Oct 15 17:30:12 2016
@@ -16,4 +16,4 @@
   specific language governing permissions and limitations
   under the License.
   -->
-<img src="<@ofbizUrl 
secure="${request.isSecure()?string}">stream?contentId=${contentId}</@ofbizUrl>"/>
\ No newline at end of file
+<img src="<@ofbizUrl 
secure="${request.isSecure()?string}">stream?contentId=${contentId!}</@ofbizUrl>"/>
\ No newline at end of file

Modified: 
ofbiz/branches/release13.07/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy?rev=1765096&r1=1765095&r2=1765096&view=diff
==============================================================================
--- 
ofbiz/branches/release13.07/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
 (original)
+++ 
ofbiz/branches/release13.07/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
 Sat Oct 15 17:30:12 2016
@@ -47,7 +47,7 @@ if (currentValue) {
         templateRoot.context = ctx;
         out = new StringWriter();
         currentValue.drDataTemplateTypeId = "NONE";
-        DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, 
out, templateRoot, locale, mimeTypeId, false);
+        DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, 
out, templateRoot, locale, null, false);
         textData = out.toString();
         context.textData = textData;
     }

Modified: 
ofbiz/branches/release14.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java?rev=1765096&r1=1765095&r2=1765096&view=diff
==============================================================================
--- 
ofbiz/branches/release14.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java
 (original)
+++ 
ofbiz/branches/release14.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java
 Sat Oct 15 17:30:12 2016
@@ -21,15 +21,12 @@ package org.ofbiz.content;
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
 import java.sql.Timestamp;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
-import javolution.util.FastList;
-import javolution.util.FastMap;
-import javolution.util.FastSet;
-
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.StringUtil;
 import org.ofbiz.base.util.UtilDateTime;
@@ -58,6 +55,10 @@ import org.ofbiz.service.ServiceUtil;
 
 import com.ibm.icu.util.Calendar;
 
+import javolution.util.FastList;
+import javolution.util.FastMap;
+import javolution.util.FastSet;
+
 /**
  * ContentManagementServices Class
  */
@@ -668,6 +669,16 @@ public class ContentManagementServices {
               }
           } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
           } else if (dataResourceTypeId.startsWith("SURVEY")) {
+          } else if (dataResourceTypeId.indexOf("_FILE") >=0) {
+              Map<String, Object> uploadImage = new HashMap<String, Object>();
+              uploadImage.put("userLogin", userLogin);
+              uploadImage.put("dataResourceId", dataResourceId);
+              uploadImage.put("dataResourceTypeId", dataResourceTypeId);
+              uploadImage.put("rootDir", context.get("objectInfo"));
+              uploadImage.put("uploadedFile", imageDataBytes);
+              uploadImage.put("_uploadedFile_fileName", (String) 
context.get("_imageData_fileName"));
+              uploadImage.put("_uploadedFile_contentType", (String) 
context.get("_imageData_contentType"));
+              dispatcher.runSync("attachUploadToDataResource", uploadImage);
           } else {
               // assume ELECTRONIC_TEXT
               if (UtilValidate.isNotEmpty(textData)) {
@@ -701,6 +712,16 @@ public class ContentManagementServices {
               }
           } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
           } else if (dataResourceTypeId.startsWith("SURVEY")) {
+          } else if (dataResourceTypeId.indexOf("_FILE") >=0) {
+              Map<String, Object> uploadImage = new HashMap<String, Object>();
+              uploadImage.put("userLogin", userLogin);
+              uploadImage.put("dataResourceId", dataResourceId);
+              uploadImage.put("dataResourceTypeId", dataResourceTypeId);
+              uploadImage.put("rootDir", context.get("objectInfo"));
+              uploadImage.put("uploadedFile", imageDataBytes);
+              uploadImage.put("_uploadedFile_fileName", (String) 
context.get("_imageData_fileName"));
+              uploadImage.put("_uploadedFile_contentType", (String) 
context.get("_imageData_contentType"));
+              dispatcher.runSync("attachUploadToDataResource", uploadImage);
           } else {
               if (UtilValidate.isNotEmpty(textData) || 
"true".equalsIgnoreCase(forceElectronicText)) {
                   fileContext.put("dataResourceId", dataResourceId);
@@ -713,17 +734,6 @@ public class ContentManagementServices {
               }
           }
       }
-      if (dataResourceTypeId.indexOf("_FILE") >=0) {
-          Map<String, Object> uploadImage = FastMap.newInstance();
-          uploadImage.put("userLogin", userLogin);
-          uploadImage.put("dataResourceId", dataResourceId);
-          uploadImage.put("dataResourceTypeId", dataResourceTypeId);
-          uploadImage.put("rootDir", context.get("objectInfo"));
-          uploadImage.put("uploadedFile", imageDataBytes);
-          uploadImage.put("_uploadedFile_fileName", (String) 
context.get("_imageData_fileName"));
-          uploadImage.put("_uploadedFile_contentType", (String) 
context.get("_imageData_contentType"));
-          dispatcher.runSync("attachUploadToDataResource", uploadImage);
-      }
       result.put("dataResourceId", dataResourceId);
       result.put("drDataResourceId", dataResourceId);
       context.put("dataResourceId", dataResourceId);

Modified: 
ofbiz/branches/release14.12/applications/content/template/mime-type/image.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/content/template/mime-type/image.ftl?rev=1765096&r1=1765095&r2=1765096&view=diff
==============================================================================
--- 
ofbiz/branches/release14.12/applications/content/template/mime-type/image.ftl 
(original)
+++ 
ofbiz/branches/release14.12/applications/content/template/mime-type/image.ftl 
Sat Oct 15 17:30:12 2016
@@ -16,4 +16,4 @@
   specific language governing permissions and limitations
   under the License.
   -->
-<img src="<@ofbizUrl 
secure="${request.isSecure()?string}">stream?contentId=${contentId}</@ofbizUrl>"/>
\ No newline at end of file
+<img src="<@ofbizUrl 
secure="${request.isSecure()?string}">stream?contentId=${contentId!}</@ofbizUrl>"/>
\ No newline at end of file

Modified: 
ofbiz/branches/release14.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy?rev=1765096&r1=1765095&r2=1765096&view=diff
==============================================================================
--- 
ofbiz/branches/release14.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
 (original)
+++ 
ofbiz/branches/release14.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
 Sat Oct 15 17:30:12 2016
@@ -47,7 +47,7 @@ if (currentValue) {
         templateRoot.context = ctx;
         out = new StringWriter();
         currentValue.drDataTemplateTypeId = "NONE";
-        DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, 
out, templateRoot, locale, mimeTypeId, false);
+        DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, 
out, templateRoot, locale, null, false);
         textData = out.toString();
         context.textData = textData;
     }

Modified: 
ofbiz/branches/release15.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release15.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java?rev=1765096&r1=1765095&r2=1765096&view=diff
==============================================================================
--- 
ofbiz/branches/release15.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java
 (original)
+++ 
ofbiz/branches/release15.12/applications/content/src/org/ofbiz/content/ContentManagementServices.java
 Sat Oct 15 17:30:12 2016
@@ -666,6 +666,16 @@ public class ContentManagementServices {
               }
           } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
           } else if (dataResourceTypeId.startsWith("SURVEY")) {
+          } else if (dataResourceTypeId.indexOf("_FILE") >=0) {
+              Map<String, Object> uploadImage = new HashMap<String, Object>();
+              uploadImage.put("userLogin", userLogin);
+              uploadImage.put("dataResourceId", dataResourceId);
+              uploadImage.put("dataResourceTypeId", dataResourceTypeId);
+              uploadImage.put("rootDir", context.get("objectInfo"));
+              uploadImage.put("uploadedFile", imageDataBytes);
+              uploadImage.put("_uploadedFile_fileName", (String) 
context.get("_imageData_fileName"));
+              uploadImage.put("_uploadedFile_contentType", (String) 
context.get("_imageData_contentType"));
+              dispatcher.runSync("attachUploadToDataResource", uploadImage);
           } else {
               // assume ELECTRONIC_TEXT
               if (UtilValidate.isNotEmpty(textData)) {
@@ -699,6 +709,16 @@ public class ContentManagementServices {
               }
           } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
           } else if (dataResourceTypeId.startsWith("SURVEY")) {
+          } else if (dataResourceTypeId.indexOf("_FILE") >=0) {
+              Map<String, Object> uploadImage = new HashMap<String, Object>();
+              uploadImage.put("userLogin", userLogin);
+              uploadImage.put("dataResourceId", dataResourceId);
+              uploadImage.put("dataResourceTypeId", dataResourceTypeId);
+              uploadImage.put("rootDir", context.get("objectInfo"));
+              uploadImage.put("uploadedFile", imageDataBytes);
+              uploadImage.put("_uploadedFile_fileName", (String) 
context.get("_imageData_fileName"));
+              uploadImage.put("_uploadedFile_contentType", (String) 
context.get("_imageData_contentType"));
+              dispatcher.runSync("attachUploadToDataResource", uploadImage);
           } else {
               if (UtilValidate.isNotEmpty(textData) || 
"true".equalsIgnoreCase(forceElectronicText)) {
                   fileContext.put("dataResourceId", dataResourceId);
@@ -711,17 +731,6 @@ public class ContentManagementServices {
               }
           }
       }
-      if (dataResourceTypeId.indexOf("_FILE") >=0) {
-          Map<String, Object> uploadImage = new HashMap<String, Object>();
-          uploadImage.put("userLogin", userLogin);
-          uploadImage.put("dataResourceId", dataResourceId);
-          uploadImage.put("dataResourceTypeId", dataResourceTypeId);
-          uploadImage.put("rootDir", context.get("objectInfo"));
-          uploadImage.put("uploadedFile", imageDataBytes);
-          uploadImage.put("_uploadedFile_fileName", (String) 
context.get("_imageData_fileName"));
-          uploadImage.put("_uploadedFile_contentType", (String) 
context.get("_imageData_contentType"));
-          dispatcher.runSync("attachUploadToDataResource", uploadImage);
-      }
       result.put("dataResourceId", dataResourceId);
       result.put("drDataResourceId", dataResourceId);
       context.put("dataResourceId", dataResourceId);

Modified: 
ofbiz/branches/release15.12/applications/content/template/mime-type/image.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release15.12/applications/content/template/mime-type/image.ftl?rev=1765096&r1=1765095&r2=1765096&view=diff
==============================================================================
--- 
ofbiz/branches/release15.12/applications/content/template/mime-type/image.ftl 
(original)
+++ 
ofbiz/branches/release15.12/applications/content/template/mime-type/image.ftl 
Sat Oct 15 17:30:12 2016
@@ -16,4 +16,4 @@
   specific language governing permissions and limitations
   under the License.
   -->
-<img src="<@ofbizUrl 
secure="${request.isSecure()?string}">stream?contentId=${contentId}</@ofbizUrl>"/>
\ No newline at end of file
+<img src="<@ofbizUrl 
secure="${request.isSecure()?string}">stream?contentId=${contentId!}</@ofbizUrl>"/>
\ No newline at end of file

Modified: 
ofbiz/branches/release15.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release15.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy?rev=1765096&r1=1765095&r2=1765096&view=diff
==============================================================================
--- 
ofbiz/branches/release15.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
 (original)
+++ 
ofbiz/branches/release15.12/applications/content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy
 Sat Oct 15 17:30:12 2016
@@ -47,7 +47,7 @@ if (currentValue) {
         templateRoot.context = ctx;
         out = new StringWriter();
         currentValue.drDataTemplateTypeId = "NONE";
-        DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, 
out, templateRoot, locale, mimeTypeId, false);
+        DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, 
out, templateRoot, locale, null, false);
         textData = out.toString();
         context.textData = textData;
     }


Reply via email to