1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.modules.actions.portlets;
18
19 import org.apache.jetspeed.portal.portlets.VelocityPortlet;
20
21
22 import org.apache.turbine.util.RunData;
23
24
25 import org.apache.velocity.context.Context;
26
27
28 /***
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 automatically
32 * associated through the registry PortletName
33 *
34 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>
35 */
36 public class HelloAction extends VelocityPortletAction
37 {
38
39 /***
40 * Subclasses should override this method if they wish to
41 * build specific content when maximized. Default behavior is
42 * to do the same as normal content.
43 */
44 protected void buildMaximizedContext( VelocityPortlet portlet,
45 Context context,
46 RunData rundata )
47 {
48 buildNormalContext( portlet, context, rundata);
49
50 String text = (String)context.get("text");
51
52 if (text == null)
53 {
54 text = "Hello World ";
55 }
56
57 context.put("text", text+" (Maximized !)");
58 }
59
60 /***
61 * Subclasses should override this method if they wish to
62 * provide their own customization behavior.
63 * Default is to use Portal base customizer action
64 */
65 protected void buildConfigureContext( VelocityPortlet portlet,
66 Context context,
67 RunData rundata )
68 {
69
70 buildNormalContext( portlet, context, rundata);
71
72 setTemplate(rundata, "hello-customize");
73
74 }
75
76 /***
77 * Subclasses must override this method to provide default behavior
78 * for the portlet action
79 */
80 protected void buildNormalContext( VelocityPortlet portlet,
81 Context context,
82 RunData rundata )
83 {
84 context.put("text",portlet.getPortletConfig().getInitParameter("text"));
85 }
86
87 public void doUpdate(RunData data, Context context)
88 {
89 String text = data.getParameters().getString("text");
90
91 if (text!=null)
92 {
93 VelocityPortlet portlet = (VelocityPortlet)context.get("portlet");
94 portlet.setAttribute("text",text,data);
95 context.put("text",text);
96 context.put("message", "Text successfully updated");
97 }
98 else
99 {
100 context.put("message", "You must specify a new text");
101 }
102 }
103 }