001 package 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 024 import org.apache.turbine.TurbineConstants; 025 import org.apache.turbine.modules.Layout; 026 import org.apache.turbine.pipeline.PipelineData; 027 import org.apache.turbine.services.jsp.TurbineJsp; 028 import org.apache.turbine.services.jsp.util.JspNavigation; 029 import org.apache.turbine.services.jsp.util.JspScreenPlaceholder; 030 import org.apache.turbine.util.RunData; 031 032 /** 033 * This Layout module allows JSP templates to be used as layouts. Since 034 * dynamic content is supposed to be primarily located in screens and 035 * navigations there should be relatively few reasons to subclass this Layout. 036 * 037 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> 038 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 039 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 040 */ 041 public class JspLayout 042 extends Layout 043 { 044 /** The prefix for lookup up layout pages */ 045 private String prefix = Layout.PREFIX + "/"; 046 047 /** 048 * Method called by LayoutLoader. 049 * 050 * @deprecated Use PipelineData version instead. 051 * @param data RunData 052 * @throws Exception generic exception 053 */ 054 @Deprecated 055 @Override 056 public void doBuild(RunData data) 057 throws Exception 058 { 059 data.getResponse().setContentType("text/html"); 060 data.declareDirectResponse(); 061 062 // variable to reference the screen in the layout template 063 data.getRequest() 064 .setAttribute(TurbineConstants.SCREEN_PLACEHOLDER, 065 new JspScreenPlaceholder(data)); 066 067 // variable to reference the navigations in the layout template 068 data.getRequest().setAttribute( 069 TurbineConstants.NAVIGATION_PLACEHOLDER, 070 new JspNavigation(data)); 071 072 // Grab the layout template set in the TemplatePage. 073 String templateName = data.getTemplateInfo().getLayoutTemplate(); 074 075 TurbineJsp.handleRequest(data, prefix + templateName, true); 076 } 077 078 /** 079 * Method called by LayoutLoader. 080 * 081 * @param data PipelineData 082 * @throws Exception generic exception 083 */ 084 @Override 085 public void doBuild(PipelineData pipelineData) 086 throws Exception 087 { 088 RunData data = getRunData(pipelineData); 089 data.getResponse().setContentType("text/html"); 090 data.declareDirectResponse(); 091 092 // variable to reference the screen in the layout template 093 data.getRequest() 094 .setAttribute(TurbineConstants.SCREEN_PLACEHOLDER, 095 new JspScreenPlaceholder(data)); 096 097 // variable to reference the navigations in the layout template 098 data.getRequest().setAttribute( 099 TurbineConstants.NAVIGATION_PLACEHOLDER, 100 new JspNavigation(data)); 101 102 // Grab the layout template set in the TemplatePage. 103 String templateName = data.getTemplateInfo().getLayoutTemplate(); 104 105 TurbineJsp.handleRequest(pipelineData, prefix + templateName, true); 106 } 107 108 }