svn commit: r902752 - /ofbiz/trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java

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

svn commit: r902752 - /ofbiz/trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java

ashish-18
Author: ashish
Date: Mon Jan 25 09:40:15 2010
New Revision: 902752

URL: http://svn.apache.org/viewvc?rev=902752&view=rev
Log:
Avoid NPE.
Patch from Vivek.

Modified:
    ofbiz/trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java?rev=902752&r1=902751&r2=902752&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/view/SimpleContentViewHandler.java Mon Jan 25 09:40:15 2010
@@ -89,8 +89,10 @@
             if (UtilValidate.isEmpty(dataResourceId)) {
                 if (UtilValidate.isEmpty(contentRevisionSeqId)) {
                     if (UtilValidate.isEmpty(mapKey) && UtilValidate.isEmpty(contentAssocTypeId)) {
-                        GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
-                        dataResourceId = content.getString("dataResourceId");
+                        if (UtilValidate.isNotEmpty(contentId)) {
+                            GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
+                            dataResourceId = content.getString("dataResourceId");
+                        }
                         if (Debug.verboseOn()) Debug.logVerbose("SCVH(0b)- dataResourceId:" + dataResourceId, module);
                     } else {
                         Timestamp fromDate = null;
@@ -121,33 +123,35 @@
                     if (Debug.verboseOn()) Debug.logVerbose("SCVH(3)- dataResourceId:" + dataResourceId, module);
                 }
             }
-            GenericValue dataResource = delegator.findByPrimaryKeyCache("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
-            // DEJ20080717: why are we rendering the DataResource directly instead of rendering the content?
-            ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, dataResourceId, https, webSiteId, locale, rootDir);
-            ByteArrayInputStream bais = new ByteArrayInputStream(byteBuffer.array());
-            // hack for IE and mime types
-            //String userAgent = request.getHeader("User-Agent");
-            //if (userAgent.indexOf("MSIE") > -1) {
-            //    Debug.log("Found MSIE changing mime type from - " + mimeTypeId, module);
-            //    mimeTypeId = "application/octet-stream";
-            //}
-            // setup chararcter encoding and content type
-            String charset = dataResource.getString("characterSetId");
-            mimeTypeId = dataResource.getString("mimeTypeId");
-            if (UtilValidate.isEmpty(charset)) {
-                charset = servletContext.getInitParameter("charset");
-            }
-            if (UtilValidate.isEmpty(charset)) {
-                charset = "UTF-8";
-            }
-
-            // setup content type
-            String contentType2 = UtilValidate.isNotEmpty(mimeTypeId) ? mimeTypeId + "; charset=" +charset : contentType;
-            String fileName = null;
-            if (!UtilValidate.isEmpty(dataResource.getString("dataResourceName"))) {
-                fileName = dataResource.getString("dataResourceName").replace(" ", "_"); // spaces in filenames can be a problem
+            if (UtilValidate.isNotEmpty(dataResourceId)) {
+                GenericValue dataResource = delegator.findByPrimaryKeyCache("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
+                // DEJ20080717: why are we rendering the DataResource directly instead of rendering the content?
+                ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, dataResourceId, https, webSiteId, locale, rootDir);
+                ByteArrayInputStream bais = new ByteArrayInputStream(byteBuffer.array());
+                // hack for IE and mime types
+                //String userAgent = request.getHeader("User-Agent");
+                //if (userAgent.indexOf("MSIE") > -1) {
+                //    Debug.log("Found MSIE changing mime type from - " + mimeTypeId, module);
+                //    mimeTypeId = "application/octet-stream";
+                //}
+                // setup chararcter encoding and content type
+                String charset = dataResource.getString("characterSetId");
+                mimeTypeId = dataResource.getString("mimeTypeId");
+                if (UtilValidate.isEmpty(charset)) {
+                    charset = servletContext.getInitParameter("charset");
+                }
+                if (UtilValidate.isEmpty(charset)) {
+                    charset = "UTF-8";
+                }
+    
+                // setup content type
+                String contentType2 = UtilValidate.isNotEmpty(mimeTypeId) ? mimeTypeId + "; charset=" +charset : contentType;
+                String fileName = null;
+                if (!UtilValidate.isEmpty(dataResource.getString("dataResourceName"))) {
+                    fileName = dataResource.getString("dataResourceName").replace(" ", "_"); // spaces in filenames can be a problem
+                }
+                UtilHttp.streamContentToBrowser(response, bais, byteBuffer.limit(), contentType2, fileName);
             }
-            UtilHttp.streamContentToBrowser(response, bais, byteBuffer.limit(), contentType2, fileName);
         } catch (GenericEntityException e) {
             throw new ViewHandlerException(e.getMessage());
         } catch (IOException e) {