001: package org.apache.turbine.modules.layouts;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import org.apache.ecs.ConcreteElement;
026:
027: import org.apache.turbine.TurbineConstants;
028: import org.apache.turbine.modules.Layout;
029: import org.apache.turbine.modules.ScreenLoader;
030: import org.apache.turbine.services.velocity.TurbineVelocity;
031: import org.apache.turbine.util.RunData;
032: import org.apache.turbine.util.template.TemplateNavigation;
033:
034: import org.apache.velocity.context.Context;
035:
036: /**
037: * This Layout module allows Velocity templates to be used as layouts.
038: * Since dynamic content is supposed to be primarily located in
039: * screens and navigations there should be relatively few reasons to
040: * subclass this Layout.
041: *
042: * This class uses ECS to render the layout.
043: *
044: * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
045: * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
046: * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
047: * @version $Id: VelocityECSLayout.java 534527 2007-05-02 16:10:59Z tv $
048: * @deprecated you should use VelocityOnlyLayout
049: */
050: public class VelocityECSLayout extends Layout {
051: /** Logging */
052: private static Log log = LogFactory.getLog(VelocityECSLayout.class);
053:
054: /** The prefix for lookup up layout pages */
055: private String prefix = TurbineConstants.LAYOUT_PREFIX + "/";
056:
057: /** Warn only once */
058: private static boolean hasWarned = false;
059:
060: /**
061: * C'tor warns once about deprecation.
062: */
063: public VelocityECSLayout() {
064: if (!hasWarned) {
065: log.warn("The VelocityECSLayout is deprecated. "
066: + "Please switch to VelocityOnlyLayout.");
067: hasWarned = true;
068: }
069: }
070:
071: /**
072: * Build the layout. Also sets the ContentType and Locale headers
073: * of the HttpServletResponse object.
074: *
075: * @param data Turbine information.
076: * @exception Exception a generic exception.
077: */
078: public void doBuild(RunData data) throws Exception {
079: // Get the context needed by Velocity.
080: Context context = TurbineVelocity.getContext(data);
081:
082: String screenName = data.getScreen();
083:
084: log.debug("Loading Screen " + screenName);
085:
086: // First, generate the screen and put it in the context so
087: // we can grab it the layout template.
088: ConcreteElement results = ScreenLoader.getInstance().eval(data,
089: screenName);
090:
091: String returnValue = (results == null) ? "" : results
092: .toString();
093:
094: // variable for the screen in the layout template
095: context.put(TurbineConstants.SCREEN_PLACEHOLDER, returnValue);
096:
097: // variable to reference the navigation screen in the layout template
098: context.put(TurbineConstants.NAVIGATION_PLACEHOLDER,
099: new TemplateNavigation(data));
100:
101: // Grab the layout template set in the VelocityPage.
102: // If null, then use the default layout template
103: // (done by the TemplateInfo object)
104: String templateName = data.getTemplateInfo()
105: .getLayoutTemplate();
106:
107: log.debug("Now trying to render layout " + templateName);
108:
109: // Finally, generate the layout template and add it to the body of the
110: // Document in the RunData.
111: data.getPage().getBody().addElement(
112: TurbineVelocity.handleRequest(context, prefix
113: + templateName));
114: }
115: }
|