KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > modules > layouts > JetspeedJspLayout


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 at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * 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 and
14  * limitations under the License.
15  */

16 package org.apache.jetspeed.modules.layouts;
17
18 // Jetspeed imports
19
import org.apache.jetspeed.services.TemplateLocator;
20 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
21 import org.apache.jetspeed.services.logging.JetspeedLogger;
22
23 //Turbine imports
24
import org.apache.turbine.modules.Layout;
25 import org.apache.turbine.util.RunData;
26 import org.apache.turbine.services.TurbineServices;
27 import org.apache.turbine.services.jsp.JspService;
28 import org.apache.turbine.services.jsp.TurbineJspService;
29
30 /*
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 JetspeedTemplatePage
34  * - Navigations are handled by the layout Jsp only
35  * - 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  */

42 public class JetspeedJspLayout extends Layout
43 {
44     /**
45      * Static initialization of the logger for this class
46      */

47     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedJspLayout.class.getName());
48     
49     /**
50      * Method called by LayoutLoader.
51      *
52      * @param RunData
53      */

54     public void doBuild(RunData data) throws Exception JavaDoc
55     {
56         String JavaDoc screenPath = null;
57         
58         // 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.
61

62         TurbineJspService jsp = (TurbineJspService)TurbineServices.getInstance().getService(JspService.SERVICE_NAME);
63
64         // set the content type (including charset)
65
data.getResponse().setContentType(data.getContentType());
66         if (logger.isInfoEnabled() )
67         {
68             logger.info("JetspeedJspLayout: set response content type to " + data.getContentType());
69         }
70
71         // tell turbine that the response is handled by the JSP system.
72
data.declareDirectResponse();
73
74         // Put the path to the screen template into the request.
75
String JavaDoc path = TemplateLocator.locateScreenTemplate(data, data.getScreenTemplate());
76         if (path != null)
77             screenPath = jsp.getRelativeTemplateName("/screens" + path);
78         data.getRequest().setAttribute("screenJsp", screenPath);
79         if (logger.isInfoEnabled() )
80         {
81             logger.info("JetspeedJspLayout: set 'screenJSP' to: " + screenPath );
82         }
83
84         // Grab the layout template set in the JetspeedTemplatePage.
85
String JavaDoc templateName = data.getLayoutTemplate();
86
87         // Finally, generate the layout template and output to the response
88
if (logger.isInfoEnabled() )
89         {
90             logger.info("JetspeedJspLayout: forward request to: " + "/layouts" + templateName);
91         }
92         jsp.handleRequest(data, "/layouts" + templateName, false);
93     }
94     
95 }
96
Popular Tags