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.turbine.TurbineConstants;
25 import org.apache.turbine.pipeline.PipelineData;
26 import org.apache.turbine.util.RunData;
27 import org.apache.velocity.context.Context;
28
29
30
31
32
33
34
35
36
37
38
39
40 public class VelocityDirectScreen
41 extends VelocityScreen
42 {
43
44 private String prefix = getPrefix() + "/";
45
46
47
48
49
50
51
52
53 @Override
54 public String buildTemplate(PipelineData pipelineData)
55 throws Exception
56 {
57 RunData data = getRunData(pipelineData);
58 Context context = velocity.getContext(pipelineData);
59
60 String screenTemplate = data.getTemplateInfo().getScreenTemplate();
61 String templateName
62 = templateService.getScreenTemplateName(screenTemplate);
63
64
65 if (StringUtils.isEmpty(templateName))
66 {
67 log.error("Screen " + screenTemplate + " not found!");
68 throw new Exception("Could not find screen for " + screenTemplate);
69 }
70
71 try
72 {
73 velocity.handleRequest(context,
74 prefix + templateName,
75 data.getResponse().getOutputStream());
76
77 }
78 catch (Exception e)
79 {
80
81
82
83 context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
84 context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));
85
86 templateName = conf.getString(TurbineConstants.TEMPLATE_ERROR_KEY,
87 TurbineConstants.TEMPLATE_ERROR_VM);
88
89 velocity.handleRequest(context,
90 prefix + templateName,
91 data.getResponse().getOutputStream());
92 }
93
94 return null;
95 }
96 }