1 package org.apache.turbine.modules.screens;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.commons.lang.exception.ExceptionUtils;
24 import org.apache.ecs.ConcreteElement;
25 import org.apache.ecs.StringElement;
26 import org.apache.turbine.Turbine;
27 import org.apache.turbine.TurbineConstants;
28 import org.apache.turbine.pipeline.PipelineData;
29 import org.apache.turbine.services.template.TurbineTemplate;
30 import org.apache.turbine.services.velocity.TurbineVelocity;
31 import org.apache.turbine.util.RunData;
32 import org.apache.velocity.context.Context;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class VelocityScreen
50 extends TemplateScreen
51 {
52
53 private final String prefix = getPrefix() + "/";
54
55
56
57
58
59
60
61
62
63
64
65 @Deprecated
66 protected void doBuildTemplate(RunData data,
67 Context context)
68 throws Exception
69 {
70
71 }
72
73
74
75
76
77
78
79
80
81
82 protected void doBuildTemplate(PipelineData pipelineData,
83 Context context)
84 throws Exception
85 {
86
87 }
88
89
90
91
92
93
94
95
96
97
98
99 @Deprecated
100 @Override
101 protected void doBuildTemplate(RunData data)
102 throws Exception
103 {
104 doBuildTemplate(data, TurbineVelocity.getContext(data));
105 }
106
107
108
109
110
111
112
113
114
115 @Override
116 protected void doBuildTemplate(PipelineData pipelineData)
117 throws Exception
118 {
119 doBuildTemplate(pipelineData, TurbineVelocity.getContext(pipelineData));
120 }
121
122
123
124
125
126
127
128
129
130
131
132 @Deprecated
133 @Override
134 public ConcreteElement buildTemplate(RunData data)
135 throws Exception
136 {
137 String screenData = null;
138
139 Context context = TurbineVelocity.getContext(data);
140
141 String screenTemplate = data.getTemplateInfo().getScreenTemplate();
142 String templateName
143 = TurbineTemplate.getScreenTemplateName(screenTemplate);
144
145
146 if (StringUtils.isEmpty(templateName))
147 {
148 log.error("Screen " + screenTemplate + " not found!");
149 throw new Exception("Could not find screen for " + screenTemplate);
150 }
151
152 try
153 {
154
155
156 if (getLayout(data) == null)
157 {
158 TurbineVelocity.handleRequest(context,
159 prefix + templateName,
160 data.getResponse().getOutputStream());
161 }
162 else
163 {
164 screenData = TurbineVelocity
165 .handleRequest(context, prefix + templateName);
166 }
167 }
168 catch (Exception e)
169 {
170
171
172
173 context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
174 context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));
175
176 templateName = Turbine.getConfiguration()
177 .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
178 TurbineConstants.TEMPLATE_ERROR_VM);
179
180 screenData = TurbineVelocity.handleRequest(
181 context, prefix + templateName);
182 }
183
184
185 StringElement output = new StringElement();
186 output.setFilterState(false);
187
188 if (screenData != null)
189 {
190 output.addElement(screenData);
191 }
192 return output;
193 }
194
195
196
197
198
199
200
201
202 @Override
203 public ConcreteElement buildTemplate(PipelineData pipelineData)
204 throws Exception
205 {
206 RunData data = getRunData(pipelineData);
207 String screenData = null;
208
209 Context context = TurbineVelocity.getContext(pipelineData);
210
211 String screenTemplate = data.getTemplateInfo().getScreenTemplate();
212 String templateName
213 = TurbineTemplate.getScreenTemplateName(screenTemplate);
214
215
216 if (StringUtils.isEmpty(templateName))
217 {
218 log.error("Screen " + screenTemplate + " not found!");
219 throw new Exception("Could not find screen for " + screenTemplate);
220 }
221
222 try
223 {
224
225
226 if (getLayout(pipelineData) == null)
227 {
228 TurbineVelocity.handleRequest(context,
229 prefix + templateName,
230 data.getResponse().getOutputStream());
231 }
232 else
233 {
234 screenData = TurbineVelocity
235 .handleRequest(context, prefix + templateName);
236 }
237 }
238 catch (Exception e)
239 {
240
241
242
243 context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
244 context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));
245
246 templateName = Turbine.getConfiguration()
247 .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
248 TurbineConstants.TEMPLATE_ERROR_VM);
249
250 screenData = TurbineVelocity.handleRequest(
251 context, prefix + templateName);
252 }
253
254
255 StringElement output = new StringElement();
256 output.setFilterState(false);
257
258 if (screenData != null)
259 {
260 output.addElement(screenData);
261 }
262 return output;
263 }
264
265
266
267
268
269
270
271
272
273
274 @Deprecated
275 public static Context getContext(RunData data)
276 {
277 return TurbineVelocity.getContext(data);
278 }
279
280
281
282
283
284
285
286
287
288 @Deprecated
289 public static Context getContext(PipelineData pipelineData)
290 {
291 return TurbineVelocity.getContext(pipelineData);
292 }
293
294 }