weaver      2003/03/20 10:11:50

  Modified:    src/java/org/apache/jetspeed/portal/portlets JspPortlet.java
                        CustomizerVelocityPortlet.java VelocityPortlet.java
               src/java/org/apache/jetspeed/modules/actions/portlets
                        VelocityPortletAction.java JspPortletAction.java
  Log:
  Relative to enhancement bug id's17747 and 17756.  
  
  All Velocity/JSP Portlet/Actions now commonly extend GenericMVCPortlet and 
GenericMVCAction
  
  Revision  Changes    Path
  1.9       +10 -95    
jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/JspPortlet.java
  
  Index: JspPortlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/JspPortlet.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JspPortlet.java   6 Feb 2003 16:14:27 -0000       1.8
  +++ JspPortlet.java   20 Mar 2003 18:11:50 -0000      1.9
  @@ -54,119 +54,34 @@
   
   package org.apache.jetspeed.portal.portlets;
   
  -// Turbine util
  -import org.apache.turbine.util.RunData;
  -import org.apache.turbine.services.TurbineServices;
  -import org.apache.turbine.services.jsp.JspService;
  -import org.apache.turbine.util.Log;
  -import org.apache.turbine.modules.ActionLoader;
  -
  -// Jetspeed portal
  +// Jetspeed stuff
   import org.apache.jetspeed.portal.PortletException;
  -import org.apache.jetspeed.services.template.TemplateLocatorService;
  -import org.apache.jetspeed.util.PortletSessionState;
  -
  -// Ecs 
  -import org.apache.ecs.ConcreteElement;
  -import org.apache.ecs.ElementContainer;
  -import org.apache.ecs.StringElement;
  -
   
   /**
    * A JSP portlet example.
    * 
  + * STW: Changed to subclass the GenericMVCPortlet to help
  + * unify the handling of all template based portlets.
    * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Santiago Gala</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Weaver</a>
    */
  -public class JspPortlet extends AbstractInstancePortlet
  +public class JspPortlet extends GenericMVCPortlet
   {
   
       public static final String TEMPLATE = "template";
   
       /**
  -    By default the data is non cacheable
  +     * STW:  Backward compatibility: set the viewType to "JSP". 
  +     * By default the data is non cacheable
       */
       public void init() throws PortletException
       {
           setCacheable(false);
  +        setViewType("JSP");
  +        super.init();
  +        
       }
   
  -    public ConcreteElement getContent(RunData rundata)
  -    {
  -
  -        String template = "";
  -
  -        try 
  -        {
  -
  -            JspService service = (JspService) TurbineServices.getInstance()
  -                                             .getService(JspService.SERVICE_NAME);
  -            // this is only necessary if we ddon't run in a JSP page environment
  -            // but better be safe than sorry...
  -            service.addDefaultObjects(rundata);
  -
  -            // Allow access to portlet from .jsp template
  -            rundata.getRequest().setAttribute("portlet", this);
  -
  -            // Add js_peid out of convenience
  -            rundata.getRequest().setAttribute("js_peid", this.getID());
  -
  -            // Retrieve and execute the action object
  -            String actionName = getPortletConfig().getInitParameter("action");
  -            if (actionName != null) 
  -            {
  -                try 
  -                {
  -                    if (Log.getLogger().isDebugEnabled())
  -                    {
  -                        Log.debug("JspPorlet: Executing action [" + actionName + "] 
for portlet [" + this.getName() + "]");
  -                    }
  -                    ActionLoader.getInstance().exec(rundata, actionName);
  -                } 
  -                catch (Exception e) 
  -                {
  -                    Log.error(e);
  -                }
  -            }
  -
  -            // either the action selected the template, or use the default template 
  -            // defined in the registry
  -            if (PortletSessionState.getAttribute(this, rundata, TEMPLATE) != null)
  -            {
  -                template = (String) PortletSessionState.getAttribute(this, rundata, 
TEMPLATE);
  -                //PortletSessionState.clearAttribute(this, rundata, TEMPLATE);
  -                if (Log.getLogger().isDebugEnabled())
  -                {
  -                    Log.debug("JspPorlet: Template switched per request attribute 
to [" + template + "] for portlet [" + 
  -                              this.getName() + "]");
  -                }
  -            }
  -            else
  -            {
  -                // 
  -                // gets the jsp page from the xreg configuration
  -                // NOTE: wouldn't it be better to get the param from the PSML?
  -                //
  -                template = getPortletConfig().getInitParameter(TEMPLATE);
  -            }
  -
  -            //we use the template locator service to translate the template
  -            TemplateLocatorService lserv = (TemplateLocatorService) 
TurbineServices.getInstance()
  -                .getService(TemplateLocatorService.SERVICE_NAME);
  -            String locatedTemplate = lserv.locatePortletTemplate(rundata, template);
  -                        
  -            // handle request
  -            service.handleRequest(rundata, locatedTemplate);
  -            
  -        } 
  -        catch (Exception e) 
  -        {
  -            String message = "JspPortlet: Could not include the following JSP Page: 
 " + template + " : " + e.getMessage();
  -            Log.error(message, e);
  -            return new StringElement(message);
  -        }
  -
  -        return new ElementContainer();
  -    }
   
   }
  
  
  
  1.3       +13 -2     
jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/CustomizerVelocityPortlet.java
  
  Index: CustomizerVelocityPortlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/CustomizerVelocityPortlet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CustomizerVelocityPortlet.java    29 Mar 2002 20:12:33 -0000      1.2
  +++ CustomizerVelocityPortlet.java    20 Mar 2003 18:11:50 -0000      1.3
  @@ -57,6 +57,15 @@
   /**
    * This subclass of VelocityPortlet should be used as base portlet
    * for all VelocityPortlets that implement their own customizer
  + * <p>
  + *  <strong>NOTE:</strong>This supports the pre-MVC style of template based portlet 
development.  
  + *  The perefered method for defining customization is to set a parameter
  + *  named "provides.customization" in the portlet config
  + *  to either "true" or "false" depending on
  + *  whether or not that portlet will provide it's own customizer.  The portlet 
  + *  should also being using @see 
org.apache.jetspeed.portal.portlets.GenericMVCPortlet
  + *  or a sub-class there of.
  + * </p>
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta</a>
    */
  @@ -65,6 +74,8 @@
       /**
       * @return true if the portlet does its own customization
       */
  -    public boolean providesCustomization() { return true; }
  +    public boolean providesCustomization()
  +    {
  +        return true;
  +    }
   }
  -
  
  
  
  1.22      +18 -161   
jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/VelocityPortlet.java
  
  Index: VelocityPortlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/VelocityPortlet.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- VelocityPortlet.java      4 Mar 2003 00:05:04 -0000       1.21
  +++ VelocityPortlet.java      20 Mar 2003 18:11:50 -0000      1.22
  @@ -54,182 +54,39 @@
   
   package org.apache.jetspeed.portal.portlets;
   
  -// Turbine stuff
  -import org.apache.turbine.util.RunData;
  -import org.apache.turbine.services.velocity.TurbineVelocity;
  -import org.apache.turbine.services.pull.TurbinePull;
  -import org.apache.turbine.modules.ActionLoader;
  +
   
   // Jetspeed stuff
   import org.apache.jetspeed.portal.PortletException;
  -import org.apache.jetspeed.portal.PortletConfig;
  -import org.apache.jetspeed.services.TemplateLocator;
  -import org.apache.jetspeed.util.template.JetspeedLink;
  -import org.apache.jetspeed.util.template.JetspeedTemplateLink;
  -
  -
  -// Ecs stuff
  -import org.apache.ecs.ConcreteElement;
  -import org.apache.jetspeed.util.JetspeedClearElement;
  -
  -// Velocity Stuff
  -import org.apache.velocity.context.Context;
  -import org.apache.turbine.util.Log;
   
   /**
    * A Velocity based portlet implementation
  - * 
  + *    <p> 
  + *   <strong>NOTE:</strong>This supports the pre-MVC style of template 
  + *    based portlet development and is supplied for backward compatibility.
  + *    The prefered method is to define template-based portlets is to use    
  + *    @see org.apache.jetspeed.portal.portlets.GenericMVCPortlet
  + *    or a sub-class there of.  The GenericMVCPortlet javadoc provides
  + *    instructions for using using the MVC portlet model.
  + *   </p>
    * @author <a href="mailto:[EMAIL PROTECTED]">Roberto Carrasco</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Paul Spencer</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Weaver</a>u
    */
  -public class VelocityPortlet extends AbstractInstancePortlet
  +public class VelocityPortlet extends GenericMVCPortlet
   
   {
  -
  -    /** 
  -    How long in milliseconds will the content of this portlet be cached,
  -    that is, how long before regenerating it.
  -    The default is zero - never cache the content.
  -    This is specified in the portlet config parameter "cache-period-milliseconds"
  -    **/
  -    private long cachePeriod = 0;
  -
  -    /**
  -     * Initialize this portlet by looking up the cache period (default is zero)
  -     * @throws PortletException Initialization failed
  -     */
  -    public void init() throws PortletException {
  -
  -        PortletConfig config = this.getPortletConfig();
  -
  -        try
  -        {
  -            cachePeriod = Long.parseLong( 
config.getInitParameter("cache-period-milliseconds","0") );
  -        } catch (NumberFormatException e) {
  -            cachePeriod = 0;
  -        }
  -    }
  -
  -    /**
  -    This methods outputs the content of the portlet for a given
  -    request.
  -
  -    @param data the RunData object for the request
  -    @return the content to be displayed to the user-agent
  +   /**
  +    * STW: Backward compatibility: set the viewType to "Velocity".
       */
  -    public ConcreteElement getContent( RunData data )
  -    {
  -        //if caching is turned off or no expiration time set, generate and return 
the content
  -        if (cachePeriod == 0 || null == getExpirationMillis())
  -            return getVelocityContent(data);
  -
  -        //is the cached content still valid, if not, generate and return the content
  -        if (getExpirationMillis().longValue() <= System.currentTimeMillis())
  -            return getVelocityContent(data);
  -
  -        //else, the cached content is fine to be returned
  -        return getContent( data, null , true );
  -    }
  -
  -
  -    /**
  -     * @param rundata The RunData object for the current request
  -     */    
  -    public ConcreteElement getVelocityContent( RunData rundata )
  +    public void init() throws PortletException
       {
  -        Log.debug("VelocityPortlet::getVelocityContent");
  -
  -        // create a blank context and with all the global application
  -        // Pull Tools inside
  -        Context context = TurbineVelocity.getContext();
  -        context.put( "data", rundata );
  -        context.put( "portlet", this );
  -        context.put( "conf", this.getPortletConfig() );
  -        context.put( "skin", this.getPortletConfig().getPortletSkin() );
  -
  -        //add a tool for security information to the template.
  -// FIXME:  This is causing an Exception.  Is it needed?         
  -//        context.put( "security", 
(JetspeedSecurityService)JetspeedSecurity.getService() );
  -        
  -        String template = getPortletConfig().getInitParameter("template");
  -        
  -        if (template != null)
  -        {
  -            context.put("template",template); 
  -        }
  -
  -        // Put the request and session based contexts
  -        TurbinePull.populateContext(context, rundata);
  -        
  -        //We need to initialize the jlink tool with ourselves to
  -        // enable links between portlets.
  -
  -        // FIXME: the tool jlink is deprecated.
  -        Object jlink = context.get( "jlink" );
  -        if (jlink instanceof JetspeedTemplateLink )
  -            ((JetspeedTemplateLink)jlink).setPortlet( this );
  -
  -        Object jslink = context.get( "jslink" );
  -        if (jslink instanceof JetspeedLink )
  -            ((JetspeedLink)jslink).setPortlet( this );
  -
  -        String actionName = getPortletConfig().getInitParameter("action");
  -        
  -        if (actionName != null)
  -        {
  -            // store the context so that the action can retrieve it
  -            Log.debug("VelocityPortlet found action "+actionName+" context 
"+context);
  -            rundata.getTemplateInfo().setTemplateContext( "VelocityPortletContext", 
context );
  -
  -            // if there is an action with the same name in modules/actions/portlets 
exec it
  -            try
  -            {
  -                ActionLoader.getInstance().exec( rundata, actionName );
  -            }
  -            catch( Exception e)
  -            {
  -               Log.error( e );
  -            }
  -        }
  - 
  -        // either the action selected the template, or use the default template 
  -        // defined in the registry
  -        if (context.get( "template" )!=null)
  -        {
  -            template = (String)context.get( "template" );
  -        }
  -        
  -        // generate the content
  -        JetspeedClearElement element = null;
  -
  -        try
  -        {
  -            if (-1 == template.indexOf(".vm"))
  -                template = template + ".vm";
  -            String templatePath = TemplateLocator.locatePortletTemplate(rundata, 
template);
  -            if (cachePeriod > 0)
  -            {
  -                String s = TurbineVelocity.handleRequest(context, templatePath);
  -                setExpirationMillis(cachePeriod + System.currentTimeMillis());
  -                element = new JetspeedClearElement( s );
  -                clearContent();  // doing this because setContent() is not 
overwriting current content.
  -                setContent(element);
  -            } else {
  -                TurbineVelocity.handleRequest(context, templatePath, 
rundata.getOut());
  -            }
  -        }
  -        catch( Exception e)
  -        {
  -            element = new JetspeedClearElement( e.toString() );
  -        }
  -        
  -        TurbineVelocity.requestFinished(context);
  -        
  -        if (element == null) element = new JetspeedClearElement("");
  -
  -        return element;
  +        setCacheable(true);
  +        setViewType("Velocity");
  +        super.init();        
       }
  +   
   
   
   }
  
  
  
  1.12      +88 -171   
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/VelocityPortletAction.java
  
  Index: VelocityPortletAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/VelocityPortletAction.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- VelocityPortletAction.java        4 Mar 2003 00:04:53 -0000       1.11
  +++ VelocityPortletAction.java        20 Mar 2003 18:11:50 -0000      1.12
  @@ -54,15 +54,16 @@
    
   package org.apache.jetspeed.modules.actions.portlets;
   
  +
  +import java.lang.reflect.Method;
  +
  +import org.apache.jetspeed.portal.Portlet;
   import org.apache.jetspeed.portal.portlets.VelocityPortlet;
  -import org.apache.jetspeed.services.rundata.JetspeedRunData;
  -import org.apache.jetspeed.util.PortletSessionState;
  +
   
   // Turbine stuff
  -import org.apache.turbine.util.Log;
   import org.apache.turbine.util.RunData;
  -import org.apache.turbine.services.velocity.TurbineVelocity;
  -import org.apache.turbine.modules.actions.VelocityAction;
  +
   
   // Velocity Stuff
   import org.apache.velocity.context.Context;
  @@ -73,196 +74,112 @@
    * 
    * <p>Don't call it from the URL, the Portlet and the Action are automatically
    * associated through the registry PortletName
  + *  <p>
  + *  <strong>NOTE:</strong>This supports the pre-MVC style of template based 
  + *   portlet development and is supplied for backward compatibility.   It is
  + *  suggested you  use a combination of 
  + *  @see org.apache.jetspeed.portal.portlets.GenericMVCPortlet along with
  + *  subclassing @see org.apache.jetspeed.portal.portlets.GenericMVCAction
  + *  for future portlet development.
  + *  </p>
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Roberto Carrasco</a>
    *
    * @version $Id$
    */
  -public abstract class VelocityPortletAction extends VelocityAction
  +public abstract class VelocityPortletAction extends GenericMVCAction
   {
   
  -    /**
  -     * This overrides the default Action.perform() to execute the
  -     * doEvent() method.  If that fails, then it will execute the
  -     * doPerform() method instead.
  -     *
  -     * @param data A Turbine RunData object.
  -     * @exception Exception, a generic exception.
  -     */
  -    protected void perform( RunData rundata )
  -        throws Exception
  -    {
  -        Context context = getContext(rundata);
  -        if ((context!=null)&&(rundata.getParameters().getString("action")!=null))
  -        {
  -            // if context is already defined and Actions defined, events 
  -            // have already been processed, call doPerform
  -            Log.debug("Action detected with action + context");
  -            doPerform(rundata, context);
  -        }
  -        else
  -        {
  -            // if context is null, create a new one
  -            if (context==null)
  -            {
  -                Log.debug("Action: building action context");
  -                context = TurbineVelocity.getContext();
  -                
rundata.getTemplateInfo().setTemplateContext("VelocityActionContext",context);
  -            }
  -
  -            try
  -            {
  -                // process implicit ActionEvent invocation
  -                Log.debug("Action: try executing events");
  -                
  -                VelocityPortlet portlet = (VelocityPortlet) context.get("portlet");
  -                
  -                if (portlet != null)
  -                {
  -                     // verify this portlet is the one requested by checking the 
  -                     // js_peid request var.  If there is no js_peid
  -                     // do not worry a about verifing.  helps with backward compat.
  -                    if (rundata.getParameters().getString("js_peid") == null
  -                        || PortletSessionState.isMyRequest(rundata, portlet))
  -                    {
  -                        executeEvents(rundata, context);
  -                    }
  -                    else
  -                    {
  -                        Log.debug("Action: calling doPerform");
  -                        doPerform(rundata, context);
  -                    }
  -                }
  -                else
  -                {
  -                    executeEvents(rundata, context);
  -                }
  -               
  -            }                    
  -            catch (NoSuchMethodException e)
  -            {
  -                // no event selected, process normal context generation
  -                Log.debug("Action: calling doPerform");
  -                doPerform(rundata, context);
  -            }
  -        }
  -    }
   
  -    /**
  -     * This method is used when you want to short circuit an Action
  -     * and change the template that will be executed next.
  -     *
  -     * @param data Turbine information.
  -     * @param template The template that will be executed next.
  +
  +    /** 
  +     * Subclasses must override this method to provide default behavior 
  +     * for the portlet action    
        */
  -    public void setTemplate(RunData data,
  -                            String template)
  -    {
  -        getContext(data).put( "template" , template );
  -    }
  +    protected abstract void buildNormalContext(VelocityPortlet portlet, 
  +                                                Context context,
  +                                                RunData rundata)
  +        throws Exception;
   
       /**
  -     * Return the Context needed by Velocity.
  -     *
  -     * @param RunData data
  -     * @return Context, a context for web pages.
  +     * STW: Backwards compatibility so the overriden method is called specifically 
using a cast to VelocityPortlet
  +     * @see 
org.apache.jetspeed.portal.portlets.mvc.PortletAction#buildNormalContext(Portlet, 
Context, RunData)
        */
  -    protected Context getContext(RunData data)
  -    {
  -        return (Context)data.getTemplateInfo()
  -                            .getTemplateContext( "VelocityPortletContext" );
  -    }
  -
  -    public void doPerform( RunData rundata, Context context )
  +    protected void buildNormalContext(Portlet portlet, Context context, RunData 
data)
           throws Exception
       {
  -        VelocityPortlet portlet = null;
  -        JetspeedRunData jdata = (JetspeedRunData)rundata;
  -        
  -        Log.debug("VelocityAction: retrieved context: "+context);
  -        if (context != null)
  -            portlet = (VelocityPortlet)context.get( "portlet" );
  -
  -        Log.debug("VelocityAction: retrieved portlet: "+portlet);
  -        if (portlet != null)
  -        {
  -            //System.out.println("class = " + this.getClass().getName());
  -            //rundata.getUser().setTemp(this.getClass().getName(), portlet.getID());
  -
  -            // we're bein configured
  -            if  ( ( jdata.getMode()==jdata.CUSTOMIZE ) 
  -                && (portlet.getName().equals(jdata.getCustomized().getName())) )
  -            {
  -                Log.debug("VelocityAction: building customize");
  -                buildConfigureContext( portlet, context, rundata);
  -                return;
  -            }
  -            
  -            // we're maximized
  -            if ( jdata.getMode()==jdata.MAXIMIZE )
  -            {
  -                Log.debug("VelocityAction: building maximize");
  -                buildMaximizedContext( portlet, context, rundata);
  -                return;
  -            }
  -
  -            Log.debug("VelocityAction: building normal");
  -            buildNormalContext( portlet, context, rundata);
  -        }        
  +        buildNormalContext((VelocityPortlet) portlet, context, data);
       }
   
       /**
  -     * Helper function for actions to get the portlet id.
  -     * Since actions are called before portal aggregation, the ids aren't available.
  -     * This function will fail on the very first aggregation for a session.
  -     *
  -     * @param data Turbine information.
  -     * @param template The template that will be executed next.
  -     */
  -     /*
  -    public String getPortletID(RunData rundata)
  -    {
  -       System.out.println("get portlet id class = " + this.getClass().getName());
  -
  -        return (String)rundata.getUser().getTemp(this.getClass().getName());
  -    }
  -       */
  -
  -    /** 
  -     * Subclasses should override this method if they wish to
  -     * build specific content when maximized. Default behavior is
  -     * to do the same as normal content.
  +     * @see 
org.apache.jetspeed.portal.portlets.mvc.PortletAction#buildConfigureContext(Portlet, 
Context, RunData)
        */
  -    protected void buildMaximizedContext( VelocityPortlet portlet, 
  -                                          Context context,
  -                                          RunData rundata )
  +    protected void buildConfigureContext(Portlet portlet, Context context, RunData 
data)
           throws Exception
       {
  -        buildNormalContext( portlet, context, rundata);
  -    }
  +        // STW: Don't try this at home, kids.  It's about the worst reflection hack 
you
  +        // can commit.  However, it was the only to have VelocityPortletAction 
implement
  +        // GenericMVCAction an still work correctly.  The sypmtom we where 
experiencing
  +        // was that we where skipping over the overriden method in the inheriting 
class
  +        // due to the ambiguousness of the build*() method signatures 
(VelocityPortlet vs. Portlet)
  +        // This only happens when the class subclassing VelocityPortlet defines a 
build*()
  +        // method with the signature build*(VelocityPortlet, Context, RunData), 
which is 100%
  +        // of the time with any previously defined Actions subclassing 
VelocityPortletAction.
  +        // Defining build*(Portlet, Context, RunData) fixes the problem but can't 
expect 
  +        // everyone to go back and change all of there Action method signatures 
just to
  +        // fix this.  Eventually we should deprecate this class all together.
  +        try
  +        {
  +            Method method =
  +                this.getClass().getDeclaredMethod(
  +                    "buildConfigureContext",
  +                    new Class[] { VelocityPortlet.class, Context.class, 
RunData.class });
  +            method.setAccessible(true);
  +            method.invoke(this, new Object[] { portlet, context, data });
  +            method.setAccessible(false);
   
  -    /** 
  -     * Subclasses should override this method if they wish to
  -     * provide their own customization behavior.
  -     * Default is to use Portal base customizer action
  -     */
  -    protected void buildConfigureContext( VelocityPortlet portlet, 
  -                                          Context context,
  -                                          RunData rundata )
  +        }
  +        catch (NoSuchMethodException e)
  +        {
  +            // Subclass did not override this method
  +            super.buildConfigureContext(portlet, context, data);
  +        }
  +        
  +    }
  +    
  +    
  +    protected void buildMaximizedContext(Portlet portlet, Context context, RunData 
data)
           throws Exception
       {
  -
  -        //FIXME: call the default CustomizePortlet action when written
  +        // STW: Don't try this at home, kids.  It's about the worst reflection hack 
you
  +        // can commit.  However, it was the only to have VelocityPortletAction 
implement
  +        // GenericMVCAction an still work correctly.  The sypmtom we where 
experiencing
  +        // was that we where skipping over the overriden method in the inheriting 
class
  +        // due to the ambiguousness of the build*() method signatures 
(VelocityPortlet vs. Portlet)
  +        // This only happens when the class subclassing VelocityPortlet defines a 
build*()
  +        // method with the signature build*(VelocityPortlet, Context, RunData), 
which is 100%
  +        // of the time with any previously defined Actions subclassing 
VelocityPortletAction.
  +        // Defining build*(Portlet, Context, RunData) fixes the problem but can't 
expect 
  +        // everyone to go back and change all of there Action method signatures 
just to
  +        // fix this.  Eventually we should deprecate this class all together.
  +        try
  +        {
  +            Method method =
  +                this.getClass().getDeclaredMethod(
  +                    "buildMaximizedContext",
  +                    new Class[] { VelocityPortlet.class, Context.class, 
RunData.class });
  +            method.setAccessible(true);
  +            method.invoke(this, new Object[] { portlet, context, data });
  +            method.setAccessible(false);
  +        }
  +        catch (NoSuchMethodException e)
  +        {
  +            // Subclass did not override this method
  +            super.buildMaximizedContext(portlet, context, data);
  +        }
       }
  -
  -    /** 
  -     * Subclasses must override this method to provide default behavior 
  -     * for the portlet action
  -     */
  -    protected abstract void buildNormalContext( VelocityPortlet portlet, 
  -                                                Context context,
  -                                                RunData rundata )
  -        throws Exception;
  +   
  +   
   
   }
  
  
  
  1.5       +59 -194   
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/JspPortletAction.java
  
  Index: JspPortletAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/JspPortletAction.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JspPortletAction.java     6 Feb 2003 16:14:26 -0000       1.4
  +++ JspPortletAction.java     20 Mar 2003 18:11:50 -0000      1.5
  @@ -54,251 +54,116 @@
   
   package org.apache.jetspeed.modules.actions.portlets;
   
  -// Java stuff
  -import java.lang.reflect.Method;
  -import java.util.Enumeration;
  -
   // Jetspeed stuff
   import org.apache.jetspeed.portal.Portlet;
  -import org.apache.jetspeed.portal.portlets.JspPortlet;
  -import org.apache.jetspeed.services.rundata.JetspeedRunData;
  -import org.apache.jetspeed.util.PortletSessionState;
   
   // Turbine stuff
  -import org.apache.turbine.util.Log;
  +
   import org.apache.turbine.util.RunData;
  -import org.apache.turbine.util.ParameterParser;
  -import org.apache.jetspeed.modules.actions.JspAction;
   
  +import org.apache.velocity.context.Context;
   
   /**
    * An abstract action class to build JspPortlet actions.
    * 
    * <p>Don't call it from the URL, the Portlet and the Action are automatically
    * associated through the registry PortletName
  + *  <p>
  + *  <strong>NOTE:</strong>This supports the pre-MVC style of template based 
  + *   portlet development and is supplied for backward compatibility.   It is
  + *  suggested you  use a combination of 
  + *  @see org.apache.jetspeed.portal.portlets.GenericMVCPortlet along with
  + *  subclassing @see org.apache.jetspeed.portal.portlets.GenericMVCAction
  + *  for future portlet development.
  + *  </p>
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]">Mark Orciuch</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Weaver</a>
    *
    * @version $Id$
    */
  -public abstract class JspPortletAction extends JspAction
  +public abstract class JspPortletAction extends GenericMVCAction
   {
   
       /**
  -     * This method is used when you want to short circuit an Action
  -     * and change the template that will be executed next.
  -     * 
  -     * @param data     Turbine information.
  -     * @param template The template that will be executed next.
  -     * @deprecated As of 1.4b4
  -     */
  -    public void setTemplate(RunData data, String template)
  +    * @see 
org.apache.jetspeed.portal.portlets.mvc.PortletAction#buildConfigureContext(Portlet, 
Context, RunData)     
  +    */
  +    protected void buildConfigureContext(Portlet portlet, Context context, RunData 
rundata)
  +        throws Exception
       {
  -        data.getRequest().setAttribute(JspPortlet.TEMPLATE, template);
  -    }
   
  -    /**
  -     * This method is used when you want to short circuit an Action
  -     * and change the template that will be executed next. The template
  -     * will persist until session expires or setTemplate with null
  -     * template name is called.
  -     * 
  -     * @param data     Turbine information.
  -     * @param portlet  Reference to portlet.     
  -     * @param template The template that will be executed next.
  -     */
  -    public void setTemplate(RunData data, Portlet portlet, String template)
  -    {
  -        if (template != null)
  -        {
  -            PortletSessionState.setAttribute(portlet, data, JspPortlet.TEMPLATE, 
template);
  -        }   
  -        else
  +        buildConfigureContext(portlet, rundata);
  +        if (rundata.getRequest().getAttribute("_" + portlet.getID() + 
"_noConfigureContext")
  +            != null)
           {
  -            PortletSessionState.clearAttribute(portlet, data, JspPortlet.TEMPLATE);
  +            super.buildConfigureContext(portlet, context, rundata);
           }
       }
   
  -    /**
  -     * Performs the action
  -     * 
  -     * @param rundata
  -     * @exception Exception
  +    /** 
  +      * Kept for backward compatibility.  New classes should use 
  +     * the method signatures build*(Portlet, Context, RunData)
  +     * If you override this method <b>DO NOT</b> call super.buildConfigureContext().
  +     * <br>
  +     * Subclasses should override this method if they wish to
  +     * provide their own customization behavior.
  +     * Default is to use Portal base customizer action
        */
  -    public void doPerform(RunData rundata)
  -    throws Exception
  +    protected void buildConfigureContext(Portlet portlet, RunData rundata) throws 
Exception
       {
  -        Portlet portlet = (Portlet) rundata.getRequest().getAttribute("portlet");
  -        JetspeedRunData jdata = (JetspeedRunData) rundata;
   
  -        if (Log.getLogger().isDebugEnabled())
  -        {
  -            Log.debug("JspPortletAction: retrieved portlet: " + portlet);        
  -        }
  -        if (portlet != null)
  -        {
  -            // we're bein configured
  -            if ((jdata.getMode() == jdata.CUSTOMIZE) 
  -                && (portlet.getName().equals(jdata.getCustomized().getName())))
  -            {
  -                if (Log.getLogger().isDebugEnabled())
  -                {
  -                    Log.debug("JspPortletAction: building customize");
  -                }
  -                buildConfigureContext(portlet, rundata);
  -                return;
  -            }
  -
  -            // we're maximized
  -            if (jdata.getMode() == jdata.MAXIMIZE)
  -            {
  -                if (Log.getLogger().isDebugEnabled())
  -                {
  -                    Log.debug("JspPortletAction: building maximize");
  -                }
  -                buildMaximizedContext(portlet, rundata);
  -                return;
  -            }
  -
  -            if (Log.getLogger().isDebugEnabled())
  -            {
  -                Log.debug("JspPortletAction: building normal");
  -            }
  -            buildNormalContext(portlet, rundata);
  -        }
  +        // STW: backward compatibility bootstrap flag
  +        rundata.getRequest().setAttribute("_" + portlet.getID() + 
"_noConfigureContext", " ");
       }
   
       /**
  -     * This method should be called to execute the event based system.
  -     *
  -     * @param data Turbine information.
  -     * @exception Exception a generic exception.
  +     * @see 
org.apache.jetspeed.portal.portlets.mvc.PortletAction#buildMaximizedContext(Portlet, 
Context, RunData)
        */
  -    public void executeEvents(RunData data)
  -    throws Exception
  +    protected void buildMaximizedContext(Portlet portlet, Context context, RunData 
rundata)
  +        throws Exception
       {
  -        // Name of the button.
  -        String theButton = null;
  -
  -        // Parameter parser.
  -        ParameterParser pp = data.getParameters();
  -
  -        // The arguments to pass to the method to execute.
  -        Object[] args = new Object[2];
  -
  -        // The arguments to the method to find.
  -        Class[] classes = new Class[2];
  -        classes[0] = RunData.class;
  -        classes[1] = Portlet.class;
  -
  -        String button = pp.convert(BUTTON);
  -
  -        // Loop through and find the button.
  -        for (Enumeration e = pp.keys() ; e.hasMoreElements() ;)
  +        buildMaximizedContext(portlet, rundata);
  +        if (rundata.getRequest().getAttribute("_" + portlet.getID() + 
"_noMaximizedContext")
  +            != null)
           {
  -            String key = (String) e.nextElement();
  -            if (key.startsWith(button))
  -            {
  -                theButton = formatString(key);
  -                break;
  -            }
  -        }
  -        // Portlet context
  -        Portlet portlet = (Portlet) data.getRequest().getAttribute("portlet");      
  
  -
  -        // Ignore submits from other instances of the same portlet
  -        if (theButton == null || !PortletSessionState.isMyRequest(data, portlet))
  -        {
  -            throw new NoSuchMethodException("JspPortletAction: The button was null 
or not my request");
  -        }
  -
  -        if (Log.getLogger().isDebugEnabled())
  -        {
  -            Log.debug("JspPortletAction: attempting to execute event handler: " + 
theButton);
  -        }
  -
  -        Method method = getClass().getMethod(theButton, classes);
  -        args[0] = data;
  -        args[1] = portlet;
  -        method.invoke(this, args);
  -    }
  -
  -    /**
  -     * This overrides the default Action.perform() to execute the
  -     * doEvent() method.  If that fails, then it will execute the
  -     * doPerform() method instead.
  -     *
  -     * @param data A Turbine RunData object.
  -     * @exception Exception, a generic exception.
  -     */
  -    protected void perform(RunData rundata)
  -    throws Exception
  -    {
  -        if (rundata.getParameters().getString("action") != null)
  -        {
  -            // if context is already defined and Actions defined, events 
  -            // have already been processed, call doPerform
  -            if (Log.getLogger().isDebugEnabled())
  -            {
  -                Log.debug("JspPortletAction: Action detected, calling doPerform");
  -            }
  -            doPerform(rundata);
  -        }
  -        else
  -        {
  -            try
  -            {
  -                // process implicit ActionEvent invocation
  -                Log.debug("JspPortletAction: try executing events");
  -                
  -                Portlet portlet = (Portlet) 
rundata.getRequest().getAttribute("portlet");
  -                
  -                if (portlet != null)
  -                {
  -                    executeEvents(rundata);
  -                    doPerform(rundata);
  -                }
  -            }                    
  -            catch (NoSuchMethodException e)
  -            {
  -                // no event selected, process normal context generation
  -                if (Log.getLogger().isDebugEnabled())
  -                {
  -                    Log.debug("JspPortletAction: no events, calling doPerform");
  -                }
  -                doPerform(rundata);
  -            }
  +            super.buildMaximizedContext(portlet, context, rundata);
           }
       }
   
       /** 
  +     * Kept for backward compatibility.  New classes should use 
  +     * the method signatures build*(Portlet, Context, RunData)
  +     * If you override this method <b>DO NOT</b> call super.buildMaximizedContext().
  +     * <br>
        * Subclasses should override this method if they wish to
        * build specific content when maximized. Default behavior is
  -     * to do the same as normal content.
  +     * to do the same as normal content.<br>     
        */
  -    protected void buildMaximizedContext(Portlet portlet, RunData rundata)
  -    throws Exception
  +    protected void buildMaximizedContext(Portlet portlet, RunData rundata) throws 
Exception
       {
  -        buildNormalContext(portlet, rundata);
  +        // STW: backward compatibility bootstrap flag
  +        rundata.getRequest().setAttribute("_" + portlet.getID() + 
"_noMaximizedContext", " ");
       }
   
  -    /** 
  -     * Subclasses should override this method if they wish to
  -     * provide their own customization behavior.
  -     * Default is to use Portal base customizer action
  +    /**
  +     * @see 
org.apache.jetspeed.portal.portlets.mvc.PortletAction#buildNormalContext(Portlet, 
Context, RunData)
        */
  -    protected void buildConfigureContext(Portlet portlet, RunData rundata)
  -    throws Exception
  +    protected void buildNormalContext(Portlet portlet, Context context, RunData 
data)
  +        throws Exception
       {
  -
  -        //FIXME: call the default CustomizePortlet action when written
  +        buildNormalContext(portlet, data);
       }
   
       /** 
        * Subclasses must override this method to provide default behavior 
        * for the portlet action
        */
  -    protected abstract void buildNormalContext(Portlet portlet, RunData rundata)
  -    throws Exception;
  +    protected abstract void buildNormalContext(Portlet portlet, RunData rundata) 
throws Exception;
  +
  +    public void setTemplate(RunData data, Portlet portlet, String template)
  +    
  +    {
  +        super.setTemplate(data, template);
  +    }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to