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.ecs.ConcreteElement;
26
27 import org.apache.turbine.TurbineConstants;
28 import org.apache.turbine.modules.Layout;
29 import org.apache.turbine.modules.ScreenLoader;
30 import org.apache.turbine.services.velocity.TurbineVelocity;
31 import org.apache.turbine.util.RunData;
32 import org.apache.turbine.util.template.TemplateNavigation;
33
34 import org.apache.velocity.context.Context;
35
36 /***
37 * This Layout module allows Velocity templates to be used as layouts.
38 * Since dynamic content is supposed to be primarily located in
39 * screens and navigations there should be relatively few reasons to
40 * subclass this Layout.
41 *
42 * To get the same functionality as with VelocityECSLayout, you can use two
43 * supplied VelocityMacros, TurbineHtmlHead and TurbineHtmlBodyAttributes
44 * in your templates. These are used to put HtmlPageAttributes into a page
45 * before rendering.
46 *
47 * Use these macros should be used in the Layout template like this:
48 *
49 * ... set things like style sheets, scripts here.
50 * <html>
51 * #TurbineHtmlHead()
52 * <body #TurbineHtmlBodyAttributes() >
53 * .... your body information
54 * </body>
55 * </html>
56 *
57 * As the layout template is rendered _after_ the screen template, you
58 * can of course, add information to the $page tool in your screen template.
59 * This will be added correctly to the <head>...</head> and
60 * <body> tags.
61 *
62 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
63 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
64 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
65 * @version $Id: VelocityOnlyLayout.java 534527 2007-05-02 16:10:59Z tv $
66 */
67 public class VelocityOnlyLayout
68 extends Layout
69 {
70 /*** Logging */
71 private static Log log = LogFactory.getLog(VelocityOnlyLayout.class);
72
73 /*** The prefix for lookup up layout pages */
74 private String prefix = TurbineConstants.LAYOUT_PREFIX + "/";
75
76 /***
77 * Build the layout. Also sets the ContentType and Locale headers
78 * of the HttpServletResponse object.
79 *
80 * @param data Turbine information.
81 * @exception Exception a generic exception.
82 */
83 public void doBuild(RunData data)
84 throws Exception
85 {
86
87 Context context = TurbineVelocity.getContext(data);
88
89 String screenName = data.getScreen();
90
91 log.debug("Loading Screen " + screenName);
92
93
94
95 ConcreteElement results =
96 ScreenLoader.getInstance().eval(data, screenName);
97
98 String returnValue = (results == null) ? "" : results.toString();
99
100
101 context.put(TurbineConstants.SCREEN_PLACEHOLDER, returnValue);
102
103
104 context.put(TurbineConstants.NAVIGATION_PLACEHOLDER,
105 new TemplateNavigation(data));
106
107
108
109
110 String templateName = data.getTemplateInfo().getLayoutTemplate();
111
112
113 data.getResponse().setLocale(data.getLocale());
114 data.getResponse().setContentType(data.getContentType());
115
116 log.debug("Now trying to render layout " + templateName);
117
118
119 data.getOut().print(TurbineVelocity
120 .handleRequest(context, prefix + templateName));
121 }
122 }