You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2008/07/17 20:52:59 UTC

svn commit: r677683 - in /ofbiz/trunk/applications/content/src/org/ofbiz/content: cms/CmsEvents.java content/ContentMapFacade.java content/ContentWorker.java

Author: jonesde
Date: Thu Jul 17 11:52:57 2008
New Revision: 677683

URL: http://svn.apache.org/viewvc?rev=677683&view=rev
Log:
Fixed bug where links with jsessionid from a cms page had the link built out of order with the jsessionid in the middle

Modified:
    ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java?rev=677683&r1=677682&r2=677683&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java Thu Jul 17 11:52:57 2008
@@ -19,17 +19,11 @@
 
 package org.ofbiz.content.cms;
 
-import org.ofbiz.base.util.*;
-import org.ofbiz.base.util.collections.MapStack;
-import org.ofbiz.content.content.ContentWorker;
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.GenericEntityException;
-import org.ofbiz.entity.GenericValue;
-import org.ofbiz.entity.util.EntityUtil;
-import org.ofbiz.webapp.control.RequestHandler;
-import org.ofbiz.widget.screen.ScreenRenderer;
-import org.ofbiz.widget.html.HtmlFormRenderer;
-import org.ofbiz.service.LocalDispatcher;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.List;
+import java.util.Locale;
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
@@ -38,13 +32,24 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.sql.Timestamp;
-import java.util.List;
-import java.util.Locale;
-import java.util.Iterator;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.GeneralRuntimeException;
+import org.ofbiz.base.util.UtilHttp;
+import org.ofbiz.base.util.UtilJ2eeCompat;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.collections.MapStack;
+import org.ofbiz.content.content.ContentWorker;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.webapp.control.RequestHandler;
+import org.ofbiz.widget.html.HtmlFormRenderer;
+import org.ofbiz.widget.screen.ScreenRenderer;
 
 
 /**
@@ -98,7 +103,7 @@
 
         // if path info is null; check for a default content
         if (pathInfo == null) {
-            List defaultContents = null;
+            List<GenericValue> defaultContents = null;
             try {
                 defaultContents = delegator.findByAnd("WebSiteContent", UtilMisc.toMap("webSiteId", webSiteId,
                         "webSiteContentTypeId", "DEFAULT_PAGE"), UtilMisc.toList("-fromDate"));
@@ -159,10 +164,10 @@
 
             // get the contentId/mapKey from URL
             if (contentId == null) {
-                Debug.log("Current PathInfo: " + pathInfo, module);
+                if (Debug.verboseOn()) Debug.logVerbose("Current PathInfo: " + pathInfo, module);
                 if (pathInfo.indexOf("/") != -1) {
                     String[] pathSplit = pathInfo.split("/");
-                    Debug.log("Split pathinfo: " + pathSplit.length, module);
+                    if (Debug.verboseOn()) Debug.logVerbose("Split pathinfo: " + pathSplit.length, module);
                     if (pathSplit != null && pathSplit.length > 0) {
                         contentId = pathSplit[0];
                         if (pathSplit.length > 1) {
@@ -185,15 +190,18 @@
 
             if (websiteOk) {
                 // create the template map
-                MapStack templateMap = MapStack.create();
+                MapStack<String> templateMap = MapStack.create();
                 ScreenRenderer.populateContextForRequest(templateMap, null, request, response, servletContext);
                 templateMap.put("formStringRenderer", new HtmlFormRenderer(request, response));
                 
                 // make the link prefix
                 ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
                 RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
-                String contextLinkPrefix = rh.makeLink(request, response, "", true, false, true);
-                templateMap.put("_CONTEXT_LINK_PREFIX_", contextLinkPrefix);
+                templateMap.put("_REQUEST_HANDLER_", rh);
+                
+                // NOTE DEJ20080817: this is done in the ContentMapFacade class now to avoid problems with the jsessionid being in the middle of the URL and such
+                //String contextLinkPrefix = rh.makeLink(request, response, "", true, false, true);
+                //templateMap.put("_CONTEXT_LINK_PREFIX_", contextLinkPrefix);
 
                 Writer writer;
                 try {
@@ -224,7 +232,7 @@
 
                 return "success";
             } else {
-                Debug.log("No website [" + webSiteId + "] publish point found for contentId: " + contentId, module);
+                if (Debug.verboseOn()) Debug.logVerbose("No website [" + webSiteId + "] publish point found for contentId: " + contentId, module);
             }
         }
 
@@ -236,7 +244,7 @@
     protected static boolean verifyContentToWebSite(GenericDelegator delegator, String webSiteId, String contentId) throws GeneralException {
         // first check the top level publish point
         // get the root content id
-        List publishPoints = null;
+        List<GenericValue> publishPoints = null;
         try {
             publishPoints = delegator.findByAndCache("WebSiteContent",
                     UtilMisc.toMap("webSiteId", webSiteId, "contentId", contentId, "webSiteContentTypeId", "PUBLISH_POINT"),
@@ -247,21 +255,18 @@
 
         publishPoints = EntityUtil.filterByDate(publishPoints);
         if (publishPoints == null || publishPoints.size() == 0) {
-            List topLevel = delegator.findByAndCache("WebSiteContent",
-                UtilMisc.toMap("webSiteId", webSiteId, "webSiteContentTypeId", "PUBLISH_POINT"),
-                    UtilMisc.toList("-fromDate"));
-            topLevel = EntityUtil.filterByDate(topLevel);
-            if (topLevel != null) {
-                Iterator i = topLevel.iterator();
-                while (i.hasNext()) {
-                    GenericValue point = (GenericValue) i.next();
+            List<GenericValue> topLevelContentValues = delegator.findByAndCache("WebSiteContent",
+                UtilMisc.toMap("webSiteId", webSiteId, "webSiteContentTypeId", "PUBLISH_POINT"), UtilMisc.toList("-fromDate"));
+            topLevelContentValues = EntityUtil.filterByDate(topLevelContentValues);
+            if (topLevelContentValues != null) {
+                for (GenericValue point: topLevelContentValues) {
                     if (verifySubContent(delegator, contentId, point.getString("contentId"))) {
                         return true;
                     }
                 }
             }
         } else {
-            Debug.log("Found publish points: " + publishPoints, module);
+            if (Debug.verboseOn()) Debug.logVerbose("Found publish points: " + publishPoints, module);
             return true;
         }
 
@@ -269,22 +274,20 @@
     }
 
     protected static boolean verifySubContent(GenericDelegator delegator, String contentId, String contentIdFrom) throws GeneralException {
-        List contentAssoc = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdFrom, "contentIdTo", contentId));
+        List<GenericValue> contentAssoc = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdFrom, "contentIdTo", contentId));
         contentAssoc = EntityUtil.filterByDate(contentAssoc);
         if (contentAssoc == null || contentAssoc.size() == 0) {
-            List assocs = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdFrom));
+            List<GenericValue> assocs = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdFrom));
             assocs = EntityUtil.filterByDate(assocs);
             if (assocs != null) {
-                Iterator i = assocs.iterator();
-                while (i.hasNext()) {
-                    GenericValue assoc = (GenericValue) i.next();
+                for (GenericValue assoc: assocs) {
                     if (verifySubContent(delegator, contentId, assoc.getString("contentIdTo"))) {
                         return true;
                     }
                 }
             }
         } else {
-            Debug.log("Found assocs: " + contentAssoc, module);
+            if (Debug.verboseOn()) Debug.logVerbose("Found assocs: " + contentAssoc, module);
             return true;
         }
 

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java?rev=677683&r1=677682&r2=677683&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java Thu Jul 17 11:52:57 2008
@@ -24,6 +24,7 @@
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.webapp.control.RequestHandler;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
@@ -33,6 +34,9 @@
 import java.util.*;
 import java.io.IOException;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import javolution.util.FastList;
 import javolution.util.FastMap;
 import javolution.util.FastSet;
@@ -43,6 +47,19 @@
 public class ContentMapFacade implements Map {
 
     public static final String module = ContentMapFacade.class.getName();
+    
+    protected static final Set<String> mapKeySet = FastSet.newInstance();
+    static {
+        mapKeySet.add("fields");
+        mapKeySet.add("link");
+        mapKeySet.add("data");
+        mapKeySet.add("dataresource");
+        mapKeySet.add("subcontent");
+        mapKeySet.add("subcontent_all");
+        mapKeySet.add("metadata");
+        mapKeySet.add("content");
+        mapKeySet.add("render");
+    }
 
     protected final LocalDispatcher dispatcher;
     protected final GenericDelegator delegator;
@@ -146,19 +163,9 @@
         Debug.logWarning("This method [clear()] is not implemented in ContentMapFacade", module);
     }
 
-    public Set keySet() {
-        Debug.logWarning("This method [keySet()] is not completely implemented in ContentMapFacade", module);
-        Set keys = FastSet.newInstance();
-        keys.add("fields");
-        keys.add("link");
-        keys.add("data");
-        keys.add("dataresource");
-        keys.add("subcontent");
-        keys.add("subcontent_all");
-        keys.add("metadata");
-        keys.add("content");
-        keys.add("render");
-        return keys;
+    public Set<String> keySet() {
+        // Debug.logWarning("This method [keySet()] is not completely implemented in ContentMapFacade", module);
+        return mapKeySet;
     }
 
     public Collection values() {
@@ -198,15 +205,15 @@
         } else if ("link".equalsIgnoreCase(name)) {
             // link to this content
             // TODO: make more intelligent to use a link alias if exists
-            String contextLinkPrefix = (String) this.context.get("_CONTEXT_LINK_PREFIX_");
-            if (UtilValidate.isNotEmpty(contextLinkPrefix)) {
-                StringBuffer linkBuf = new StringBuffer();
-                linkBuf.append(contextLinkPrefix);
-                if (!contextLinkPrefix.endsWith("/")) {
-                    linkBuf.append("/");
-                }
-                linkBuf.append(this.contentId);
-                return linkBuf.toString();
+
+            RequestHandler rh = (RequestHandler) this.context.get("_REQUEST_HANDLER_");
+            HttpServletRequest request = (HttpServletRequest) this.context.get("request");
+            HttpServletResponse response = (HttpServletResponse) this.context.get("response");
+
+            if (rh != null && request != null && response != null) {
+                String contextLink = rh.makeLink(request, response, this.contentId, true, false, true);
+                // Debug.logInfo("Made link to content with ID [" + this.contentId + "]: " + contextLink, module);
+                return contextLink;
             } else {
                 return this.contentId;
             }
@@ -215,8 +222,8 @@
             return dataResource;   
         } else if ("subcontent_all".equalsIgnoreCase(name)) {
             // subcontent list of ordered subcontent
-            List subContent = FastList.newInstance();
-            List subs = null;
+            List<ContentMapFacade> subContent = FastList.newInstance();
+            List<GenericValue> subs = null;
             try {
                 if (cache) {
                     subs = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentId", contentId), UtilMisc.toList("-fromDate"));
@@ -229,9 +236,7 @@
             if (subs != null) {
                 subs = EntityUtil.filterByDate(subs);
 
-                Iterator i = subs.iterator();
-                while (i.hasNext()) {
-                    GenericValue v = (GenericValue) i.next();
+                for (GenericValue v: subs) {
                     subContent.add(new ContentMapFacade(dispatcher, delegator, v.getString("contentIdTo"), context, locale, mimeType, cache));
                 }
             }

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java?rev=677683&r1=677682&r2=677683&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java Thu Jul 17 11:52:57 2008
@@ -134,7 +134,7 @@
 
         // if the content is a PUBLISH_POINT and the data resource is not defined; get the related content
         if ("WEB_SITE_PUB_PT".equals(content.get("contentTypeId")) && content.get("dataResourceId") == null) {
-            List relContentIds = delegator.findByAnd("ContentAssocDataResourceViewTo",
+            List<GenericValue> relContentIds = delegator.findByAnd("ContentAssocDataResourceViewTo",
                     UtilMisc.toMap("contentIdStart", content.get("contentId"),"statusId","CTNT_PUBLISHED",
                     "caContentAssocTypeId", "PUBLISH_LINK"), UtilMisc.toList("caFromDate"));