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