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;
1819import org.apache.jetspeed.portal.portlets.VelocityPortlet;
2021// Turbine stuff22import org.apache.turbine.util.RunData;
2324// Velocity Stuff25import org.apache.velocity.context.Context;
262728/***29 * An abstract action class to build VelocityPortlet actions.30 * 31 * <p>Don't call it from the URL, the Portlet and the Action are automatically32 * associated through the registry PortletName33 * 34 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>35 */36publicclassHelloActionextendsVelocityPortletAction37 {
3839/*** 40 * Subclasses should override this method if they wish to41 * build specific content when maximized. Default behavior is42 * to do the same as normal content.43 */44protectedvoid buildMaximizedContext( VelocityPortlet portlet,
45 Context context,
46 RunData rundata )
47 {
48 buildNormalContext( portlet, context, rundata);
4950 String text = (String)context.get("text");
5152if (text == null)
53 {
54 text = "Hello World ";
55 }
5657 context.put("text", text+" (Maximized !)");
58 }
5960/*** 61 * Subclasses should override this method if they wish to62 * provide their own customization behavior.63 * Default is to use Portal base customizer action64 */65protectedvoid buildConfigureContext( VelocityPortlet portlet,
66 Context context,
67 RunData rundata )
68 {
6970 buildNormalContext( portlet, context, rundata);
7172 setTemplate(rundata, "hello-customize");
7374 }
7576/*** 77 * Subclasses must override this method to provide default behavior 78 * for the portlet action79 */80protectedvoid buildNormalContext( VelocityPortlet portlet,
81 Context context,
82 RunData rundata )
83 {
84 context.put("text",portlet.getPortletConfig().getInitParameter("text"));
85 }
8687publicvoid doUpdate(RunData data, Context context)
88 {
89 String text = data.getParameters().getString("text");
9091if (text!=null)
92 {
93VelocityPortlet portlet = (VelocityPortlet)context.get("portlet");
94 portlet.setAttribute("text",text,data);
95 context.put("text",text);
96 context.put("message", "Text successfully updated");
97 }
98else99 {
100 context.put("message", "You must specify a new text");
101 }
102 }
103 }