KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 import org.apache.struts.taglib.TagUtils;
25 import org.apache.struts.taglib.html.BaseHandlerTag;
26
27 import com.sslexplorer.tabs.TabModel;
28
29 /**
30  * Custom tag that acts as a container for <tabHeadings> tags and
31  * <tab> tags.
32  * <p>
33  * This tag requires access to a bean that is an instance of
34  * {@link com.sslexplorer.tabs.TabModel} which is supplied using the normal
35  * <i>name</i> and <i>property</i> attributes.
36  * <p>
37  * It also requires <i>resourcePrefix</i> and <i>bundle</i> attributes. These
38  * are used for build up the resource keys used for get the individual tab
39  * titles (when {@link com.sslexplorer.tabs.TabModel#getTabTitle(int)} is null).
40  *
41  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
42  * @see com.sslexplorer.tabs.tags.TabTag
43  * @see com.sslexplorer.tabs.tags.TabHeadingsTag
44  * @see com.sslexplorer.tabs.TabModel
45  */

46 public class TabSetTag extends BaseHandlerTag {
47
48     // Protected instance variables
49

50     protected String JavaDoc name;
51     protected String JavaDoc property;
52     protected String JavaDoc resourcePrefix;
53     protected TabModel model;
54     protected String JavaDoc text;
55
56     /*
57      * (non-Javadoc)
58      *
59      * @see org.apache.struts.taglib.html.BaseFieldTag#doStartTag()
60      */

61     public int doStartTag() throws JspException JavaDoc {
62
63         Object JavaDoc value = TagUtils.getInstance().lookup(pageContext, name, property, null);
64         if (value == null || !(value instanceof TabModel)) {
65             throw new JspException JavaDoc("Name / property attributes must specify an instance of TabModel (" + value + ")");
66         }
67         model = (TabModel) value;
68         return (EVAL_BODY_BUFFERED);
69     }
70
71     protected String JavaDoc getName() {
72         return name;
73     }
74
75     /**
76      * Set the name of the bean that contains the {@link TabModel}
77      * implementation.
78      *
79      * @param name name of the bean that is the {@link TabModel} implementation.
80      */

81     public void setName(String JavaDoc name) {
82         this.name = name;
83     }
84
85     /**
86      * Set the optional property of the bean that contains the {@link TabModel}
87      * implementation.
88      *
89      * @param property optional property of the bean that contains the
90      * {@link TabModel} implementation
91      */

92     public void setProperty(String JavaDoc property) {
93         this.property = property;
94     }
95
96     /**
97      * Set the resource prefix that is used to build up the key used to
98      * get the table titles.
99      *
100      * @param resourcePrefix resource prefix used to build up key for tab titles
101      */

102     public void setResourcePrefix(String JavaDoc resourcePrefix) {
103         this.resourcePrefix = resourcePrefix;
104     }
105
106     /* (non-Javadoc)
107      * @see javax.servlet.jsp.tagext.IterationTag#doAfterBody()
108      */

109     public int doAfterBody() throws JspException JavaDoc {
110
111         if (bodyContent != null) {
112             String JavaDoc value = bodyContent.getString().trim();
113             if (value.length() > 0)
114                 text = value;
115         }
116         return (SKIP_BODY);
117
118     }
119
120     /* (non-Javadoc)
121      * @see javax.servlet.jsp.tagext.Tag#doEndTag()
122      */

123     public int doEndTag() throws JspException JavaDoc {
124
125         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
126         results.append("<div class=\"tabSet\">");
127         results.append(text);
128         results.append("</div>");
129
130         // Render this element to our writer
131
TagUtils.getInstance().write(pageContext, results.toString());
132
133         // Evaluate the remainder of this page
134
return (EVAL_PAGE);
135     }
136
137     protected String JavaDoc getResourcePrefix() {
138         return resourcePrefix;
139     }
140
141     protected String JavaDoc getProperty() {
142         return property;
143     }
144
145     protected TabModel getModel() {
146         return model;
147     }
148 }
149
Popular Tags