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