View Javadoc

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