View Javadoc

    1   package org.apache.turbine.modules.layouts;
    2
    3
    4   /*
    5    * Licensed to the Apache Software Foundation (ASF) under one
    6    * or more contributor license agreements.  See the NOTICE file
    7    * distributed with this work for additional information
    8    * regarding copyright ownership.  The ASF licenses this file
    9    * to you under the Apache License, Version 2.0 (the
    10   * "License"); you may not use this file except in compliance
    11   * with the License.  You may obtain a copy of the License at
    12   *
    13   *   http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing,
    16   * software distributed under the License is distributed on an
    17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    18   * KIND, either express or implied.  See the License for the
    19   * specific language governing permissions and limitations
    20   * under the License.
    21   */
    22
    23
    24  import org.apache.turbine.TurbineConstants;
    25  import org.apache.turbine.annotation.TurbineService;
    26  import org.apache.turbine.modules.Layout;
    27  import org.apache.turbine.pipeline.PipelineData;
    28  import org.apache.turbine.services.jsp.JspService;
    29  import org.apache.turbine.services.jsp.util.JspNavigation;
    30  import org.apache.turbine.services.jsp.util.JspScreenPlaceholder;
    31  import org.apache.turbine.util.RunData;
    32
    33  /**
    34   * This Layout module allows JSP templates to be used as layouts. Since
    35   * dynamic content is supposed to be primarily located in screens and
    36   * navigations there should be relatively few reasons to subclass this Layout.
    37   *
    38   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
    39   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    40   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    41   */
    42  public class JspLayout
    43      extends Layout
    44  {
    45      /** The prefix for lookup up layout pages */
    46      private String prefix = Layout.PREFIX + "/";
    47
    48      /** Injected service instance */
    49      @TurbineService
    50      private JspService jspService;
    51
    52      /**
    53       * Method called by LayoutLoader.
    54       *
    55       * @param pipelineData PipelineData
    56       * @throws Exception generic exception
    57       */
    58      @Override
    59      public void doBuild(PipelineData pipelineData)
    60          throws Exception
    61      {
    62          RunData data = getRunData(pipelineData);
    63          data.getResponse().setContentType("text/html");
    64          data.declareDirectResponse();
    65
    66          // variable to reference the screen in the layout template
    67          data.getRequest()
    68              .setAttribute(TurbineConstants.SCREEN_PLACEHOLDER,
    69                            new JspScreenPlaceholder(data));
    70
    71          // variable to reference the navigations in the layout template
    72          data.getRequest().setAttribute(
    73              TurbineConstants.NAVIGATION_PLACEHOLDER,
    74              new JspNavigation(data));
    75
    76          // Grab the layout template set in the TemplatePage.
    77          String templateName = data.getTemplateInfo().getLayoutTemplate();
    78
    79          jspService.handleRequest(pipelineData, prefix + templateName, true);
    80      }
    81  }