You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2004/08/11 08:40:49 UTC

cvs commit: jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/portal/controls FusionPortletControl.java

taylor      2004/08/10 23:40:49

  Added:       fusion/src/java/org/apache/jetspeed/fusion/portal/controls
                        FusionPortletControl.java
  Log:
  completing support for window state and mode integration for JSR 168 portlets running in Fusion
  help, edit, min, max, restore
  originating from both j1 actions and j2 links, test keep state in tabs, and combinations of max + modes
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/portal/controls/FusionPortletControl.java
  
  Index: FusionPortletControl.java
  ===================================================================
  /*
   * 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.fusion.portal.controls;
  
  import java.util.List;
  import java.util.Vector;
  
  import javax.portlet.PortletMode;
  import javax.portlet.WindowState;
  import javax.servlet.ServletConfig;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.jetspeed.Jetspeed;
  import org.apache.jetspeed.PortalReservedParameters;
  import org.apache.jetspeed.container.session.NavigationalState;
  import org.apache.jetspeed.engine.Engine;
  import org.apache.jetspeed.fusion.portal.portlets.JetspeedFusionPortlet;
  import org.apache.jetspeed.om.security.JetspeedUser;
  import org.apache.jetspeed.portal.Portlet;
  import org.apache.jetspeed.portal.PortletException;
  import org.apache.jetspeed.portal.PortletInstance;
  import org.apache.jetspeed.portal.PortletState;
  import org.apache.jetspeed.portal.controls.VelocityPortletControl;
  import org.apache.jetspeed.portal.controls.PortletAction;
  import org.apache.jetspeed.request.RequestContext;
  import org.apache.jetspeed.request.RequestContextComponent;
  import org.apache.jetspeed.services.JetspeedSecurity;
  import org.apache.jetspeed.services.resources.FusionResources;
  import org.apache.jetspeed.services.rundata.JetspeedRunData;
  import org.apache.pluto.om.window.PortletWindow;
  import org.apache.turbine.util.RunData;
  
  
  /**
   * A Velocity based portlet control which implements all PortletState action
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   *
   * @version $Id: FusionPortletControl.java,v 1.1 2004/08/11 06:40:49 taylor Exp $
   *
   */
  public class FusionPortletControl extends VelocityPortletControl
  {
      private static final String J2_ENTITY = FusionResources.getString(FusionResources.J2_ENTITY); 
      private static final String PORTLET_APPLICATION_NAME = FusionResources.getString(FusionResources.PORTLET_APPLICATION_PARAMETER);
      private static final String PORTLET_DEFINITION_NAME = FusionResources.getString(FusionResources.PORTLET_DEFINITION_PARAMETER);
      private static final String J1_HELP_ACTION = FusionResources.getString(FusionResources.J1_HELP_ACTION);  
      private static final String J1_RESTORE_ACTION = FusionResources.getString(FusionResources.J1_RESTORE_ACTION);
      private static final String J1_MINIMIZE_ACTION = FusionResources.getString(FusionResources.J1_MINIMIZE_ACTION);
      private static final String J1_MAXIMIZE_ACTION = FusionResources.getString(FusionResources.J1_MAXIMIZE_ACTION);
      private static final String J1_EDIT_ACTION = FusionResources.getString(FusionResources.J1_EDIT_ACTION);
      private static final String J1_PRINT_ACTION = FusionResources.getString(FusionResources.J1_PRINT_ACTION);
      
      public void init()
      throws PortletException
      {
          super.init();
      }
      
      public void init(Portlet portlet)
      {
          super.init(portlet);
      }
          
      /** Builds a list of possible window actions for this portlet
       *  instance. For best results, the portlet should also implement the
       *  PortletState interface.
       *
       * @param rundata the request RunData
       * @param the portlet instance managed by this control
       * @return a list of ordered PortletAction objects describing the
       * the actions available for this portlet
       */
      protected List buildActionList( RunData rundata, Portlet portlet )
      {        
          PortletInstance instance = portlet.getInstance(rundata);
          Portlet real = portlet.getInstance(rundata).getPortlet();
          
          if (!(real instanceof JetspeedFusionPortlet))
          {
              return super.buildActionList(rundata, portlet);
          }
          JetspeedFusionPortlet fusion = (JetspeedFusionPortlet)real;
          
          List actions = new Vector();
          JetspeedRunData jdata = (JetspeedRunData)rundata;
  
          // disable actions option
          if (JetspeedSecurity.areActionsDisabledForAllUsers())
          {
              return actions;
          }
          JetspeedUser user = jdata.getJetspeedUser();
          if (JetspeedSecurity.areActionsDisabledForAnon() && false == user.hasLoggedIn())
          {
              return actions;
          }
  
          // the portlet is state aware
          PortletState state = (PortletState)portlet;
                  
          String entityId = instance.getAttribute(J2_ENTITY, "");
          serviceNavsPipeline(rundata, entityId);
          
          String pa = getPortletConfig().getInitParameter(PORTLET_APPLICATION_NAME, null);
          String pd = getPortletConfig().getInitParameter(PORTLET_DEFINITION_NAME, null);
          String registryKey = pa + "::" + pd;
          
          PortletWindow window = fusion.getPortletWindow(entityId, registryKey); 
          if (window == null)
          {
              return super.buildActionList(rundata, portlet);
          }
          PortletMode mode2 = PortletMode.VIEW;
          WindowState state2 = WindowState.NORMAL;
          NavigationalState nav = fusion.getNavigationalState(jdata);
          if (nav == null)
          {
              mode2 = PortletMode.VIEW;
              state2 = WindowState.NORMAL;
          }
          else
          {
              mode2 = nav.getMode(window);
              state2 = nav.getState(window);
          }
                  
          String action = jdata.getAction();
          
          boolean targeted = fusion.isTargeted(jdata, instance, action);
                  
          boolean customized = (jdata.getMode() == JetspeedRunData.CUSTOMIZE ||
                               mode2 == PortletMode.EDIT);
          
          boolean maximized = (jdata.getMode() == JetspeedRunData.MAXIMIZE ||
                              state2 == WindowState.MAXIMIZED);
          boolean helped = (mode2 == PortletMode.HELP || (targeted && action.equals(J1_HELP_ACTION)));
    
          boolean minimized = (state.isMinimized( rundata ) || state2 == WindowState.MINIMIZED);
          
          if (!customized && state.allowCustomize(rundata))
          {
              actions.add( new PortletAction("customize", "Customize") );
          }
   
          if (state.allowPrintFriendly(rundata))
          {
              actions.add( new PortletAction("print", "Print Friendly Format") );
          }
  
          if (!helped && state.allowInfo(rundata))
          {
              actions.add( new PortletAction("info", "Information") );
          }
                     
          if (state.allowClose(rundata))
          {
              actions.add( new PortletAction("close", "Close") );
          }
          
          if (maximized || customized || helped || minimized)
          {
              actions.add( new PortletAction("restore", "Restore") );
          }
          
         if (!minimized && state.allowMinimize( rundata ))
          {
              actions.add( new PortletAction("minimize", "Minimize") );
          }
  
          if (!maximized && state.allowMaximize( rundata ))
          {
              actions.add( new PortletAction("maximize", "Maximize") );
          }
          
          return createActionList(actions, jdata, portlet);
      }
      
      public void serviceNavsPipeline(RunData data, String entityId) 
      {        
          RequestContextComponent contextComponent = null;
          RequestContext context = null;
          try
          {
              HttpServletRequest request = data.getRequest();
              HttpServletResponse response =  data.getResponse();
              ServletConfig config = data.getServletConfig();
              Engine engine = Jetspeed.getEngine();
              contextComponent = (RequestContextComponent)Jetspeed.getComponentManager().getComponent(RequestContextComponent.class);
              context = (RequestContext) data.getRequest().getAttribute(JetspeedFusionPortlet.FUSION_NAV_STATE);
              if (context == null)
              {
                  context = contextComponent.create(request, response, config);
                  data.getRequest().setAttribute(JetspeedFusionPortlet.FUSION_NAV_STATE, context);                
              }
              
              context.setAttribute(PortalReservedParameters.PORTLET_ENTITY, entityId);
              context.setAttribute(PortalReservedParameters.PIPELINE, FusionResources.NAVS_PIPELINE);
              engine.service(context);          
          }
          catch (Throwable t)
          {
              t.printStackTrace();            
          }
          finally
          {
             // if (contextComponent != null && context != null)
             // {
             //     contextComponent.release(context);
             // }                        
          }
      }
  
  }
  
  
  

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