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 import org.apache.commons.lang.StringUtils;
20 import org.apache.commons.lang.exception.ExceptionUtils;
21
22 import org.apache.ecs.ConcreteElement;
23
24 import org.apache.velocity.context.Context;
25
26 import org.apache.turbine.Turbine;
27 import org.apache.turbine.TurbineConstants;
28 import org.apache.turbine.services.template.TurbineTemplate;
29 import org.apache.turbine.services.velocity.TurbineVelocity;
30 import org.apache.turbine.util.RunData;
31
32 /***
33 * VelocityDirectScreen is a screen class which returns its output
34 * directly to the output stream. It can be used if buffering an
35 * output screen isn't possible or the result doesn't fit in the
36 * memory.
37 * <p>
38 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
39 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
40 * @version $Id: VelocityDirectScreen.java 264148 2005-08-29 14:21:04Z henning $
41 */
42 public class VelocityDirectScreen
43 extends VelocityScreen
44 {
45 /*** The prefix for lookup up screen pages */
46 private String prefix = TurbineConstants.SCREEN_PREFIX + "/";
47
48 /***
49 * This builds the Velocity template.
50 *
51 * @param data Turbine information.
52 * @return A ConcreteElement.
53 * @exception Exception, a generic exception.
54 */
55 public ConcreteElement buildTemplate(RunData data)
56 throws Exception
57 {
58 Context context = TurbineVelocity.getContext(data);
59
60 String screenTemplate = data.getTemplateInfo().getScreenTemplate();
61 String templateName
62 = TurbineTemplate.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 TurbineVelocity.handleRequest(context,
74 prefix + templateName,
75 data.getOut());
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 = Turbine.getConfiguration()
87 .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
88 TurbineConstants.TEMPLATE_ERROR_VM);
89
90 TurbineVelocity.handleRequest(context,
91 prefix + templateName,
92 data.getOut());
93 }
94
95 return null;
96 }
97 }