KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > tabs > tags > TabTag


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.tabs.tags;
21
22 import javax.servlet.jsp.JspException JavaDoc;
23 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
24
25 import org.apache.struts.taglib.TagUtils;
26
27 import com.sslexplorer.tabs.TabModel;
28
29 /**
30  * Custom tag used to render an invidual tab provided by a
31  * {@link com.sslexplorer.tabs.TabModel}.
32  * <p>
33  * This tag takes a single attribute <i>tabName</i> which must match as it
34  * derives all of its attributes from the &lt;tabSet&gt; tag that is must be
35  * insed.
36  *
37  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
38  * @see com.sslexplorer.tabs.tags.TabSetTag
39  * @see com.sslexplorer.tabs.tags.TabHeadingsTag
40  * @see com.sslexplorer.tabs.TabModel
41  */

42 public class TabTag extends BodyTagSupport JavaDoc {
43
44     // Protected instance variables
45

46     protected String JavaDoc tabName;
47     protected TabModel model;
48     protected String JavaDoc text;
49
50     /*
51      * (non-Javadoc)
52      *
53      * @see org.apache.struts.taglib.html.BaseFieldTag#doStartTag()
54      */

55     public int doStartTag() throws JspException JavaDoc {
56         Object JavaDoc value = findAncestorWithClass(this, TabSetTag.class);
57         if (value == null) {
58             throw new JspException JavaDoc("TabTag must be contained in a TabSetTag");
59         }
60         model = ((TabSetTag) value).getModel();
61         text = null;
62         return EVAL_BODY_BUFFERED;
63     }
64
65     /* (non-Javadoc)
66      * @see javax.servlet.jsp.tagext.IterationTag#doAfterBody()
67      */

68     public int doAfterBody() throws JspException JavaDoc {
69         if (bodyContent != null) {
70             String JavaDoc value = bodyContent.getString().trim();
71             if (value.length() > 0)
72                 text = value;
73         }
74         return (SKIP_BODY);
75     }
76
77     /* (non-Javadoc)
78      * @see javax.servlet.jsp.tagext.Tag#doEndTag()
79      */

80     public int doEndTag() throws JspException JavaDoc {
81
82         boolean selected = (tabName.equals(model.getSelectedTab() == null ? model.getTabName(0) : model.getSelectedTab()));
83
84         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
85         results.append("<div id=\"");
86         results.append("tab_panel_");
87         results.append(tabName);
88         results.append("\" ");
89         if (selected) {
90             // results.append("style=\"visiblity: hidden\" ");
91
results.append("class=\"tabPanel\"><div class=\"tabContent\">");
92         } else {
93             results.append("class=\"tabPanelHidden\"><div class=\"tabContent\">");
94
95         }
96         // results.append("class=\"tabPanel\"><div class=\"tabContent\">");
97
results.append(text);
98         results.append("</div></div>");
99         // Render this element to our writer
100
TagUtils.getInstance().write(pageContext, results.toString());
101         // Evaluate the remainder of this page
102
return (EVAL_PAGE);
103     }
104
105     /**
106      * Set the tab name display. This must match the name returned by
107      * {@link TabModel#getTabName(int)}.
108      *
109      * @param tabName tab name
110      */

111     public void setTabName(String JavaDoc tabName) {
112         this.tabName = tabName;
113     }
114 }
115
Popular Tags