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 implements Layout
43 {
44 /** The prefix for lookup up layout pages */
45 private static final String prefix = PREFIX + "/";
46
47 /** Injected service instance */
48 @TurbineService
49 private JspService jspService;
50
51 /**
52 * Method called by LayoutLoader.
53 *
54 * @param pipelineData PipelineData
55 * @throws Exception generic exception
56 */
57 @Override
58 public void doBuild(PipelineData pipelineData)
59 throws Exception
60 {
61 RunData data = pipelineData.getRunData();
62 data.getResponse().setContentType( TurbineConstants.DEFAULT_HTML_CONTENT_TYPE );
63 data.declareDirectResponse();
64
65 // variable to reference the screen in the layout template
66 data.getRequest()
67 .setAttribute(TurbineConstants.SCREEN_PLACEHOLDER,
68 new JspScreenPlaceholder(data));
69
70 // variable to reference the navigations in the layout template
71 data.getRequest().setAttribute(
72 TurbineConstants.NAVIGATION_PLACEHOLDER,
73 new JspNavigation(data));
74
75 // Grab the layout template set in the TemplatePage.
76 String templateName = data.getTemplateInfo().getLayoutTemplate();
77
78 jspService.handleRequest(pipelineData, prefix + templateName, true);
79 }
80 }