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 * This class uses ECS to render the layout.
40 *
41 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
42 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
43 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
44 * @version $Id: VelocityECSLayout.java 264148 2005-08-29 14:21:04Z henning $
45 * @deprecated you should use VelocityOnlyLayout
46 */
47 public class VelocityECSLayout
48 extends Layout
49 {
50 /*** Logging */
51 private static Log log = LogFactory.getLog(VelocityECSLayout.class);
52
53 /*** The prefix for lookup up layout pages */
54 private String prefix = TurbineConstants.LAYOUT_PREFIX + "/";
55
56 /*** Warn only once */
57 private static boolean hasWarned = false;
58
59 /***
60 * C'tor warns once about deprecation.
61 */
62 public VelocityECSLayout()
63 {
64 if (!hasWarned)
65 {
66 log.warn("The VelocityECSLayout is deprecated. "
67 + "Please switch to VelocityOnlyLayout.");
68 hasWarned = true;
69 }
70 }
71
72 /***
73 * Build the layout. Also sets the ContentType and Locale headers
74 * of the HttpServletResponse object.
75 *
76 * @param data Turbine information.
77 * @exception Exception a generic exception.
78 */
79 public void doBuild(RunData data)
80 throws Exception
81 {
82
83 Context context = TurbineVelocity.getContext(data);
84
85 String screenName = data.getScreen();
86
87 log.debug("Loading Screen " + screenName);
88
89
90
91 ConcreteElement results =
92 ScreenLoader.getInstance().eval(data, screenName);
93
94 String returnValue = (results == null) ? "" : results.toString();
95
96
97 context.put(TurbineConstants.SCREEN_PLACEHOLDER, returnValue);
98
99
100 context.put(TurbineConstants.NAVIGATION_PLACEHOLDER,
101 new TemplateNavigation(data));
102
103
104
105
106 String templateName = data.getTemplateInfo().getLayoutTemplate();
107
108 log.debug("Now trying to render layout " + templateName);
109
110
111
112 data.getPage().getBody().addElement(TurbineVelocity
113 .handleRequest(context, prefix + templateName));
114 }
115 }