001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: TabTag.java 6499 2005-04-01 09:59:04Z kemlerp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.taglib;
027:
028: import java.net.MalformedURLException;
029: import java.util.Map;
030:
031: import javax.servlet.jsp.JspException;
032: import javax.servlet.jsp.tagext.BodyTagSupport;
033: import javax.servlet.jsp.tagext.Tag;
034:
035: import org.apache.struts.taglib.TagUtils;
036:
037: /**
038: * @author Michel-Ange ANTON
039: */
040: public class TabTag extends BodyTagSupport {
041:
042: // ----------------------------------------------------- Instance Variables
043: private String m_Body = null;
044: private String m_Url = null;
045:
046: // ----------------------------------------------------- Properties
047:
048: private boolean selected = false;
049: private String href = null;
050: private String forward = null;
051: private String forwardControl = null;
052:
053: /**
054: * Accessor Href property.
055: */
056: public String getHref() {
057: return href;
058: }
059:
060: public void setHref(String href) {
061: this .href = href;
062: }
063:
064: /**
065: * Accessor Selected property.
066: */
067: public boolean getSelected() {
068: return (this .selected);
069: }
070:
071: public void setSelected(boolean selected) {
072: this .selected = selected;
073: }
074:
075: /**
076: * Accessor Forward property.
077: */
078: public String getForward() {
079: return forward;
080: }
081:
082: public void setForward(String forward) {
083: this .forward = forward;
084: }
085:
086: /**
087: * Accessor ForwardControl property.
088: */
089: public String getForwardControl() {
090: return forwardControl;
091: }
092:
093: public void setForwardControl(String forwardControl) {
094: this .forwardControl = forwardControl;
095: }
096:
097: /**
098: * The anchor to be added to the end of the generated hyperlink.
099: */
100: protected String anchor = null;
101:
102: public String getAnchor() {
103: return (this .anchor);
104: }
105:
106: public void setAnchor(String anchor) {
107: this .anchor = anchor;
108: }
109:
110: /**
111: * The link name for named links.
112: */
113: protected String linkName = null;
114:
115: public String getLinkName() {
116: return (this .linkName);
117: }
118:
119: public void setLinkName(String linkName) {
120: this .linkName = linkName;
121: }
122:
123: /**
124: * The JSP bean name for query parameters.
125: */
126: protected String name = null;
127:
128: public String getName() {
129: return (this .name);
130: }
131:
132: public void setName(String 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 page = null;
141:
142: public String getPage() {
143: return (this .page);
144: }
145:
146: public void setPage(String page) {
147: this .page = page;
148: }
149:
150: /**
151: * The single-parameter request parameter name to generate.
152: */
153: protected String paramId = null;
154:
155: public String getParamId() {
156: return (this .paramId);
157: }
158:
159: public void setParamId(String paramId) {
160: this .paramId = paramId;
161: }
162:
163: /**
164: * The single-parameter JSP bean name.
165: */
166: protected String paramName = null;
167:
168: public String getParamName() {
169: return (this .paramName);
170: }
171:
172: public void setParamName(String paramName) {
173: this .paramName = paramName;
174: }
175:
176: /**
177: * The single-parameter JSP bean property.
178: */
179: protected String paramProperty = null;
180:
181: public String getParamProperty() {
182: return (this .paramProperty);
183: }
184:
185: public void setParamProperty(String paramProperty) {
186: this .paramProperty = paramProperty;
187: }
188:
189: /**
190: * The single-parameter JSP bean scope.
191: */
192: protected String paramScope = null;
193:
194: public String getParamScope() {
195: return (this .paramScope);
196: }
197:
198: public void setParamScope(String paramScope) {
199: this .paramScope = paramScope;
200: }
201:
202: /**
203: * The JSP bean property name for query parameters.
204: */
205: protected String property = null;
206:
207: public String getProperty() {
208: return (this .property);
209: }
210:
211: public void setProperty(String 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 scope = null;
219:
220: public String getScope() {
221: return (this .scope);
222: }
223:
224: public void setScope(String scope) {
225: this .scope = scope;
226: }
227:
228: /**
229: * The window target.
230: */
231: protected String target = null;
232:
233: public String getTarget() {
234: return (this .target);
235: }
236:
237: public void setTarget(String 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() throws JspException {
257: // Initialize the older body
258: m_Body = null;
259:
260: // Do no further processing for now
261: return (EVAL_BODY_BUFFERED);
262: }
263:
264: public int doAfterBody() throws JspException {
265: String sBody = bodyContent.getString();
266: if (sBody != null) {
267: sBody = sBody.trim();
268: if (sBody.length() > 0) {
269: this .m_Body = sBody;
270: }
271: }
272: return (SKIP_BODY);
273: }
274:
275: /**
276: * Record this tab with our surrounding TabsTag instance.
277: *
278: * @exception JspException if a processing error occurs
279: */
280: public int doEndTag() throws JspException {
281:
282: // Find our parent TabsTag instance
283: Tag parent = findAncestorWithClass(this , TabsTag.class);
284: if ((parent == null) || !(parent instanceof TabsTag)) {
285: throw new JspException(
286: "Must be nested in a TabsTag instance");
287: }
288: TabsTag oTabs = (TabsTag) parent;
289:
290: // Generate the hyperlink URL
291: TagUtils tagUtils = TagUtils.getInstance();
292: Map oParams = tagUtils.computeParameters(pageContext, paramId,
293: paramName, paramProperty, paramScope, name, property,
294: scope, transaction);
295: m_Url = null;
296: try {
297: m_Url = tagUtils.computeURL(pageContext, forward, href,
298: page, null, null, oParams, anchor, false);
299: } catch (MalformedURLException e) {
300: // none
301: }
302: // Verify forwardControl parameter
303: if ((m_Url == null) && (forwardControl != null)
304: && (oTabs.isUsingWhere() == true)) {
305: try {
306: // Get the selected node
307: TreeControlNode oNode = oTabs
308: .getSelectedTreeControlNode();
309: if (oNode != null) {
310: try {
311: String sForward = tagUtils.computeURL(
312: pageContext, forwardControl, null,
313: null, null, null, null, null, false);
314: int iPos = oNode.getAction().indexOf("?");
315: m_Url = sForward
316: + oNode.getAction().substring(iPos);
317: } catch (MalformedURLException e) {
318: // none
319: }
320: }
321: } catch (Exception ex) {
322: // none
323: }
324: }
325: // Verify Url
326: if (m_Url == null) {
327: m_Url = new String("");
328: }
329: // Verify body label
330: if (m_Body == null) {
331: m_Body = new String("");
332: }
333: // Register the information for the action represented by
334: // this action
335: oTabs.addTab(m_Body, m_Url, selected);
336:
337: return (EVAL_PAGE);
338: }
339:
340: /**
341: * Release all state information set by this tag.
342: */
343: public void release() {
344: this.m_Body = null;
345: this.href = null;
346: this.forward = null;
347: this.forwardControl = null;
348: }
349: }
|