KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > taglib > TabTag


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: TabTag.java,v 1.7 2005/04/01 09:58:33 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.taglib;
27
28 import java.net.MalformedURLException JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import javax.servlet.jsp.JspException JavaDoc;
32 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
33 import javax.servlet.jsp.tagext.Tag JavaDoc;
34
35 import org.apache.struts.taglib.TagUtils;
36
37
38 /**
39  * @author Michel-Ange ANTON
40  */

41 public class TabTag extends BodyTagSupport JavaDoc {
42
43 // ----------------------------------------------------- Instance Variables
44
private String JavaDoc m_Body = null;
45     private String JavaDoc m_Url = null;
46
47 // ----------------------------------------------------- Properties
48

49     private boolean selected = false;
50     private String JavaDoc href = null;
51     private String JavaDoc forward = null;
52     private String JavaDoc forwardControl = null;
53     /**
54      * Accessor Href property.
55      */

56     public String JavaDoc getHref() {
57         return href;
58     }
59
60     public void setHref(String JavaDoc href) {
61         this.href = href;
62     }
63
64     /**
65      * Accessor Selected property.
66      */

67     public boolean getSelected() {
68         return (this.selected);
69     }
70
71     public void setSelected(boolean selected) {
72         this.selected = selected;
73     }
74
75     /**
76      * Accessor Forward property.
77      */

78     public String JavaDoc getForward() {
79         return forward;
80     }
81
82     public void setForward(String JavaDoc forward) {
83         this.forward = forward;
84     }
85
86     /**
87      * Accessor ForwardControl property.
88      */

89     public String JavaDoc getForwardControl() {
90         return forwardControl;
91     }
92
93     public void setForwardControl(String JavaDoc forwardControl) {
94         this.forwardControl = forwardControl;
95     }
96
97     /**
98      * The anchor to be added to the end of the generated hyperlink.
99      */

100     protected String JavaDoc anchor = null;
101
102     public String JavaDoc getAnchor() {
103         return (this.anchor);
104     }
105
106     public void setAnchor(String JavaDoc anchor) {
107         this.anchor = anchor;
108     }
109
110     /**
111      * The link name for named links.
112      */

113     protected String JavaDoc linkName = null;
114
115     public String JavaDoc getLinkName() {
116         return (this.linkName);
117     }
118
119     public void setLinkName(String JavaDoc linkName) {
120         this.linkName = linkName;
121     }
122
123     /**
124      * The JSP bean name for query parameters.
125      */

126     protected String JavaDoc name = null;
127
128     public String JavaDoc getName() {
129         return (this.name);
130     }
131
132     public void setName(String JavaDoc name) {
133         this.name = name;
134     }
135
136     /**
137      * The context-relative page URL (beginning with a slash) to which
138      * this hyperlink will be rendered.
139      */

140     protected String JavaDoc page = null;
141
142     public String JavaDoc getPage() {
143         return (this.page);
144     }
145
146     public void setPage(String JavaDoc page) {
147         this.page = page;
148     }
149
150     /**
151      * The single-parameter request parameter name to generate.
152      */

153     protected String JavaDoc paramId = null;
154
155     public String JavaDoc getParamId() {
156         return (this.paramId);
157     }
158
159     public void setParamId(String JavaDoc paramId) {
160         this.paramId = paramId;
161     }
162
163     /**
164      * The single-parameter JSP bean name.
165      */

166     protected String JavaDoc paramName = null;
167
168     public String JavaDoc getParamName() {
169         return (this.paramName);
170     }
171
172     public void setParamName(String JavaDoc paramName) {
173         this.paramName = paramName;
174     }
175
176     /**
177      * The single-parameter JSP bean property.
178      */

179     protected String JavaDoc paramProperty = null;
180
181     public String JavaDoc getParamProperty() {
182         return (this.paramProperty);
183     }
184
185     public void setParamProperty(String JavaDoc paramProperty) {
186         this.paramProperty = paramProperty;
187     }
188
189     /**
190      * The single-parameter JSP bean scope.
191      */

192     protected String JavaDoc paramScope = null;
193
194     public String JavaDoc getParamScope() {
195         return (this.paramScope);
196     }
197
198     public void setParamScope(String JavaDoc paramScope) {
199         this.paramScope = paramScope;
200     }
201
202     /**
203      * The JSP bean property name for query parameters.
204      */

205     protected String JavaDoc property = null;
206
207     public String JavaDoc getProperty() {
208         return (this.property);
209     }
210
211     public void setProperty(String JavaDoc property) {
212         this.property = property;
213     }
214
215     /**
216      * The scope of the bean specified by the name property, if any.
217      */

218     protected String JavaDoc scope = null;
219
220     public String JavaDoc getScope() {
221         return (this.scope);
222     }
223
224     public void setScope(String JavaDoc scope) {
225         this.scope = scope;
226     }
227
228     /**
229      * The window target.
230      */

231     protected String JavaDoc target = null;
232
233     public String JavaDoc getTarget() {
234         return (this.target);
235     }
236
237     public void setTarget(String JavaDoc target) {
238         this.target = target;
239     }
240
241     /**
242      * Include transaction token (if any) in the hyperlink?
243      */

244     protected boolean transaction = false;
245
246     public boolean getTransaction() {
247         return (this.transaction);
248     }
249
250     public void setTransaction(boolean transaction) {
251         this.transaction = transaction;
252     }
253
254 // --------------------------------------------------------- Public Methods
255

256     public int doStartTag()
257         throws JspException JavaDoc {
258         // Initialize the older body
259
m_Body = null;
260
261         // Do no further processing for now
262
return (EVAL_BODY_BUFFERED);
263     }
264
265     public int doAfterBody()
266         throws JspException JavaDoc {
267         String JavaDoc sBody = bodyContent.getString();
268         if (sBody != null) {
269             sBody = sBody.trim();
270             if (sBody.length() > 0) {
271                 this.m_Body = sBody;
272             }
273         }
274         return (SKIP_BODY);
275     }
276
277     /**
278      * Record this tab with our surrounding TabsTag instance.
279      *
280      * @exception JspException if a processing error occurs
281      */

282     public int doEndTag()
283         throws JspException JavaDoc {
284
285         // Find our parent TabsTag instance
286
Tag JavaDoc parent = findAncestorWithClass(this, TabsTag.class);
287         if ((parent == null) || !(parent instanceof TabsTag)) {
288             throw new JspException JavaDoc("Must be nested in a TabsTag instance");
289         }
290         TabsTag oTabs = (TabsTag) parent;
291
292         // Generate the hyperlink URL
293
TagUtils tagUtils = TagUtils.getInstance();
294         Map JavaDoc oParams = tagUtils.computeParameters(pageContext, paramId, paramName, paramProperty
295             , paramScope, name, property, scope, transaction);
296         m_Url = null;
297         try {
298             m_Url = tagUtils.computeURL(pageContext, forward, href, page, null, null, oParams, anchor, false);
299          } catch (MalformedURLException JavaDoc e) {
300             // none
301
}
302         // Verify forwardControl parameter
303
if ((m_Url == null) && (forwardControl != null) && (oTabs.isUsingWhere() == true)) {
304             try {
305                 // Get the selected node
306
TreeControlNode oNode = oTabs.getSelectedTreeControlNode();
307                 if (oNode != null) {
308                     try {
309                         String JavaDoc sForward = tagUtils.computeURL(pageContext, forwardControl, null, null, null, null, null, null, false);
310                         int iPos = oNode.getAction().indexOf("?");
311                         m_Url = sForward + oNode.getAction().substring(iPos);
312                     } catch (MalformedURLException JavaDoc e) {
313                         // none
314
}
315                 }
316             } catch (Exception JavaDoc ex) {
317                 // none
318
}
319         }
320         // Verify Url
321
if (m_Url == null) {
322             m_Url = new String JavaDoc("");
323         }
324         // Verify body label
325
if (m_Body == null) {
326             m_Body = new String JavaDoc("");
327         }
328         // Register the information for the action represented by
329
// this action
330
oTabs.addTab(m_Body, m_Url, selected);
331
332         return (EVAL_PAGE);
333     }
334
335     /**
336      * Release all state information set by this tag.
337      */

338     public void release() {
339         this.m_Body = null;
340         this.href = null;
341         this.forward = null;
342         this.forwardControl = null;
343     }
344 }
345
Popular Tags