001package org.apache.turbine.services.jsp.util; 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.commons.logging.Log; 025import org.apache.commons.logging.LogFactory; 026import org.apache.turbine.modules.NavigationLoader; 027import org.apache.turbine.services.template.TurbineTemplate; 028import org.apache.turbine.util.RunData; 029 030/** 031 * Returns output of a Navigation module. An instance of this is placed in the 032 * request by the JspLayout. This allows template authors to 033 * set the navigation template they'd like to place in their templates.<br> 034 * Here's how it's used in a JSP template:<br> 035 * <code> 036 * <%useBean id="navigation" class="JspNavigation" scope="request"/%> 037 * ... 038 * <%= navigation.setTemplate("admin_navigation.jsp") %> 039 * </code> 040 * @author <a href="john.mcnally@clearink.com">John D. McNally</a> 041 * @author <a href="mbryson@mont.mindspring.com">Dave Bryson</a> 042 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 043 * @version $Id: JspNavigation.java 1706239 2015-10-01 13:18:35Z tv $ 044 */ 045public class JspNavigation 046{ 047 /** Logging */ 048 private static Log log = LogFactory.getLog(JspNavigation.class); 049 050 /* The RunData object */ 051 private final RunData data; 052 053 /** 054 * Constructor 055 * 056 * @param data Turbine request data 057 */ 058 public JspNavigation(RunData data) 059 { 060 this.data = data; 061 } 062 063 /** 064 * builds the output of the navigation template 065 * @param template the name of the navigation template 066 */ 067 public void setTemplate(String template) 068 { 069 data.getTemplateInfo().setNavigationTemplate(template); 070 String module = null; 071 try 072 { 073 module = TurbineTemplate.getNavigationName(template); 074 NavigationLoader.getInstance().exec(data, module); 075 } 076 catch (Exception e) 077 { 078 String message = "Error processing navigation template:" + 079 template + " using module: " + module; 080 log.error(message, e); 081 try 082 { 083 data.getResponse().getWriter().print("Error processing navigation template: " 084 + template + " using module: " + module); 085 } 086 catch (java.io.IOException ioe) 087 { 088 // ignore 089 } 090 } 091 } 092}