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