1/*2 * Copyright 2000-2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16packageorg.apache.jetspeed.modules.layouts;
1718// Jetspeed imports19import org.apache.jetspeed.services.TemplateLocator;
20import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
21import org.apache.jetspeed.services.logging.JetspeedLogger;
2223//Turbine imports24import org.apache.turbine.modules.Layout;
25import org.apache.turbine.util.RunData;
26import org.apache.turbine.services.TurbineServices;
27import org.apache.turbine.services.jsp.JspService;
28import org.apache.turbine.services.jsp.TurbineJspService;
2930/*31 * This Layout module allows JSP templates to be used as layouts.32 * Same as turbine's JspLayout, except that:-33 * - The Mimetype is not fixed text/html but the one set in JetspeedTemplatePage34 * - Navigations are handled by the layout Jsp only35 * - Not the result of the screen is placed in the request, just the screen name and relative path.36 * The Ecs.jsp will handle ecs-screen processing.37 *38 * @author <a href="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>39 * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>40 * @version $Id: JetspeedJspLayout.java,v 1.21 2004/02/23 02:59:30 jford Exp $41 */42publicclassJetspeedJspLayoutextends Layout
43 {
44/***45 * Static initialization of the logger for this class46 */47privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedJspLayout.class.getName());
4849/*** 50 * Method called by LayoutLoader.51 *52 * @param RunData53 */54publicvoid doBuild(RunData data) throws Exception
55 {
56 String screenPath = null;
5758// FIXME: using TurbineJspService instead of the interface JspService 59// because getRelativeTemplateName() is not defined in the 60// interface. A patch has been submitted to Turbine.6162 TurbineJspService jsp = (TurbineJspService)TurbineServices.getInstance().getService(JspService.SERVICE_NAME);
6364// set the content type (including charset)65 data.getResponse().setContentType(data.getContentType());
66if (logger.isInfoEnabled() )
67 {
68 logger.info("JetspeedJspLayout: set response content type to " + data.getContentType());
69 }
7071// tell turbine that the response is handled by the JSP system.72 data.declareDirectResponse();
7374// Put the path to the screen template into the request.75 String path = TemplateLocator.locateScreenTemplate(data, data.getScreenTemplate());
76if (path != null)
77 screenPath = jsp.getRelativeTemplateName("/screens" + path);
78 data.getRequest().setAttribute("screenJsp", screenPath);
79if (logger.isInfoEnabled() )
80 {
81 logger.info("JetspeedJspLayout: set 'screenJSP' to: " + screenPath );
82 }
8384// Grab the layout template set in the JetspeedTemplatePage. 85 String templateName = data.getLayoutTemplate();
8687// Finally, generate the layout template and output to the response88if (logger.isInfoEnabled() )
89 {
90 logger.info("JetspeedJspLayout: forward request to: " + "/layouts" + templateName);
91 }
92 jsp.handleRequest(data, "/layouts" + templateName, false);
93 }
9495 }