View Javadoc

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