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
25 import org.apache.ecs.ConcreteElement;
26
27 import org.apache.velocity.context.Context;
28
29 import org.apache.turbine.Turbine;
30 import org.apache.turbine.TurbineConstants;
31 import org.apache.turbine.services.template.TurbineTemplate;
32 import org.apache.turbine.services.velocity.TurbineVelocity;
33 import org.apache.turbine.util.RunData;
34
35 /***
36 * VelocityDirectScreen is a screen class which returns its output
37 * directly to the output stream. It can be used if buffering an
38 * output screen isn't possible or the result doesn't fit in the
39 * memory.
40 * <p>
41 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
42 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
43 * @version $Id: VelocityDirectScreen.java 534527 2007-05-02 16:10:59Z tv $
44 */
45 public class VelocityDirectScreen
46 extends VelocityScreen
47 {
48 /*** The prefix for lookup up screen pages */
49 private String prefix = TurbineConstants.SCREEN_PREFIX + "/";
50
51 /***
52 * This builds the Velocity template.
53 *
54 * @param data Turbine information.
55 * @return A ConcreteElement.
56 * @exception Exception, a generic exception.
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.getOut());
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.getOut());
96 }
97
98 return null;
99 }
100 }