1 package org.apache.turbine.modules.layouts;
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.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 import org.apache.turbine.TurbineConstants;
26 import org.apache.turbine.modules.Layout;
27 import org.apache.turbine.services.velocity.TurbineVelocity;
28 import org.apache.turbine.util.RunData;
29 import org.apache.turbine.util.template.TemplateNavigation;
30 import org.apache.turbine.util.template.TemplateScreen;
31
32 import org.apache.velocity.context.Context;
33
34 /***
35 * This Layout module allows Velocity templates
36 * to be used as layouts. It will stream directly the output of
37 * the layout and navigation templates to the output writer without
38 * using a screen. Use this if you have a large page to output
39 * and won't buffer it in the memory.
40 *
41 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>
42 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
43 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
44 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
45 * @version $Id: VelocityDirectLayout.java 534527 2007-05-02 16:10:59Z tv $
46 */
47 public class VelocityDirectLayout
48 extends Layout
49 {
50 /*** Logging */
51 private static Log log = LogFactory.getLog(VelocityDirectLayout.class);
52
53 /*** The prefix for lookup up layout pages */
54 private String prefix = TurbineConstants.LAYOUT_PREFIX + "/";
55
56 /***
57 * Method called by LayoutLoader.
58 *
59 * @param data Turbine information.
60 * @exception Exception a generic exception.
61 */
62 public void doBuild(RunData data)
63 throws Exception
64 {
65
66 Context context = TurbineVelocity.getContext(data);
67
68
69 context.put(TurbineConstants.SCREEN_PLACEHOLDER,
70 new TemplateScreen(data));
71
72
73 context.put(TurbineConstants.NAVIGATION_PLACEHOLDER,
74 new TemplateNavigation(data));
75
76
77
78
79 String templateName = data.getTemplateInfo().getLayoutTemplate();
80
81
82 data.getResponse().setLocale(data.getLocale());
83 data.getResponse().setContentType(data.getContentType());
84
85 log.debug("Now trying to render layout " + templateName);
86
87
88 TurbineVelocity.handleRequest(context,
89 prefix + templateName, data.getOut());
90 }
91 }