View Javadoc

1   /*
2    * Copyright 2000-2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16   
17  package org.apache.jetspeed.modules.actions.portlets;
18  
19  
20  import java.lang.reflect.Method;
21  
22  import org.apache.jetspeed.portal.Portlet;
23  import org.apache.jetspeed.portal.portlets.VelocityPortlet;
24  
25  
26  // Turbine stuff
27  import org.apache.turbine.util.RunData;
28  
29  
30  // Velocity Stuff
31  import org.apache.velocity.context.Context;
32  
33  
34  /***
35   * An abstract action class to build VelocityPortlet actions.
36   * 
37   * <p>Don't call it from the URL, the Portlet and the Action are automatically
38   * associated through the registry PortletName
39   *  <p>
40   *  <strong>NOTE:</strong>This supports the pre-MVC style of template based 
41   *   portlet development and is supplied for backward compatibility.   It is
42   *  suggested you  use a combination of 
43   *  @see org.apache.jetspeed.portal.portlets.GenericMVCPortlet along with
44   *  subclassing @see org.apache.jetspeed.portal.portlets.GenericMVCAction
45   *  for future portlet development.
46   *  </p>
47   * 
48   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
49   * @author <a href="mailto:re_carrasco@bco011.sonda.cl">Roberto Carrasco</a>
50   *
51   * @version $Id: VelocityPortletAction.java,v 1.14 2004/02/23 02:56:58 jford Exp $
52   */
53  public abstract class VelocityPortletAction extends GenericMVCAction
54  {
55  
56  
57  
58      /*** 
59       * Subclasses must override this method to provide default behavior 
60       * for the portlet action    
61       */
62      protected abstract void buildNormalContext(VelocityPortlet portlet, 
63                                                  Context context,
64                                                  RunData rundata)
65          throws Exception;
66  
67      /***
68       * STW: Backwards compatibility so the overriden method is called specifically using a cast to VelocityPortlet
69       * @see org.apache.jetspeed.portal.portlets.mvc.PortletAction#buildNormalContext(Portlet, Context, RunData)
70       */
71      protected void buildNormalContext(Portlet portlet, Context context, RunData data)
72          throws Exception
73      {
74          buildNormalContext((VelocityPortlet) portlet, context, data);
75      }
76  
77      /***
78       * @see org.apache.jetspeed.portal.portlets.mvc.PortletAction#buildConfigureContext(Portlet, Context, RunData)
79       */
80      protected void buildConfigureContext(Portlet portlet, Context context, RunData data)
81          throws Exception
82      {
83          // STW: Don't try this at home, kids.  It's about the worst reflection hack you
84          // can commit.  However, it was the only to have VelocityPortletAction implement
85          // GenericMVCAction an still work correctly.  The sypmtom we where experiencing
86          // was that we where skipping over the overriden method in the inheriting class
87          // due to the ambiguousness of the build*() method signatures (VelocityPortlet vs. Portlet)
88          // This only happens when the class subclassing VelocityPortlet defines a build*()
89          // method with the signature build*(VelocityPortlet, Context, RunData), which is 100%
90          // of the time with any previously defined Actions subclassing VelocityPortletAction.
91          // Defining build*(Portlet, Context, RunData) fixes the problem but can't expect 
92          // everyone to go back and change all of there Action method signatures just to
93          // fix this.  Eventually we should deprecate this class all together.
94          try
95          {
96              Method method =
97                  this.getClass().getDeclaredMethod(
98                      "buildConfigureContext",
99                      new Class[] { VelocityPortlet.class, Context.class, RunData.class });
100             method.setAccessible(true);
101             method.invoke(this, new Object[] { portlet, context, data });
102             method.setAccessible(false);
103 
104         }
105         catch (NoSuchMethodException e)
106         {
107             // Subclass did not override this method
108             super.buildConfigureContext(portlet, context, data);
109         }
110         
111     }
112     
113     /***
114      * prevents possible self-referencing loop when sub-classes invoke super.buildConfigureContext().
115      * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
116      */
117     protected void buildConfigureContext(VelocityPortlet portlet, Context context, RunData data)
118         throws Exception
119     {
120     }
121     
122     
123     protected void buildMaximizedContext(Portlet portlet, Context context, RunData data)
124         throws Exception
125     {
126         // STW: Don't try this at home, kids.  It's about the worst reflection hack you
127         // can commit.  However, it was the only to have VelocityPortletAction implement
128         // GenericMVCAction an still work correctly.  The sypmtom we where experiencing
129         // was that we where skipping over the overriden method in the inheriting class
130         // due to the ambiguousness of the build*() method signatures (VelocityPortlet vs. Portlet)
131         // This only happens when the class subclassing VelocityPortlet defines a build*()
132         // method with the signature build*(VelocityPortlet, Context, RunData), which is 100%
133         // of the time with any previously defined Actions subclassing VelocityPortletAction.
134         // Defining build*(Portlet, Context, RunData) fixes the problem but can't expect 
135         // everyone to go back and change all of there Action method signatures just to
136         // fix this.  Eventually we should deprecate this class all together.
137         try
138         {
139             Method method =
140                 this.getClass().getDeclaredMethod(
141                     "buildMaximizedContext",
142                     new Class[] { VelocityPortlet.class, Context.class, RunData.class });
143             method.setAccessible(true);
144             method.invoke(this, new Object[] { portlet, context, data });
145             method.setAccessible(false);
146         }
147         catch (NoSuchMethodException e)
148         {
149             // Subclass did not override this method
150             super.buildMaximizedContext(portlet, context, data);
151         }
152     }
153     
154     /***
155      * prevents possible self-referencing loop when sub-classes invoke super.buildMaximizedContext().
156      * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
157      */
158     protected void buildMaximizedContext(VelocityPortlet portlet, Context context, RunData data)
159         throws Exception
160     {
161     }
162     
163    
164    
165 
166 }