KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > portlets > VTLPortlet


1 package org.apache.jetspeed.portal.portlets;
2
3 // Turbine stuff
4
import org.apache.turbine.util.RunData;
5 import org.apache.turbine.services.velocity.TurbineVelocity;
6 import org.apache.turbine.modules.ActionLoader;
7
8 // Jetspeed stuff
9
import org.apache.jetspeed.portal.Portlet;
10 import org.apache.jetspeed.portal.portlets.AbstractPortlet;
11 import org.apache.jetspeed.portal.PortletException;
12
13 // Ecs stuff
14
import org.apache.ecs.ConcreteElement;
15 import org.apache.ecs.StringElement;
16
17 // Velocity Stuff
18
import org.apache.velocity.context.Context;
19
20 import org.apache.turbine.util.Log;
21
22
23 /**
24 An implementation of AbstractVTLPortlet.
25
26 you need lines like this in jetspeed-config.jcfg:
27
28     <portlet-registry>
29
30         <portlet-entry type="abstract" name="VTLPortlet">
31             <classname>org.apache.jetspeed.portal.portlets.VTLPortlet</classname>
32          </portlet-entry>
33
34         <portlet-entry type="ref" name="Hello" parent="VTLPortlet">
35             <parameter name="vtlTemplate" value="HelloPortlet"/>
36             <meta-info>
37                 <title>Hello</title>
38                 <description>Hello portlet</description>
39             </meta-info>
40         </portlet-entry>
41
42     </portlet-registry>
43
44 Basically a VTLPortlet is this file, an action, and a template
45
46 @author <a HREF="mailto:re_carrasco@bco011.sonda.cl">Roberto Carrasco</a>
47 */

48 public class VTLPortlet extends AbstractVTLPortlet
49 {
50     public ConcreteElement getContent( RunData rundata )
51     {
52         // get the template name from the URL ( or from jetspeed-config.jcfg (
53
String JavaDoc template = rundata.getParameters().getString ( "vtlTemplate", null );
54         if( template == null )
55         {
56             template = this.getPortletConfig().getInitParameter( "vtlTemplate" );
57         }
58
59         // make a blank context and put some data
60
Context context = TurbineVelocity.getContext();
61         context.put( "portlet", this );
62         context.put( "vtlTemplate", template );
63         rundata.getTemplateInfo().setTemplateContext( "VTLPortletContext", context );
64
65         // if there is an action with the same name in modules/actions/portlets exec it
66
// The action processes max/min/conf/restore/close buttons
67
try
68         {
69             ActionLoader.getInstance().exec( rundata, "portlets." + template.replace(',', '.') );
70         }
71         catch( Exception JavaDoc e)
72         {
73            //Log.error( e.toString() );
74
}
75  
76         // don't make content if portlet is minimized
77
String JavaDoc s = "";
78         if( isButtonMaximize( rundata ) || isButtonConfigure( rundata ) || !isMinimized( rundata ) )
79         {
80             // may be the action changed the template
81
template = ( (String JavaDoc)context.get( "vtlTemplate" ) ).replace(',', '/');
82
83             // generate the content
84
try
85             {
86                 s = TurbineVelocity.handleRequest(context, "portlets/" + template + ".vm");
87             }
88             catch( Exception JavaDoc e)
89             {
90                 s= e.toString();
91             }
92         }
93
94         return new StringElement( s );
95     }
96
97
98 }
99
100
Popular Tags