portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r377040 - in /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed: decoration/DecorationValve.java velocity/JetspeedPowerToolImpl.java
Date Sat, 11 Feb 2006 20:14:36 GMT
Author: ate
Date: Sat Feb 11 12:14:33 2006
New Revision: 377040

URL: http://svn.apache.org/viewcvs?rev=377040&view=rev
Log:
Centralizing all DecoratorAction creation for Page and Portlet level actions using the PageActionAccess
component
to the DecorationValve, thus removing all legacy usage thereof from the JetspeedPowerTool.
Furthermore, added Page "edit" state management using the new PageEditAccess features of PageActionAccess.
See http://issues.apache.org/jira/browse/JS2-468.

Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecorationValve.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecorationValve.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecorationValve.java?rev=377040&r1=377039&r2=377040&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecorationValve.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecorationValve.java
Sat Feb 11 12:14:33 2006
@@ -15,12 +15,10 @@
  */
 package org.apache.jetspeed.decoration;
 
-import java.security.Principal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import javax.portlet.PortletMode;
 import javax.portlet.WindowState;
@@ -37,15 +35,12 @@
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.ContentPage;
-import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.pipeline.PipelineException;
 import org.apache.jetspeed.pipeline.valve.AbstractValve;
 import org.apache.jetspeed.pipeline.valve.Valve;
 import org.apache.jetspeed.pipeline.valve.ValveContext;
 import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.velocity.DecoratorAction;
-import org.apache.jetspeed.velocity.JetspeedPowerToolImpl;
-import org.apache.jetspeed.velocity.PageActionAccess;
 import org.apache.pluto.om.entity.PortletEntity;
 import org.apache.pluto.om.portlet.ContentTypeSet;
 import org.apache.pluto.om.window.PortletWindow;
@@ -89,9 +84,10 @@
         }
         ContentPage page = requestContext.getPage();
         Theme theme = decorationFactory.getTheme(page, requestContext);
+
         requestContext.setAttribute(PortalReservedParameters.PAGE_THEME_ATTRIBUTE, theme);
         
-        PageActionAccess pageActionAccess = getPageActionAccess(requestContext, page);
+        PageActionAccess pageActionAccess = (PageActionAccess)requestContext.getAttribute(PortalReservedParameters.PAGE_EDIT_ACCESS_ATTRIBUTE);
         
         ContentFragment rootFragment = page.getRootContentFragment();
         
@@ -106,59 +102,6 @@
     }
     
     /**
-     * Returns a <code>PageActionAccess</code> for the current user request.
-     * 
-     * @see PageActionAccess
-     * @param requestContext RequestContext of the current portal request.
-     * @param page
-     * @return PageActionAccess for the current user request.
-     */
-    protected PageActionAccess getPageActionAccess(RequestContext requestContext, Page page)
-    { 
-        String key = page.getId();
-        boolean loggedOn = isLoggedOn(requestContext);
-        boolean anonymous = !loggedOn;
-        PageActionAccess pageActionAccess = null;
-
-   
-        Map sessionActions = (Map) requestContext.getSessionAttribute(JetspeedPowerToolImpl.POWER_TOOL_SESSION_ACTIONS);
-        if (sessionActions == null)
-        {
-            sessionActions = new HashMap();
-            requestContext.setSessionAttribute(JetspeedPowerToolImpl.POWER_TOOL_SESSION_ACTIONS,
sessionActions);
-        }
-        else
-        {
-            pageActionAccess = (PageActionAccess) sessionActions.get(key);
-        }
-        if (pageActionAccess == null)
-        {
-            pageActionAccess = new PageActionAccess(anonymous, page);
-            sessionActions.put(key, pageActionAccess);
-        }
-        else
-        {
-            pageActionAccess.checkReset(loggedOn, page);
-        }
-        
-        
-        return pageActionAccess;
-    }
-
-    /**
-     * Indicates if the user of the current request has been authenticated.
-     * 
-     * @param requestContext RequestContext of the current portal request.
-     * @return <code>true</code> if the user is currently authenticated, otherwise
returns
-     * <code>false</code>.
-     */
-    protected boolean isLoggedOn(RequestContext requestContext)
-    {
-        Principal principal = requestContext.getRequest().getUserPrincipal();
-        return (principal != null);
-    }
-
-    /**
      * Returns the current <code>PortletMode</code> for the target 
      * <code>Fragment</code> in the current portal request.
      * 
@@ -205,7 +148,7 @@
     {
         PortletEntity portletEntity = windowAccessor.getPortletWindow(fragment).getPortletEntity();
         PortletDefinitionComposite portlet = (PortletDefinitionComposite) portletEntity.getPortletDefinition();
-        Page page = requestContext.getPage();
+        ContentPage page = requestContext.getPage();
         
         if (null == portlet)
         {
@@ -219,24 +162,24 @@
 
         ContentTypeSet content = portlet.getContentTypeSet();
 
-        String fragmentId = fragment.getId();
         String portletName = portlet.getUniqueName();
         PortletWindow window = windowAccessor.getPortletWindow(fragment);        
         
         boolean isRootLayout = fragment.equals(page.getRootFragment());
 
-        if (!isRootLayout || pageActionAccess.isEditAllowed())
+        if ( isRootLayout )
         {
-            List portletModeActions = getPortletModes(requestContext, pageActionAccess, mode,
content, portletName, window, fragment);
-            actions.addAll(portletModeActions);
+            List pageModeActions = getPageModes(requestContext, pageActionAccess, page);
+            actions.addAll(pageModeActions);
         }
-        
-        if(!isRootLayout)
+        else if ( !Fragment.LAYOUT.equals(fragment.getType()) )
         {
+            List portletModeActions = getPortletModes(requestContext, pageActionAccess, mode,
content, portletName, window, fragment);
+            actions.addAll(portletModeActions);
             List stateActions = getWindowStates(requestContext, pageActionAccess, state,
portletName, window, fragment);
             actions.addAll(stateActions);
         }
-
+        
         decoration.setActions(actions);
     }
     
@@ -301,6 +244,86 @@
         return portletModes;
     }
     
+    
+    /**
+     * Builds a list of portlet modes that can be executed on the current
+     * <code>fragment</code> excluding the portlet's current mode.
+     * 
+     * @param requestContext RequestContext of the current portal request.
+     * @param pageActionAccess
+     * @param mode
+     * @param content
+     * @param portletName
+     * @param window
+     * @param fragment
+     * @return <code>java.util.List</code> of modes excluding the current one.
+     * @throws PortletEntityNotStoredException 
+     */
+    protected List getPageModes(RequestContext requestContext, PageActionAccess pageActionAccess,
ContentPage page)
+    {
+        List pageModes = new ArrayList();
+        
+        ContentFragment fragment = page.getRootContentFragment();
+        Decoration decoration = fragment.getDecoration();
+        
+        try
+        {
+            PortletWindow window = windowAccessor.getPortletWindow(fragment);        
+            PortletEntity portletEntity = window.getPortletEntity();
+            PortletDefinitionComposite portlet = (PortletDefinitionComposite) portletEntity.getPortletDefinition();
       
+            ContentTypeSet content = portlet.getContentTypeSet();
+
+            NavigationalState nav = requestContext.getPortalURL().getNavigationalState();
+            PortletMode mode = nav.getMode(window);
+            WindowState state = nav.getState(window);
+            
+            if (mode.equals(PortletMode.HELP) || !state.equals(WindowState.NORMAL))
+            {
+                // switch back to VIEW mode and NORMAL state.
+                DecoratorAction action = createDecoratorAction(PortletMode.VIEW.toString(),
decoration);                        
+                PortalURL portalURL = requestContext.getPortalURL();
+                action.setAction(portalURL.createPortletURL(window, PortletMode.VIEW, WindowState.NORMAL,
portalURL.isSecure()).toString());
+                pageModes.add(action);
+            }
+            else if ( pageActionAccess.isEditAllowed() )
+            {
+                String targetMode = pageActionAccess.isEditing() ? PortletMode.VIEW.toString()
: PortletMode.EDIT.toString();
+                DecoratorAction action = createDecoratorAction(targetMode, decoration);
+                PortalURL portalURL = requestContext.getPortalURL();
+                HashMap parameters = new HashMap();
+                String[] paramValues = new String[]{targetMode};
+                parameters.put("pageMode",paramValues);
+
+                // Use an ActionURL to set the oposite pageMode and always set VIEW mode
and state NORMAL 
+                action.setAction(portalURL.createPortletURL(window, parameters, PortletMode.VIEW,
WindowState.NORMAL, true, portalURL.isSecure()).toString());
+                pageModes.add(action);
+                
+                if (content.supportsPortletMode(PortletMode.HELP))
+                {
+                    action = createDecoratorAction(PortletMode.HELP.toString(), decoration);
+                    if ( pageActionAccess.isEditing() )
+                    {
+                        // force it back to VIEW mode first with an ActionURL, as well as
setting HELP mode and MAXIMIZED state
+                        paramValues[0] = PortletMode.VIEW.toString();
+                        action.setAction(portalURL.createPortletURL(window, parameters, PortletMode.HELP,
WindowState.MAXIMIZED, true, portalURL.isSecure()).toString());
+                    }
+                    else
+                    {
+                        // switch to mode HELP and state MAXIMIZED
+                        action.setAction(portalURL.createPortletURL(window,PortletMode.HELP,
WindowState.MAXIMIZED, portalURL.isSecure()).toString());
+                    }
+                    pageModes.add(action);
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            log.warn("Unable to initalize PageLayout actions for fragment "+fragment.getId(),
e);
+            pageModes = null;
+        }
+        
+        return pageModes;
+    }  
     
     /**
      * Builds a list of window states that can be executed on the current

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java?rev=377040&r1=377039&r2=377040&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerToolImpl.java
Sat Feb 11 12:14:33 2006
@@ -18,13 +18,9 @@
 import java.io.PrintWriter;
 import java.io.Writer;
 import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
-import java.util.Map;
 import java.util.Set;
 
 import javax.portlet.PortletConfig;
@@ -40,7 +36,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.Jetspeed;
-import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.capabilities.CapabilityMap;
 import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
@@ -48,14 +43,12 @@
 import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
 import org.apache.jetspeed.container.state.NavigationalState;
 import org.apache.jetspeed.container.url.BasePortalURL;
-import org.apache.jetspeed.container.url.PortalURL;
 import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
 import org.apache.jetspeed.container.window.PortletWindowAccessor;
 import org.apache.jetspeed.locator.LocatorDescriptor;
 import org.apache.jetspeed.locator.TemplateDescriptor;
 import org.apache.jetspeed.locator.TemplateLocator;
 import org.apache.jetspeed.locator.TemplateLocatorException;
-import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.request.RequestContext;
@@ -63,8 +56,6 @@
 import org.apache.jetspeed.util.ArgUtil;
 import org.apache.jetspeed.util.Path;
 import org.apache.pluto.om.entity.PortletEntity;
-import org.apache.pluto.om.portlet.ContentTypeSet;
-import org.apache.pluto.om.window.PortletWindow;
 import org.apache.velocity.context.Context;
 
 /**
@@ -112,8 +103,6 @@
 
     protected Writer templateWriter;
 
-    public static final String POWER_TOOL_SESSION_ACTIONS = "org.apache.jetspeed.powertool.actions";
-
     protected static final Log log = LogFactory.getLog(JetspeedPowerToolImpl.class);
 
     protected CapabilityMap capabilityMap;
@@ -487,7 +476,6 @@
         // include decorated layout or portlet fragment
         try
         {
-            String fragmentType = f.getType();
             return decorateAndIncludePortlet(f);
         }
         catch (Exception e)
@@ -656,10 +644,11 @@
      * @return A list of actions available to the current window, filtered by
      *         securty access and current state.
      * @throws Exception
+     * @deprecated
      */
     public List getDecoratorActions()
     {
-        return getDecoratorActions(false);
+        return getCurrentFragment().getDecoration().getActions();
     }
 
     /**
@@ -669,200 +658,11 @@
      * @return A list of actions available to the current window, filtered by
      *         securty access and current state.
      * @throws Exception
+     * @deprecated
      */
     public List getPageDecoratorActions() throws Exception
     {
-        return getDecoratorActions(true);
-    }
-
-    protected List getDecoratorActions(boolean layout)
-    {
-        try
-        {
-            String key = getPage().getId();
-            boolean anonymous = !getLoggedOn();
-            PageActionAccess pageActionAccess = null;
-
-            synchronized (getRequestContext().getRequest().getSession())
-            {
-                Map sessionActions = (Map) getRequestContext().getSessionAttribute(POWER_TOOL_SESSION_ACTIONS);
-                if (sessionActions == null)
-                {
-                    sessionActions = new HashMap();
-                    getRequestContext().setSessionAttribute(POWER_TOOL_SESSION_ACTIONS, sessionActions);
-                }
-                else
-                {
-                    pageActionAccess = (PageActionAccess) sessionActions.get(key);
-                }
-                if (pageActionAccess == null)
-                {
-                    pageActionAccess = new PageActionAccess(anonymous, getPage());
-                    sessionActions.put(key, pageActionAccess);
-                }
-                else
-                {
-                    pageActionAccess.checkReset(getLoggedOn(), getPage());
-                }
-            }
-
-            PortletDefinitionComposite portlet = (PortletDefinitionComposite) getCurrentPortletEntity()
-                    .getPortletDefinition();
-            if (null == portlet)
-            {
-                return Collections.EMPTY_LIST; // allow nothing
-            }
-
-            List actions = new ArrayList();
-
-            PortletMode mode = getPortletMode();
-            WindowState state = getWindowState();
-
-            ContentTypeSet content = portlet.getContentTypeSet();
-            ContentFragment fragment = getCurrentFragment();
-            String fragmentId = fragment.getId();
-            String portletName = portlet.getUniqueName();
-            PortletWindow window = windowAccess.getPortletWindow(fragment);
-            String resourceBase = getPageBasePath();
-
-            if (!layout || pageActionAccess.isEditAllowed())
-            {
-                if (mode.equals(PortletMode.VIEW))
-                {
-                    if (content.supportsPortletMode(PortletMode.EDIT) && pageActionAccess.isEditAllowed()
-                            && pageActionAccess.checkPortletMode(fragmentId, portletName,
PortletMode.EDIT))
-                    {
-                        actions.add(createPortletModeAction(window, JetspeedActions.EDIT,
PortletMode.EDIT,
-                                resourceBase));
-                    }
-                    if (content.supportsPortletMode(PortletMode.HELP)
-                            && pageActionAccess.checkPortletMode(fragmentId, portletName,
PortletMode.HELP))
-                    {
-                        actions.add(createPortletModeAction(window, JetspeedActions.HELP,
PortletMode.HELP,
-                                resourceBase));
-                    }
-                }
-                else if (mode.equals(PortletMode.EDIT))
-                {
-                    if (pageActionAccess.checkPortletMode(fragmentId, portletName, PortletMode.VIEW))
-                    {
-                        actions.add(createPortletModeAction(window, JetspeedActions.VIEW,
PortletMode.VIEW,
-                                resourceBase));
-                    }
-                    if (content.supportsPortletMode(PortletMode.HELP)
-                            && pageActionAccess.checkPortletMode(fragmentId, portletName,
PortletMode.HELP))
-                    {
-                        actions.add(createPortletModeAction(window, JetspeedActions.HELP,
PortletMode.HELP,
-                                resourceBase));
-                    }
-                }
-                else
-                // help
-                {
-                    if (pageActionAccess.checkPortletMode(fragmentId, portletName, PortletMode.VIEW))
-                    {
-                        actions.add(createPortletModeAction(window, JetspeedActions.VIEW,
PortletMode.VIEW,
-                                resourceBase));
-                    }
-                    if (content.supportsPortletMode(PortletMode.EDIT) && pageActionAccess.isEditAllowed()
-                            && pageActionAccess.checkPortletMode(fragmentId, portletName,
PortletMode.EDIT))
-                    {
-                        actions.add(createPortletModeAction(window, JetspeedActions.EDIT,
PortletMode.EDIT,
-                                resourceBase));
-                    }
-                }
-            }
-
-            if (!layout)
-            {
-                if (state.equals(WindowState.NORMAL))
-                {
-                    if (pageActionAccess.checkWindowState(fragmentId, portletName, WindowState.MINIMIZED))
-                    {
-                        actions.add(createWindowStateAction(window, JetspeedActions.MINIMIZE,
WindowState.MINIMIZED,
-                                resourceBase));
-                    }
-                    if (pageActionAccess.checkWindowState(fragmentId, portletName, WindowState.MAXIMIZED))
-                    {
-                        actions.add(createWindowStateAction(window, JetspeedActions.MAXIMIZE,
WindowState.MAXIMIZED,
-                                resourceBase));
-                    }
-                }
-                else if (state.equals(WindowState.MAXIMIZED))
-                {
-                    if (pageActionAccess.checkWindowState(fragmentId, portletName, WindowState.MINIMIZED))
-                    {
-                        actions.add(createWindowStateAction(window, JetspeedActions.MINIMIZE,
WindowState.MINIMIZED,
-                                resourceBase));
-                    }
-                    if (pageActionAccess.checkWindowState(fragmentId, portletName, JetspeedActions.RESTORED))
-                    {
-                        actions.add(createWindowStateAction(window, JetspeedActions.RESTORE,
WindowState.NORMAL,
-                                resourceBase));
-                    }
-                }
-                else
-                // minimized
-                {
-                    if (pageActionAccess.checkWindowState(fragmentId, portletName, WindowState.MAXIMIZED))
-                    {
-                        actions.add(createWindowStateAction(window, JetspeedActions.MAXIMIZE,
WindowState.MAXIMIZED,
-                                resourceBase));
-                    }
-                    if (pageActionAccess.checkWindowState(fragmentId, portletName, JetspeedActions.RESTORED))
-                    {
-                        actions.add(createWindowStateAction(window, JetspeedActions.RESTORE,
WindowState.NORMAL,
-                                resourceBase));
-                    }
-                }
-            }
-
-            return actions;
-        }
-        catch (Exception e)
-        {
-            log.warn("Unable to generate decortator actions: " + e.toString());
-            return Collections.EMPTY_LIST;
-        }
-    }
-
-    protected DecoratorAction createDecoratorAction(String resourceBase, String actionName)
-    {
-        String imageExt = (String) renderRequest.getAttribute(ACTION_IMAGE_EXTENSION_ATTR);
-        if (imageExt == null)
-        {
-            imageExt = ".gif";
-        }
-        String link = renderResponse.encodeURL(resourceBase + "/content/images/" + actionName
+ ".gif");
-        return new DecoratorAction(actionName, actionName, link);
-    }
-
-    /**
-     * Creates a Decorator PortletMode Action to be added to the list of actions
-     * decorating a portlet.
-     */
-    protected DecoratorAction createPortletModeAction(PortletWindow window, String actionName,
PortletMode mode,
-            String resourceBase)
-    {
-        DecoratorAction action = createDecoratorAction(resourceBase, actionName);
-        PortalURL portalURL = getRequestContext().getPortalURL();
-        action.setAction(renderResponse.encodeURL(portalURL.createPortletURL(window, mode,
null, portalURL.isSecure())
-                .toString()));
-        return action;
-    }
-
-    /**
-     * Creates a Decorator WindowState Action to be added to the list of actions
-     * decorating a portlet.
-     */
-    protected DecoratorAction createWindowStateAction(PortletWindow window, String actionName,
WindowState state,
-            String resourceBase)
-    {
-        DecoratorAction action = createDecoratorAction(resourceBase, actionName);
-        PortalURL portalURL = getRequestContext().getPortalURL();
-        action.setAction(renderResponse.encodeURL(portalURL.createPortletURL(window, null,
state, portalURL.isSecure())
-                .toString()));
-        return action;
+        return getCurrentFragment().getDecoration().getActions();
     }
 
     /**



---------------------------------------------------------------------
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