1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portal.controllers;
18
19
20 import org.apache.turbine.modules.ActionLoader;
21 import org.apache.turbine.services.velocity.TurbineVelocity;
22 import org.apache.turbine.services.pull.TurbinePull;
23 import org.apache.turbine.util.RunData;
24
25
26 import org.apache.jetspeed.services.TemplateLocator;
27 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
28 import org.apache.jetspeed.services.logging.JetspeedLogger;
29
30
31 import org.apache.ecs.ConcreteElement;
32 import org.apache.ecs.StringElement;
33
34
35 import org.apache.velocity.context.Context;
36
37 /***
38 * A Velocity based portlet controller implementation
39 *
40 * @author <a href="mailto:re_carrasco@bco011.sonda.cl">Roberto Carrasco</a>
41 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>
42 *
43 * @version $Id: VelocityPortletController.java,v 1.12 2004/02/23 03:25:06 jford Exp $
44 */
45 public class VelocityPortletController extends AbstractPortletController
46 {
47
48 /***
49 * Static initialization of the logger for this class
50 */
51 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(VelocityPortletController.class.getName());
52
53 public ConcreteElement getContent( RunData rundata )
54 {
55
56
57 Context context = TurbineVelocity.getContext();
58
59 context.put( "data", rundata );
60 context.put( "controller", this );
61 context.put( "portlets", this.getPortlets().toArray() );
62 context.put( "config", this.getConfig() );
63 context.put( "skin", this.getPortlets().getPortletConfig().getPortletSkin() );
64 context.put( "template", getConfig().getInitParameter("template") );
65
66
67 TurbinePull.populateContext(context, rundata);
68
69
70 buildContext(rundata, context);
71
72 String actionName = getConfig().getInitParameter("action");
73
74 if (actionName != null)
75 {
76
77 rundata.getTemplateInfo().setTemplateContext( "VelocityControllerContext", context );
78
79
80 try
81 {
82 ActionLoader.getInstance().exec( rundata, actionName );
83 }
84 catch( Exception e)
85 {
86 logger.error("Exception", e);
87 }
88 }
89
90
91
92 String template = (String)context.get( "template" );
93
94
95 String s = "";
96
97 try
98 {
99 if (-1 == template.indexOf(".vm"))
100 {
101 template = template + ".vm";
102 }
103
104 String templatePath = TemplateLocator.locateControllerTemplate(rundata, template);
105 TurbineVelocity.handleRequest(context, templatePath, rundata.getOut());
106 }
107 catch( Exception e)
108 {
109 logger.error( "Error generating content: ", e );
110 s= e.toString();
111 }
112
113 TurbineVelocity.requestFinished(context);
114
115 return new StringElement( s );
116 }
117
118 public void buildContext(RunData data, Context context)
119 {
120
121 }
122 }
123