View Javadoc

1   package org.apache.jetspeed.services.jsp.tags;
2   
3   /*
4    * Copyright 2000-2004 The Apache Software Foundation.
5    * 
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * 
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import javax.servlet.jsp.JspException;
20  import javax.servlet.jsp.PageContext;
21  import javax.servlet.jsp.tagext.TagSupport;
22  
23  
24  // JetSpeed Classes
25  import org.apache.jetspeed.services.TemplateLocator;
26  
27  // Turbine Classes
28  import org.apache.turbine.modules.NavigationLoader;
29  import org.apache.turbine.util.RunData;
30  import org.apache.turbine.services.template.TemplateService;
31  import org.apache.turbine.services.jsp.JspService;
32  import org.apache.turbine.services.TurbineServices;
33  
34  // Jetspeed classes
35  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
36  import org.apache.jetspeed.services.logging.JetspeedLogger;
37  
38  /***
39   * Supporting class for the navigation tag.
40   * Includes a navigation JSP. If the respective tag parameter is set,
41   * different JSPs will be choosen, depending on whether the user has 
42   * already logged in or not.
43   *
44   * @author <a href="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>
45   */
46  public class NavigationTag extends TagSupport 
47  {
48      /***
49       * Static initialization of the logger for this class
50       */    
51      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(NavigationTag.class.getName());
52      
53      /***
54       * defaultTemplate parameter defines the template whose contents will replace
55       * this tag in the layout if none of the special states are detected.
56       */
57      private String defaultTemplate;
58  
59      /*** 
60       * The setter for DefaultTemplate parameter
61       */
62      public void setDefaultTemplate(String defaultTemplate) 
63      {
64          this.defaultTemplate = defaultTemplate;
65      }
66  
67      /***
68       * loggedInTemplate parameter defines the template whose contents will replace
69       * this tag in the layout if the user is already logged into the system.
70       */
71      private String loggedInTemplate;
72  
73      /*** 
74       * The setter for loggedInTemplate parameter
75       */
76      public void setLoggedInTemplate(String loggedInTemplate) 
77      {
78          this.loggedInTemplate = loggedInTemplate;
79      }
80  
81  
82      /***
83       * Method called when the tag is encountered to send the navigation
84       * template's contents to the output stream
85       *
86       * @return SKIP_BODY, as it is intended to be a single tag.
87       */
88      public int doStartTag() throws JspException 
89      {
90          String template = defaultTemplate;
91          String module   = null;
92  
93          RunData data = (RunData)pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
94          try
95          {  
96              /* LOGGED_IN */
97              if ( (data != null) && (data.getUser() != null) && data.getUser().hasLoggedIn() && (loggedInTemplate != null) ) 
98                template = loggedInTemplate;
99  
100             data.getTemplateInfo().setNavigationTemplate(
101                         TemplateLocator.locateNavigationTemplate(data,template));
102 
103             pageContext.getOut().flush();
104             module = ((TemplateService)TurbineServices.getInstance().getService(
105             TemplateService.SERVICE_NAME)).getNavigationName(template);
106             NavigationLoader.getInstance().exec(data, module);
107         }
108         catch (Exception e)
109         {
110             String message = "Error processing navigation template:" + template + " using module: " + module;
111             logger.error(message, e);
112             try
113             {
114                 data.getOut().print("Error processing navigation template: " + template + " using module: " + module);
115             }
116             catch(java.io.IOException ioe) {}    
117         }
118         return SKIP_BODY;
119     }
120 }