1 package org.apache.turbine.services.jsp.util;
2
3
4 import org.apache.logging.log4j.LogManager;
5
6 /*
7 * Licensed to the Apache Software Foundation (ASF) under one
8 * or more contributor license agreements. See the NOTICE file
9 * distributed with this work for additional information
10 * regarding copyright ownership. The ASF licenses this file
11 * to you under the Apache License, Version 2.0 (the
12 * "License"); you may not use this file except in compliance
13 * with the License. You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing,
18 * software distributed under the License is distributed on an
19 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20 * KIND, either express or implied. See the License for the
21 * specific language governing permissions and limitations
22 * under the License.
23 */
24
25
26 import org.apache.logging.log4j.Logger;
27 import org.apache.turbine.modules.NavigationLoader;
28 import org.apache.turbine.services.TurbineServices;
29 import org.apache.turbine.services.template.TemplateService;
30 import org.apache.turbine.util.RunData;
31
32 /**
33 * Returns output of a Navigation module. An instance of this is placed in the
34 * request by the JspLayout. This allows template authors to
35 * set the navigation template they'd like to place in their templates.<br>
36 * Here's how it's used in a JSP template:<br>
37 * <code>
38 * <%useBean id="navigation" class="JspNavigation" scope="request" %>
39 * ...
40 * <%= navigation.setTemplate("admin_navigation.jsp") %>
41 * </code>
42 * @author <a href="john.mcnally@clearink.com">John D. McNally</a>
43 * @author <a href="mbryson@mont.mindspring.com">Dave Bryson</a>
44 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
45 * @version $Id$
46 */
47 public class JspNavigation
48 {
49 /** Logging */
50 private static Logger log = LogManager.getLogger(JspNavigation.class);
51
52 /* The RunData object */
53 private final RunData data;
54
55 /**
56 * Constructor
57 *
58 * @param data Turbine request data
59 */
60 public JspNavigation(RunData data)
61 {
62 this.data = data;
63 }
64
65 /**
66 * builds the output of the navigation template
67 * @param template the name of the navigation template
68 */
69 public void setTemplate(String template)
70 {
71 data.getTemplateInfo().setNavigationTemplate(template);
72 String module = null;
73 try
74 {
75 TemplateService templateService = (TemplateService)TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
76 module = templateService.getNavigationName(template);
77 NavigationLoader.getInstance().exec(data, module);
78 }
79 catch (Exception e)
80 {
81 String message = "Error processing navigation template:" +
82 template + " using module: " + module;
83 log.error(message, e);
84 try
85 {
86 data.getResponse().getWriter().print(message);
87 }
88 catch (java.io.IOException ioe)
89 {
90 // ignore
91 }
92 }
93 }
94 }