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 implements Layout 043{ 044 /** The prefix for lookup up layout pages */ 045 private static final String prefix = PREFIX + "/"; 046 047 /** Injected service instance */ 048 @TurbineService 049 private JspService jspService; 050 051 /** 052 * Method called by LayoutLoader. 053 * 054 * @param pipelineData PipelineData 055 * @throws Exception generic exception 056 */ 057 @Override 058 public void doBuild(PipelineData pipelineData) 059 throws Exception 060 { 061 RunData data = pipelineData.getRunData(); 062 data.getResponse().setContentType( TurbineConstants.DEFAULT_HTML_CONTENT_TYPE ); 063 data.declareDirectResponse(); 064 065 // variable to reference the screen in the layout template 066 data.getRequest() 067 .setAttribute(TurbineConstants.SCREEN_PLACEHOLDER, 068 new JspScreenPlaceholder(data)); 069 070 // variable to reference the navigations in the layout template 071 data.getRequest().setAttribute( 072 TurbineConstants.NAVIGATION_PLACEHOLDER, 073 new JspNavigation(data)); 074 075 // Grab the layout template set in the TemplatePage. 076 String templateName = data.getTemplateInfo().getLayoutTemplate(); 077 078 jspService.handleRequest(pipelineData, prefix + templateName, true); 079 } 080}