portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r392165 - in /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout: ajax-xml/ impl/
Date Fri, 07 Apr 2006 02:49:03 GMT
Author: taylor
Date: Thu Apr  6 19:49:02 2006
New Revision: 392165

URL: http://svn.apache.org/viewcvs?rev=392165&view=rev
Log:
a couple of commits here:

1. fix bug in remove portlet where it wasnt updated the fragment columns
2. add portlets was not checking for valid portlet names
3. add portlets was not checking for portlets that are allowed viewable for current user
4. the default security behavior was not the correct one
5. Portlet Mode and Window State changes support started
   still need to integrate this into the Portal URL
6. validate modes and states on setting

Steve, please try testing with Desktop, as it will at least persist 

Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/window.vm
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/ChangePortletAction.java
Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/window.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/window.vm?rev=392165&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/window.vm
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/window.vm
Thu Apr  6 19:49:02 2006
@@ -0,0 +1,13 @@
+<js>
+    <status>$status</status>
+    <action>$action</action>
+    <id>$id</id> 
+#if ($state)    
+    <old_state>$oldState</old_state>
+    <new_state>$state</new_state>
+#end
+#if ($mode)    
+    <old_mode>$oldMode</old_mode>
+    <new_mode>$mode</new_mode>
+#end   
+</js>
\ No newline at end of file

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java?rev=392165&r1=392164&r2=392165&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
Thu Apr  6 19:49:02 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.jetspeed.layout.impl;
 
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -50,18 +51,21 @@
     implements AjaxAction, AjaxBuilder, Constants
 {
     protected Log log = LogFactory.getLog(AddPortletAction.class);
+    protected GetPortletsAction getPortletsAction = null;
 
-    public AddPortletAction(String template, String errorTemplate)
+    public AddPortletAction(String template, String errorTemplate, GetPortletsAction getPortletsAction)
     {
-        this(template, errorTemplate, null, null);
+        this(template, errorTemplate, null, null, getPortletsAction);
     }
 
     public AddPortletAction(String template, 
                             String errorTemplate, 
                             PageManager pageManager,
-                            PortletActionSecurityBehavior securityBehavior)
+                            PortletActionSecurityBehavior securityBehavior,
+                            GetPortletsAction getPortletsAction)
     {
-        super(template, errorTemplate, pageManager, securityBehavior);        
+        super(template, errorTemplate, pageManager, securityBehavior); 
+        this.getPortletsAction = getPortletsAction;
     }
     
     public boolean run(RequestContext requestContext, Map resultMap)
@@ -78,6 +82,10 @@
             { 
                 throw new RuntimeException("portlet id not provided"); 
             }
+            // Verify that the specified portlet id is valid and accessible
+            // If the portletid is not valid an exception will be thrown
+            verifyPortletId(requestContext, portletId);
+            
             resultMap.put(PORTLETID, portletId);
             if (false == checkAccess(requestContext, JetspeedActions.EDIT))
             {
@@ -135,5 +143,24 @@
         }
 
         return success;
+    }
+    
+    protected void verifyPortletId(RequestContext requestContext, String portletId) throws
Exception
+    {
+        // Get the list of valid portlets from the getPortletAction
+        List portletList = getPortletsAction.retrievePortlets(requestContext, null);
+        if(portletList != null) {
+            for(int i = 0; i < portletList.size(); i++) {
+                PortletInfo portletInfo = (PortletInfo)portletList.get(i);
+                if(portletInfo != null) {
+                    if(portletInfo.getName().equalsIgnoreCase(portletId)) {
+                        // A match was found there is no need to continue
+                        return;
+                    }
+                }
+            }
+        }
+        // If we got here, then no match was found
+        throw new Exception(portletId + " is not a valid portlet or not allowed for this
user");
     }
 }

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/ChangePortletAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/ChangePortletAction.java?rev=392165&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/ChangePortletAction.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/ChangePortletAction.java
Thu Apr  6 19:49:02 2006
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.layout.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.JetspeedActions;
+import org.apache.jetspeed.ajax.AJAXException;
+import org.apache.jetspeed.ajax.AjaxAction;
+import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.pluto.services.information.PortalContextProvider;
+
+/**
+ * Move Portlet portlet placement action
+ *
+ * AJAX Parameters: 
+ *    id = the fragment id of the portlet to move
+ *    page = (implied in the URL)
+ * Additional Absolute Parameters:  
+ *    row = the new row to move to
+ *    col = the new column to move to
+ * Additional Relative Parameters: (move left, right, up, down)
+ *    none
+ *    
+ * @author <a>David Gurney</a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class ChangePortletAction 
+    extends BasePortletAction 
+    implements AjaxAction, AjaxBuilder, Constants
+{
+    protected Log log = LogFactory.getLog(ChangePortletAction.class);
+    protected String action;
+    protected PortalContextProvider portalContext;
+    protected Map validWindowStates = new HashMap();
+    protected Map validPortletModes = new HashMap();
+    
+    public ChangePortletAction(String template, 
+            String errorTemplate, 
+            String action)
+    throws AJAXException    
+    {
+        this(template, errorTemplate, action, null, null, null);
+    }
+    
+    public ChangePortletAction(String template, 
+                             String errorTemplate, 
+                             String action,
+                             PageManager pageManager,
+                             PortletActionSecurityBehavior securityBehavior,
+                             PortalContextProvider portalContext)
+    throws AJAXException
+    {
+        super(template, errorTemplate, pageManager, securityBehavior);
+        this.action = action;
+        this.portalContext = portalContext;
+        Iterator modes = this.portalContext.getSupportedPortletModes().iterator();      
 
+        while (modes.hasNext())
+        {
+            String mode = modes.next().toString();
+            this.validPortletModes.put(mode, mode);
+        }
+        Iterator states = this.portalContext.getSupportedWindowStates().iterator();     
  
+        while (states.hasNext())
+        {
+            String state = states.next().toString();
+            this.validWindowStates.put(state, state);
+        }        
+    }
+
+    public boolean run(RequestContext requestContext, Map resultMap)
+    {
+        boolean success = true;
+        String status = "success";
+        try
+        {
+            resultMap.put(ACTION, action);
+            // Get the necessary parameters off of the request
+            String portletId = requestContext.getRequestParameter(PORTLETID);
+            if (portletId == null) 
+            { 
+                throw new Exception("portlet id not provided"); 
+            }            
+            resultMap.put(PORTLETID, portletId);
+            
+            String windowState = requestContext.getRequestParameter(WINDOW_STATE);
+            String portletMode = requestContext.getRequestParameter(PORTLET_MODE);
+            if (windowState == null && portletMode == null) 
+            { 
+                throw new Exception("portlet window state or mode not provided"); 
+            }           
+            if (windowState != null && !isValidWindowState(windowState))
+            {
+                throw new Exception("portlet window state " + windowState + " is not supported");
+            }
+            if (portletMode != null && !isValidPortletMode(portletMode))
+            {
+                throw new Exception("portlet mode " + portletMode + " is not supported");
+            }
+                        
+            if (false == checkAccess(requestContext, JetspeedActions.EDIT))
+            {
+                Page page = requestContext.getPage();
+                Fragment fragment = page.getFragmentById(portletId);
+                if (fragment == null)
+                {
+                    success = false;
+                    resultMap.put(REASON, "Fragment not found");
+                    return success;                    
+                }
+                int column = fragment.getLayoutColumn();
+                int row = fragment.getLayoutRow();                
+                if (!createNewPageOnEdit(requestContext))
+                {
+                    success = false;
+                    resultMap.put(REASON, "Insufficient access to edit page");
+                    return success;
+                }
+                status = "refresh";
+                // translate old portlet id to new portlet id
+                Fragment newFragment = getFragmentIdFromLocation(row, column, requestContext.getPage());
+                if (newFragment == null)
+                {
+                    success = false;
+                    resultMap.put(REASON, "Failed to find new fragment");
+                    return success;                    
+                }                
+                portletId = newFragment.getId();
+            }            
+            Page page = requestContext.getPage();            
+            Fragment fragment = page.getFragmentById(portletId);
+            String oldState = fragment.getState();
+            String oldMode = fragment.getMode();
+            if (windowState != null)
+                fragment.setState(windowState);
+            if (portletMode != null)
+                fragment.setMode(portletMode);
+            
+            if (pageManager != null)
+                pageManager.updatePage(page);
+            
+            resultMap.put(STATUS, status);
+            
+            if (windowState != null)
+            {
+                resultMap.put(OLD_WINDOW_STATE, oldState);
+                resultMap.put(WINDOW_STATE, windowState);
+            }
+
+            if (portletMode != null)
+            {
+                resultMap.put(OLD_PORTLET_MODE, oldMode);
+                resultMap.put(PORTLET_MODE, portletMode);
+            }
+            
+        } 
+        catch (Exception e)
+        {
+            // Log the exception
+            log.error("exception while moving a portlet", e);
+            resultMap.put(REASON, e.toString());
+            // Return a failure indicator
+            success = false;
+        }
+
+        return success;
+    }
+    
+    protected boolean isValidWindowState(String windowState)
+    {
+        return this.validWindowStates.containsKey(windowState);
+    }
+    protected boolean isValidPortletMode(String portletMode)
+    {
+        return this.validPortletModes.containsKey(portletMode);
+    }
+    
+}

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java?rev=392165&r1=392164&r2=392165&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
Thu Apr  6 19:49:02 2006
@@ -27,7 +27,11 @@
 	public static final String STATUS = "status";
 	public static final String ACTION = "action";
     public static final String REASON = "reason";
-	public static final String PORTLETID = "id";    
+	public static final String PORTLETID = "id";
+    public static final String WINDOW_STATE = "state";
+    public static final String PORTLET_MODE = "mode";
+    public static final String OLD_WINDOW_STATE = "oldState";
+    public static final String OLD_PORTLET_MODE = "oldMode";    
 	public static final String OLDCOL = "oldcol";
 	public static final String OLDROW = "oldrow";
 	public static final String NEWCOL = "newcol";

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java?rev=392165&r1=392164&r2=392165&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
Thu Apr  6 19:49:02 2006
@@ -107,7 +107,7 @@
         return success;
 	}
     
-    protected List retrievePortlets(RequestContext requestContext, String filter)
+    public List retrievePortlets(RequestContext requestContext, String filter)
     {
         Iterator portlets = null;
         List list = new ArrayList();

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java?rev=392165&r1=392164&r2=392165&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
Thu Apr  6 19:49:02 2006
@@ -118,8 +118,8 @@
                 resultMap.put(REASON, "Fragment not found");
                 return success;                
             }
-            //Coordinate coordinate = placement.remove(fragment);
-            Page page = requestContext.getPage();
+            placement.remove(fragment);
+            Page page = placement.syncPageFragments();
             page.removeFragmentById(fragment.getId());            
             pageManager.updatePage(page);            
             // Build the results for the response



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message