KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > modules > layouts > VelocityECSLayout


1 package org.apache.turbine.modules.layouts;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
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,v 1.12.2.2 2004/05/20 03:03:54 seade Exp $
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 JavaDoc 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 JavaDoc
81     {
82         // Get the context needed by Velocity.
83
Context context = TurbineVelocity.getContext(data);
84
85         String JavaDoc screenName = data.getScreen();
86
87         log.debug("Loading Screen " + screenName);
88
89         // First, generate the screen and put it in the context so
90
// we can grab it the layout template.
91
ConcreteElement results =
92             ScreenLoader.getInstance().eval(data, screenName);
93
94         String JavaDoc returnValue = (results == null) ? "" : results.toString();
95
96         // variable for the screen in the layout template
97
context.put(TurbineConstants.SCREEN_PLACEHOLDER, returnValue);
98
99         // variable to reference the navigation screen in the layout template
100
context.put(TurbineConstants.NAVIGATION_PLACEHOLDER,
101                     new TemplateNavigation(data));
102
103         // Grab the layout template set in the VelocityPage.
104
// If null, then use the default layout template
105
// (done by the TemplateInfo object)
106
String JavaDoc templateName = data.getTemplateInfo().getLayoutTemplate();
107
108         log.debug("Now trying to render layout " + templateName);
109
110         // Finally, generate the layout template and add it to the body of the
111
// Document in the RunData.
112
data.getPage().getBody().addElement(TurbineVelocity
113                 .handleRequest(context, prefix + templateName));
114     }
115 }
116
Popular Tags