KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > modules > actions > portlets > HelloAction


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 import org.apache.jetspeed.portal.portlets.VelocityPortlet;
20
21 // Turbine stuff
22
import org.apache.turbine.util.RunData;
23
24 // Velocity Stuff
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 JavaDoc text = (String JavaDoc)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 JavaDoc 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 }
104
Popular Tags