View Javadoc

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