KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > jsp > tags > NavigationTag


1 package org.apache.turbine.services.jsp.tags;
2
3 /*
4  * Copyright 2001-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 java.io.IOException JavaDoc;
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.PageContext JavaDoc;
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23 import org.apache.turbine.modules.NavigationLoader;
24 import org.apache.turbine.services.TurbineServices;
25 import org.apache.turbine.services.jsp.JspService;
26 import org.apache.turbine.services.template.TemplateService;
27 import org.apache.turbine.util.Log;
28 import org.apache.turbine.util.RunData;
29 import org.apache.turbine.util.template.TemplateInfo;
30
31 /**
32  * Supporting class for the bodyAttributes tag.
33  * Sends the contents of the a screen's body tag's attributes
34  * parameter to the output stream. If the screen did not set
35  * the attributes parameter, a default may be used if specified
36  * in this tag. Example usage:
37  * <body <x:bodyAttributes default='onLoad="jsfunc()"' />>
38  *
39  * @author <a HREF="mailto:john.mcnally@clearink.com">John D. McNally</a>
40  * @version $Id: NavigationTag.java,v 1.1.2.2 2004/05/20 03:03:07 seade Exp $
41  */

42 public class NavigationTag extends TagSupport JavaDoc
43 {
44     /**
45      * template parameter defines the template whose contents will replace
46      * this tag in the layout.
47      */

48     private String JavaDoc template;
49
50     /**
51      * The setter for template parameter
52      */

53     public void setTemplate(String JavaDoc template)
54     {
55         this.template = template;
56     }
57
58     /**
59      * Method called when the tag is encountered to send the navigation
60      * template's contents to the output stream
61      *
62      * @return SKIP_BODY, as it is intended to be a single tag.
63      */

64     public int doStartTag() throws JspException JavaDoc
65     {
66         RunData data = (RunData)pageContext
67                 .getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
68         data.getTemplateInfo().setNavigationTemplate(template);
69         String JavaDoc module = null;
70         try
71         {
72             pageContext.getOut().flush();
73             module = ((TemplateService)TurbineServices.getInstance().getService(
74             TemplateService.SERVICE_NAME)).getNavigationName(template);
75             NavigationLoader.getInstance().exec(data, module);
76         }
77         catch (Exception JavaDoc e)
78         {
79             String JavaDoc message = "Error processing navigation template:" +
80                 template + " using module: " + module;
81             Log.error(message, e);
82             try
83             {
84                 data.getOut().print("Error processing navigation template: "
85                     + template + " using module: " + module);
86             }
87             catch(java.io.IOException JavaDoc ioe) {}
88         }
89         return SKIP_BODY;
90     }
91 }
92
Popular Tags