    001package org.apache.turbine.modules.layouts;
    002
    003
    004/*
    005 * Licensed to the Apache Software Foundation (ASF) under one
    006 * or more contributor license agreements.  See the NOTICE file
    007 * distributed with this work for additional information
    008 * regarding copyright ownership.  The ASF licenses this file
    009 * to you under the Apache License, Version 2.0 (the
    010 * "License"); you may not use this file except in compliance
    011 * with the License.  You may obtain a copy of the License at
    012 *
    013 *   http://www.apache.org/licenses/LICENSE-2.0
    014 *
    015 * Unless required by applicable law or agreed to in writing,
    016 * software distributed under the License is distributed on an
    017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    018 * KIND, either express or implied.  See the License for the
    019 * specific language governing permissions and limitations
    020 * under the License.
    021 */
    022
    023
    024import org.apache.turbine.TurbineConstants;
    025import org.apache.turbine.annotation.TurbineService;
    026import org.apache.turbine.modules.Layout;
    027import org.apache.turbine.pipeline.PipelineData;
    028import org.apache.turbine.services.jsp.JspService;
    029import org.apache.turbine.services.jsp.util.JspNavigation;
    030import org.apache.turbine.services.jsp.util.JspScreenPlaceholder;
    031import org.apache.turbine.util.RunData;
    032
    033/**
    034 * This Layout module allows JSP templates to be used as layouts. Since
    035 * dynamic content is supposed to be primarily located in screens and
    036 * navigations there should be relatively few reasons to subclass this Layout.
    037 *
    038 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
    039 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    040 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    041 */
    042public class JspLayout
    043    extends Layout
    044{
    045    /** The prefix for lookup up layout pages */
    046    private String prefix = Layout.PREFIX + "/";
    047
    048    /** Injected service instance */
    049    @TurbineService
    050    private JspService jspService;
    051
    052    /**
    053     * Method called by LayoutLoader.
    054     *
    055     * @param pipelineData PipelineData
    056     * @throws Exception generic exception
    057     */
    058    @Override
    059    public void doBuild(PipelineData pipelineData)
    060        throws Exception
    061    {
    062        RunData data = getRunData(pipelineData);
    063        data.getResponse().setContentType("text/html");
    064        data.declareDirectResponse();
    065
    066        // variable to reference the screen in the layout template
    067        data.getRequest()
    068            .setAttribute(TurbineConstants.SCREEN_PLACEHOLDER,
    069                          new JspScreenPlaceholder(data));
    070
    071        // variable to reference the navigations in the layout template
    072        data.getRequest().setAttribute(
    073            TurbineConstants.NAVIGATION_PLACEHOLDER,
    074            new JspNavigation(data));
    075
    076        // Grab the layout template set in the TemplatePage.
    077        String templateName = data.getTemplateInfo().getLayoutTemplate();
    078
    079        jspService.handleRequest(pipelineData, prefix + templateName, true);
    080    }
    081}