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.turbine.Turbine;
26 import org.apache.turbine.TurbineConstants;
27 import org.apache.turbine.pipeline.PipelineData;
28 import org.apache.turbine.services.template.TurbineTemplate;
29 import org.apache.turbine.services.velocity.TurbineVelocity;
30 import org.apache.turbine.util.RunData;
31 import org.apache.velocity.context.Context;
32
33
34
35
36
37
38
39
40
41
42
43
44 public class VelocityDirectScreen
45 extends VelocityScreen
46 {
47
48 private String prefix = getPrefix() + "/";
49
50
51
52
53
54
55
56
57
58 public ConcreteElement buildTemplate(RunData data)
59 throws Exception
60 {
61 Context context = TurbineVelocity.getContext(data);
62
63 String screenTemplate = data.getTemplateInfo().getScreenTemplate();
64 String templateName
65 = TurbineTemplate.getScreenTemplateName(screenTemplate);
66
67
68 if (StringUtils.isEmpty(templateName))
69 {
70 log.error("Screen " + screenTemplate + " not found!");
71 throw new Exception("Could not find screen for " + screenTemplate);
72 }
73
74 try
75 {
76 TurbineVelocity.handleRequest(context,
77 prefix + templateName,
78 data.getResponse().getOutputStream());
79
80 }
81 catch (Exception e)
82 {
83
84
85
86 context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
87 context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));
88
89 templateName = Turbine.getConfiguration()
90 .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
91 TurbineConstants.TEMPLATE_ERROR_VM);
92
93 TurbineVelocity.handleRequest(context,
94 prefix + templateName,
95 data.getResponse().getOutputStream());
96 }
97
98 return null;
99 }
100
101
102
103
104
105
106
107
108 public ConcreteElement buildTemplate(PipelineData pipelineData)
109 throws Exception
110 {
111 RunData data = getRunData(pipelineData);
112 Context context = TurbineVelocity.getContext(pipelineData);
113
114 String screenTemplate = data.getTemplateInfo().getScreenTemplate();
115 String templateName
116 = TurbineTemplate.getScreenTemplateName(screenTemplate);
117
118
119 if (StringUtils.isEmpty(templateName))
120 {
121 log.error("Screen " + screenTemplate + " not found!");
122 throw new Exception("Could not find screen for " + screenTemplate);
123 }
124
125 try
126 {
127 TurbineVelocity.handleRequest(context,
128 prefix + templateName,
129 data.getResponse().getOutputStream());
130
131 }
132 catch (Exception e)
133 {
134
135
136
137 context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
138 context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));
139
140 templateName = Turbine.getConfiguration()
141 .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
142 TurbineConstants.TEMPLATE_ERROR_VM);
143
144 TurbineVelocity.handleRequest(context,
145 prefix + templateName,
146 data.getResponse().getOutputStream());
147 }
148
149 return null;
150 }
151 }