KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ditchnet > jsp > taglib > tabs > handler > TabConfigTag


1 /*
2  * The contents of this file are subject to the GNU Lesser General Public
3  * License Version 2.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.gnu.org/copyleft/lesser.html
6  *
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  *
12  * Developer:
13  * Todd Ditchendorf, todd@ditchnet.org
14  *
15  */

16
17 /**
18  * @author Todd Ditchendorf
19  * @version 0.8
20  * @since 0.8
21  */

22 package org.ditchnet.jsp.taglib.tabs.handler;
23
24 import java.io.IOException JavaDoc;
25 import java.net.URLEncoder JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.jsp.PageContext JavaDoc;
28 import javax.servlet.jsp.JspException JavaDoc;
29 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
30 import org.ditchnet.jsp.taglib.tabs.listener.TabServletContextListener;
31
32
33 /**
34  * @author Todd Ditchendorf
35  * @since 0.8
36  *
37  * JSP Tag that renders XHTML </code>script</code> and </code>style</code> elements
38  * that link to the CSS and JavaScript resources necessary to render the
39  * tab components on the current page. The resources that are linked to are
40  * the resources placed in a directory named </code>/org.ditchnet.taglib/</code>
41  * in the web app's root directory. These resources were placed there by
42  * the {@link org.ditchnet.jsp.taglib.tabs.listener.TabServletContextListener}.
43  */

44 public final class TabConfigTag extends SimpleTagSupport JavaDoc {
45     
46     private String JavaDoc contextPath;
47
48     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
49         
50         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
51         
52         findContextPath();
53         renderScriptTag(buff);
54         renderStyleTag(buff);
55         
56         getJspContext().getOut().print(buff);
57         
58     }
59     
60     private void findContextPath() {
61         PageContext JavaDoc pageContext = (PageContext JavaDoc)getJspContext();
62         HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc)pageContext.getRequest();
63         contextPath = req.getContextPath();
64     }
65     
66     private void renderScriptTag(final StringBuffer JavaDoc buff) {
67         String JavaDoc uri =
68             getEncodedContextRelativePath(TabServletContextListener.SCRIPT_URI);
69
70         buff.append("\n\n\t<script type=\"text/javascript\" ")
71             .append("src=\"").append(uri).append("\">")
72             .append("</script>\n");
73     }
74     
75     private void renderStyleTag(final StringBuffer JavaDoc buff) {
76         String JavaDoc uri =
77             getEncodedContextRelativePath(TabServletContextListener.STYLE_URI);
78
79         buff.append("\t<link type=\"text/css\" rel=\"stylesheet\" ")
80             .append("href=\"").append(uri).append("\" />\n\n");
81     }
82     
83     private String JavaDoc getEncodedContextRelativePath(final String JavaDoc uri) {
84         return contextPath + uri;
85     }
86
87
88     
89 }
90
Popular Tags