[jboss-svn-commits] JBL Code SVN: r7947 - labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 29 15:31:37 EST 2006


Author: unibrew
Date: 2006-11-29 15:31:34 -0500 (Wed, 29 Nov 2006)
New Revision: 7947

Modified:
   labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java
   labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
Log:
[JBFORUMS-149] Finally, I managed to hack a way to get rid of very long myfaces url parameter.

Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java	2006-11-29 20:13:42 UTC (rev 7946)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java	2006-11-29 20:31:34 UTC (rev 7947)
@@ -29,9 +29,19 @@
 import org.apache.myfaces.portlet.MyFacesGenericPortlet;
 
 import java.io.IOException;
+
+import java.lang.reflect.Field;
+
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 
 //portlet api
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.faces.context.FacesContext;
+
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.RenderRequest;
@@ -40,34 +50,200 @@
 import javax.portlet.PortletSession;
 import javax.portlet.PortletMode;
 
-//jboss portal 
+//jboss portal
+import org.jboss.portal.portlet.impl.PortletRequestImpl;
 import org.jboss.portlet.forums.helper.TempFileBinding;
 import org.jboss.portlet.forums.ui.PortalUtil;
+import org.jboss.portlet.util.Parameters;
 
 
 /**
  * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
  *
- * 
  */
 public class ForumsJSFPortlet extends MyFacesGenericPortlet 
 {
+
     /**
+     * PortletRequest parameter for JBoss Forums Portlet for replacing
+     * standard parameter of MyFacesGenericPortlet
+     */
+    public static final String VIEW = "v";
+    
+    /**
+     * This Map contains sorted pairs of view name and view id.
+     */
+    public static final Map VIEW_NAME_TO_ID = Collections.synchronizedSortedMap(new TreeMap());
+    
+    /**
+     * This Map contains sorted pairs of view id and view name.
+     */
+    public static final Map VIEW_ID_TO_NAME = Collections.synchronizedSortedMap(new TreeMap());
+    
+    
+    /**
+     * Static class initializer will fill VIEW_ID_TO_NAME and VIEW_ID_TO_NAME maps.
+     */
+    static {
+    
+        // Root views
+        VIEW_ID_TO_NAME.put("i","/views/index.jsf");
+        VIEW_NAME_TO_ID.put("/views/index.jsf","i");
+        
+        VIEW_ID_TO_NAME.put("j","/views/jumpbox.jsf");
+        VIEW_NAME_TO_ID.put("/views/jumpbox.jsf","j");
+        
+        VIEW_ID_TO_NAME.put("m","/views/portal_index.jsf");
+        VIEW_NAME_TO_ID.put("/views/portal_index.jsf","m");
+        
+        // admin views
+        VIEW_ID_TO_NAME.put("a","/views/admin/index.jsf");
+        VIEW_NAME_TO_ID.put("/views/admin/index.jsf","a");
+        
+        VIEW_ID_TO_NAME.put("h","/views/admin/editCategory.jsf");
+        VIEW_NAME_TO_ID.put("/views/admin/editCategory.jsf","h");
+        
+        VIEW_ID_TO_NAME.put("k","/views/admin/editForum.jsf");
+        VIEW_NAME_TO_ID.put("/views/admin/editForum.jsf","k");
+        
+        VIEW_ID_TO_NAME.put("l","/views/admin/deleteCategory.jsf");
+        VIEW_NAME_TO_ID.put("/views/admin/deleteCategory.jsf","l");
+        
+        VIEW_ID_TO_NAME.put("d","/views/admin/deleteForum.jsf");
+        VIEW_NAME_TO_ID.put("/views/admin/deleteForum.jsf","d");
+        
+        // category views
+        VIEW_ID_TO_NAME.put("c","/views/category/viewcategory_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/category/viewcategory_body.jsf","c");
+         
+        // common views
+        VIEW_ID_TO_NAME.put("b","/views/common/common.jsf");
+        VIEW_NAME_TO_ID.put("/views/common/common.jsf","b");
+        
+        VIEW_ID_TO_NAME.put("n","/views/common/common_noMenu.jsf");
+        VIEW_NAME_TO_ID.put("/views/common/common_noMenu.jsf","n");
+        
+        // errors views
+        VIEW_ID_TO_NAME.put("e","/views/errors/error_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/errors/error_body.jsf","e");        
+        
+        // forums views
+        VIEW_ID_TO_NAME.put("f","/views/forums/viewforum_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/forums/viewforum_body.jsf","f");
+
+        // moderator views
+        VIEW_ID_TO_NAME.put("m","/views/moderator/modcp_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/moderator/modcp_body.jsf","m");
+
+        VIEW_ID_TO_NAME.put("v","/views/moderator/delete_topic.jsf");
+        VIEW_NAME_TO_ID.put("/views/moderator/delete_topic.jsf","v");
+        
+        VIEW_ID_TO_NAME.put("q","/views/moderator/modcp_move.jsf");
+        VIEW_NAME_TO_ID.put("/views/moderator/modcp_move.jsf","q");
+        
+        VIEW_ID_TO_NAME.put("o","/views/moderator/modcp_split.jsf");
+        VIEW_NAME_TO_ID.put("/views/moderator/modcp_split.jsf","o");
+        
+        // preferences views
+        VIEW_ID_TO_NAME.put("r","/views/pref/index.jsf");
+        VIEW_NAME_TO_ID.put("/views/pref/index.jsf","r");
+        
+        // profile views
+        VIEW_ID_TO_NAME.put("u","/views/profile/viewprofile_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/profile/viewprofile_body.jsf","u");
+        
+        VIEW_ID_TO_NAME.put("ue","/views/profile/usermessage_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/profile/usermessage_body.jsf","ue");
+        
+        // summary views
+        VIEW_ID_TO_NAME.put("s","/views/summary/viewsummary_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/summary/viewsummary_body.jsf","s");
+        
+        // topic views
+        VIEW_ID_TO_NAME.put("t","/views/topics/viewtopic_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/viewtopic_body.jsf","t");
+        
+        VIEW_ID_TO_NAME.put("p","/views/topics/posting_new_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/posting_new_body.jsf","p");
+        
+        VIEW_ID_TO_NAME.put("g","/views/topics/posting_edit_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/posting_edit_body.jsf","g");
+        
+        VIEW_ID_TO_NAME.put("z","/views/topics/posting_reply_body.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/posting_reply_body.jsf","z");
+        
+        VIEW_ID_TO_NAME.put("y","/views/topics/delete_poll.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/delete_poll.jsf","y");
+        
+        VIEW_ID_TO_NAME.put("x","/views/topics/delete_post.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/delete_post.jsf","x");
+        
+        VIEW_ID_TO_NAME.put("pa","/views/topics/attachmentsview.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/attachmentsview.jsf","pa");
+        
+        VIEW_ID_TO_NAME.put("pe","/views/topics/posting_edit_preview.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/posting_edit_preview.jsf","pe");
+        
+        VIEW_ID_TO_NAME.put("pi","/views/topics/posting_new_preview.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/posting_new_preview.jsf","pi");
+        
+        VIEW_ID_TO_NAME.put("pr","/views/topics/posting_reply_preview.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/posting_reply_preview.jsf","pr");
+        
+        VIEW_ID_TO_NAME.put("pc","/views/topics/viewtopic_poll_ballot.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/viewtopic_poll_ballot.jsf","pc");
+        
+        VIEW_ID_TO_NAME.put("pk","/views/topics/viewtopic_poll_result.jsf");
+        VIEW_NAME_TO_ID.put("/views/topics/viewtopic_poll_result.jsf","pk");
+        
+        // watches views
+        VIEW_ID_TO_NAME.put("w","/views/watches/forumWatch.jsf");
+        VIEW_NAME_TO_ID.put("/views/watches/forumWatch.jsf","w");
+
+    }
+
+    /**
      * Called by the portlet container to allow the portlet to process an action request.
      */
     public void processAction(ActionRequest request, ActionResponse response) throws PortletException,IOException
     { 
         try
         {
-	        this.setupRenderParameters(request,response);   
-	        
-	        //parse and setup any attachments if they are sent in
-	        if ((request.getContentType() != null) && request.getContentType().startsWith("multipart/form-data"))
-	        {
-	            this.processAttachments(request,response);
-	        }
-	        
-	        super.processAction(request,response);
+            if (sessionTimedOut(request)) return;
+            setPortletRequestFlag(request);
+            
+            this.setupRenderParameters(request,response);   
+            
+            //parse and setup any attachments if they are sent in
+            if ((request.getContentType() != null) && request.getContentType().startsWith("multipart/form-data"))
+            {
+                this.processAttachments(request,response);
+            }
+
+            FacesContext fc = facesContext(request, response);
+
+            lifecycle.execute(fc);
+
+            if (fc.getResponseComplete()==false)
+            {
+                if (request.getParameterValues(VIEW)!=null) {
+                
+                    String viewId = request.getParameterValues(VIEW)[0];
+                    response.setRenderParameter(VIEW, request.getParameterValues(VIEW) );
+                    fc.getViewRoot().setViewId(getNameForId(viewId));
+                    
+                } else if (fc.getViewRoot().getViewId()!=null) {
+                
+                    String viewName = fc.getViewRoot().getViewId();
+                    if (viewName.endsWith("xhtml")) {
+                        viewName = viewName.replaceAll("xhtml","jsf");
+                    }
+                    response.setRenderParameter(VIEW, new String[]{getIdForName(viewName)} );
+                }
+            }
+
+            request.getPortletSession().setAttribute(CURRENT_FACES_CONTEXT, fc);
         }
         catch(Throwable t)
         {
@@ -90,7 +266,20 @@
                 nonFacesRequest(request,response,"/views/index.jsf");
                 return;
             }
+            Map map = request.getParameterMap();
             
+            if (map.get(VIEW)!=null) {
+                Map newParams = new HashMap();  
+                newParams.putAll(map);
+                String viewName = ((String[])newParams.get(VIEW))[0];
+                newParams.put(MyFacesGenericPortlet.VIEW_ID,new String[]{getNameForId(viewName)});
+                Class requestClass = PortletRequestImpl.class;
+                Field field = requestClass.getDeclaredField("parameters");
+                field.setAccessible(true);
+                field.set(request, new Parameters(newParams));
+                field.setAccessible(false);
+            }
+            
             super.doView(request,response);
         }
         catch(Throwable t)
@@ -138,6 +327,27 @@
         nonFacesRequest(request,response,"/views/pref/index.jsf");
     }     
     //----------------------------------------------------------------------------------------------------------------
+    
+     /**
+      * This method translates standard view file path into short view id parameter.
+      */
+     public static String getIdForName(String name) {
+         if (name==null) {
+             return null;
+         }
+         return (String)VIEW_NAME_TO_ID.get(name);
+     }
+     
+     /**
+      * This method translates short id view parameter into standard view file path.
+      */
+     public static String getNameForId(String id) {
+         if (id==null) {
+             return null;
+         }
+         return (String)VIEW_ID_TO_NAME.get(id);
+     }
+    
     /**
      * Not sure why this needs to be done...
      * This method tends to propagate the request parameters over to the JSF layer

Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java	2006-11-29 20:13:42 UTC (rev 7946)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java	2006-11-29 20:31:34 UTC (rev 7947)
@@ -51,8 +51,6 @@
 import javax.portlet.RenderResponse;
 import javax.portlet.PortletRequest;
 
-import javax.servlet.ServletRequest;
-
 import javax.servlet.http.HttpServletRequest;
 
 import org.jboss.portal.core.CoreConstants;
@@ -141,9 +139,8 @@
                 }
 
                 String jsfUrl = portletURL.toString();
-                jsfUrl +=
-                        "&org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID=" +
-                        URLEncoder.encode(outputLink, "UTF-8");
+                jsfUrl +="&" + ForumsJSFPortlet.VIEW + "=" +
+                         URLEncoder.encode(ForumsJSFPortlet.getIdForName(outputLink), "UTF-8");
 
                 url = jsfUrl;
             }




More information about the jboss-svn-commits mailing list