View Javadoc
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   * &lt;%useBean id="navigation" class="JspNavigation" scope="request" %&gt;
39   * ...
40   * &lt;%= navigation.setTemplate("admin_navigation.jsp") %&gt;
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: JspNavigation.java 1854688 2019-03-03 10:36:42Z tv $
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              TemplateServiceorg/apache/turbine/services/template/TemplateService.html#TemplateService">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  }