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