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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.modules.actions.portlets;
181920import java.lang.reflect.Method;
2122import org.apache.jetspeed.portal.Portlet;
23import org.apache.jetspeed.portal.portlets.VelocityPortlet;
242526// Turbine stuff27import org.apache.turbine.util.RunData;
282930// Velocity Stuff31import org.apache.velocity.context.Context;
323334/***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 automatically38 * associated through the registry PortletName39 * <p>40 * <strong>NOTE:</strong>This supports the pre-MVC style of template based 41 * portlet development and is supplied for backward compatibility. It is42 * suggested you use a combination of 43 * @see org.apache.jetspeed.portal.portlets.GenericMVCPortlet along with44 * subclassing @see org.apache.jetspeed.portal.portlets.GenericMVCAction45 * 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 */53publicabstractclassVelocityPortletActionextendsGenericMVCAction54 {
55565758/*** 59 * Subclasses must override this method to provide default behavior 60 * for the portlet action 61 */62protectedabstractvoid buildNormalContext(VelocityPortlet portlet,
63 Context context,
64 RunData rundata)
65 throws Exception;
6667/***68 * STW: Backwards compatibility so the overriden method is called specifically using a cast to VelocityPortlet69 * @see org.apache.jetspeed.portal.portlets.mvc.PortletAction#buildNormalContext(Portlet, Context, RunData)70 */71protectedvoid buildNormalContext(Portlet portlet, Context context, RunData data)
72 throws Exception
73 {
74 buildNormalContext((VelocityPortlet) portlet, context, data);
75 }
7677/***78 * @see org.apache.jetspeed.portal.portlets.mvc.PortletAction#buildConfigureContext(Portlet, Context, RunData)79 */80protectedvoid 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 you84// can commit. However, it was the only to have VelocityPortletAction implement85// GenericMVCAction an still work correctly. The sypmtom we where experiencing86// was that we where skipping over the overriden method in the inheriting class87// 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 to93// fix this. Eventually we should deprecate this class all together.94try95 {
96 Method method =
97this.getClass().getDeclaredMethod(
98"buildConfigureContext",
99new Class[] { VelocityPortlet.class, Context.class, RunData.class });
100 method.setAccessible(true);
101 method.invoke(this, new Object[] { portlet, context, data });
102 method.setAccessible(false);
103104 }
105catch (NoSuchMethodException e)
106 {
107// Subclass did not override this method108super.buildConfigureContext(portlet, context, data);
109 }
110111 }
112113/***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 */117protectedvoid buildConfigureContext(VelocityPortlet portlet, Context context, RunData data)
118 throws Exception
119 {
120 }
121122123protectedvoid 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 you127// can commit. However, it was the only to have VelocityPortletAction implement128// GenericMVCAction an still work correctly. The sypmtom we where experiencing129// was that we where skipping over the overriden method in the inheriting class130// 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 to136// fix this. Eventually we should deprecate this class all together.137try138 {
139 Method method =
140this.getClass().getDeclaredMethod(
141"buildMaximizedContext",
142new 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 }
147catch (NoSuchMethodException e)
148 {
149// Subclass did not override this method150super.buildMaximizedContext(portlet, context, data);
151 }
152 }
153154/***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 */158protectedvoid buildMaximizedContext(VelocityPortlet portlet, Context context, RunData data)
159 throws Exception
160 {
161 }
162163164165166 }