1packageorg.apache.jetspeed.services.jsp.tags;
23/*4 * Copyright 2000-2004 The Apache Software Foundation.5 * 6 * Licensed under the Apache License, Version 2.0 (the "License");7 * you may not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 * 10 * http://www.apache.org/licenses/LICENSE-2.011 * 12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819import javax.servlet.jsp.JspException;
20import javax.servlet.jsp.PageContext;
21import javax.servlet.jsp.tagext.TagSupport;
222324// JetSpeed Classes25import org.apache.jetspeed.services.TemplateLocator;
2627// Turbine Classes28import org.apache.turbine.modules.NavigationLoader;
29import org.apache.turbine.util.RunData;
30import org.apache.turbine.services.template.TemplateService;
31import org.apache.turbine.services.jsp.JspService;
32import org.apache.turbine.services.TurbineServices;
3334// Jetspeed classes35import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
36import org.apache.jetspeed.services.logging.JetspeedLogger;
3738/***39 * Supporting class for the navigation tag.40 * Includes a navigation JSP. If the respective tag parameter is set,41 * different JSPs will be choosen, depending on whether the user has 42 * already logged in or not.43 *44 * @author <a href="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>45 */46publicclassNavigationTagextends TagSupport
47 {
48/***49 * Static initialization of the logger for this class50 */51privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(NavigationTag.class.getName());
5253/***54 * defaultTemplate parameter defines the template whose contents will replace55 * this tag in the layout if none of the special states are detected.56 */57private String defaultTemplate;
5859/*** 60 * The setter for DefaultTemplate parameter61 */62publicvoid setDefaultTemplate(String defaultTemplate)
63 {
64this.defaultTemplate = defaultTemplate;
65 }
6667/***68 * loggedInTemplate parameter defines the template whose contents will replace69 * this tag in the layout if the user is already logged into the system.70 */71private String loggedInTemplate;
7273/*** 74 * The setter for loggedInTemplate parameter75 */76publicvoid setLoggedInTemplate(String loggedInTemplate)
77 {
78this.loggedInTemplate = loggedInTemplate;
79 }
808182/***83 * Method called when the tag is encountered to send the navigation84 * template's contents to the output stream85 *86 * @return SKIP_BODY, as it is intended to be a single tag.87 */88publicint doStartTag() throws JspException
89 {
90 String template = defaultTemplate;
91 String module = null;
9293 RunData data = (RunData)pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
94try95 {
96/* LOGGED_IN */97if ( (data != null) && (data.getUser() != null) && data.getUser().hasLoggedIn() && (loggedInTemplate != null) )
98 template = loggedInTemplate;
99100 data.getTemplateInfo().setNavigationTemplate(
101 TemplateLocator.locateNavigationTemplate(data,template));
102103 pageContext.getOut().flush();
104 module = ((TemplateService)TurbineServices.getInstance().getService(
105 TemplateService.SERVICE_NAME)).getNavigationName(template);
106 NavigationLoader.getInstance().exec(data, module);
107 }
108catch (Exception e)
109 {
110 String message = "Error processing navigation template:" + template + " using module: " + module;
111 logger.error(message, e);
112try113 {
114 data.getOut().print("Error processing navigation template: " + template + " using module: " + module);
115 }
116catch(java.io.IOException ioe) {}
117 }
118return SKIP_BODY;
119 }
120 }