TabTag.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: TabTag.java,v 1.6 2004/03/19 14:31:50 sauthieg Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.taglib;
00027 
00028 import java.net.MalformedURLException;
00029 import java.util.Map;
00030 
00031 import javax.servlet.jsp.JspException;
00032 import javax.servlet.jsp.tagext.BodyTagSupport;
00033 import javax.servlet.jsp.tagext.Tag;
00034 
00035 import org.apache.struts.util.RequestUtils;
00036 
00037 
00041 public class TabTag extends BodyTagSupport {
00042 
00043 // ----------------------------------------------------- Instance Variables
00044     private String m_Body = null;
00045     private String m_Url = null;
00046 
00047 // ----------------------------------------------------- Properties
00048 
00049     private boolean selected = false;
00050     private String href = null;
00051     private String forward = null;
00052     private String forwardControl = null;
00056     public String getHref() {
00057         return href;
00058     }
00059 
00060     public void setHref(String href) {
00061         this.href = href;
00062     }
00063 
00067     public boolean getSelected() {
00068         return (this.selected);
00069     }
00070 
00071     public void setSelected(boolean selected) {
00072         this.selected = selected;
00073     }
00074 
00078     public String getForward() {
00079         return forward;
00080     }
00081 
00082     public void setForward(String forward) {
00083         this.forward = forward;
00084     }
00085 
00089     public String getForwardControl() {
00090         return forwardControl;
00091     }
00092 
00093     public void setForwardControl(String forwardControl) {
00094         this.forwardControl = forwardControl;
00095     }
00096 
00100     protected String anchor = null;
00101 
00102     public String getAnchor() {
00103         return (this.anchor);
00104     }
00105 
00106     public void setAnchor(String anchor) {
00107         this.anchor = anchor;
00108     }
00109 
00113     protected String linkName = null;
00114 
00115     public String getLinkName() {
00116         return (this.linkName);
00117     }
00118 
00119     public void setLinkName(String linkName) {
00120         this.linkName = linkName;
00121     }
00122 
00126     protected String name = null;
00127 
00128     public String getName() {
00129         return (this.name);
00130     }
00131 
00132     public void setName(String name) {
00133         this.name = name;
00134     }
00135 
00140     protected String page = null;
00141 
00142     public String getPage() {
00143         return (this.page);
00144     }
00145 
00146     public void setPage(String page) {
00147         this.page = page;
00148     }
00149 
00153     protected String paramId = null;
00154 
00155     public String getParamId() {
00156         return (this.paramId);
00157     }
00158 
00159     public void setParamId(String paramId) {
00160         this.paramId = paramId;
00161     }
00162 
00166     protected String paramName = null;
00167 
00168     public String getParamName() {
00169         return (this.paramName);
00170     }
00171 
00172     public void setParamName(String paramName) {
00173         this.paramName = paramName;
00174     }
00175 
00179     protected String paramProperty = null;
00180 
00181     public String getParamProperty() {
00182         return (this.paramProperty);
00183     }
00184 
00185     public void setParamProperty(String paramProperty) {
00186         this.paramProperty = paramProperty;
00187     }
00188 
00192     protected String paramScope = null;
00193 
00194     public String getParamScope() {
00195         return (this.paramScope);
00196     }
00197 
00198     public void setParamScope(String paramScope) {
00199         this.paramScope = paramScope;
00200     }
00201 
00205     protected String property = null;
00206 
00207     public String getProperty() {
00208         return (this.property);
00209     }
00210 
00211     public void setProperty(String property) {
00212         this.property = property;
00213     }
00214 
00218     protected String scope = null;
00219 
00220     public String getScope() {
00221         return (this.scope);
00222     }
00223 
00224     public void setScope(String scope) {
00225         this.scope = scope;
00226     }
00227 
00231     protected String target = null;
00232 
00233     public String getTarget() {
00234         return (this.target);
00235     }
00236 
00237     public void setTarget(String target) {
00238         this.target = target;
00239     }
00240 
00244     protected boolean transaction = false;
00245 
00246     public boolean getTransaction() {
00247         return (this.transaction);
00248     }
00249 
00250     public void setTransaction(boolean transaction) {
00251         this.transaction = transaction;
00252     }
00253 
00254 // --------------------------------------------------------- Public Methods
00255 
00256     public int doStartTag()
00257         throws JspException {
00258         // Initialize the older body
00259         m_Body = null;
00260 
00261         // Do no further processing for now
00262         return (EVAL_BODY_BUFFERED);
00263     }
00264 
00265     public int doAfterBody()
00266         throws JspException {
00267         String sBody = bodyContent.getString();
00268         if (sBody != null) {
00269             sBody = sBody.trim();
00270             if (sBody.length() > 0) {
00271                 this.m_Body = sBody;
00272             }
00273         }
00274         return (SKIP_BODY);
00275     }
00276 
00282     public int doEndTag()
00283         throws JspException {
00284 
00285         // Find our parent TabsTag instance
00286         Tag parent = findAncestorWithClass(this, TabsTag.class);
00287         if ((parent == null) || !(parent instanceof TabsTag)) {
00288             throw new JspException("Must be nested in a TabsTag instance");
00289         }
00290         TabsTag oTabs = (TabsTag) parent;
00291 
00292         // Generate the hyperlink URL
00293         Map oParams = RequestUtils.computeParameters(pageContext, paramId, paramName, paramProperty
00294             , paramScope, name, property, scope, transaction);
00295         m_Url = null;
00296         try {
00297             m_Url = RequestUtils.computeURL(pageContext, forward, href, page, oParams, anchor, false);
00298          }
00299         catch (MalformedURLException e) {
00300             // none
00301         }
00302         // Verify forwardControl parameter
00303         if ((m_Url == null) && (forwardControl != null) && (oTabs.isUsingWhere() == true)) {
00304             try {
00305                 // Get the selected node
00306                 TreeControlNode oNode = oTabs.getSelectedTreeControlNode();
00307                 if (oNode != null) {
00308                     try {
00309                         String sForward = RequestUtils.computeURL(pageContext, forwardControl, null, null, null, null, false);
00310                         int iPos = oNode.getAction().indexOf("?");
00311                         m_Url = sForward + oNode.getAction().substring(iPos);
00312                     }
00313                     catch (MalformedURLException e) {
00314                         // none
00315                     }
00316                 }
00317             }
00318             catch (Exception ex) {
00319                 // none
00320             }
00321         }
00322         // Verify Url
00323         if (m_Url == null) {
00324             m_Url = new String("");
00325         }
00326         // Verify body label
00327         if (m_Body == null) {
00328             m_Body = new String("");
00329         }
00330         // Register the information for the action represented by
00331         // this action
00332         oTabs.addTab(m_Body, m_Url, selected);
00333 
00334         return (EVAL_PAGE);
00335     }
00336 
00340     public void release() {
00341         this.m_Body = null;
00342         this.href = null;
00343         this.forward = null;
00344         this.forwardControl = null;
00345     }
00346 }

Generated on Tue Feb 15 15:05:34 2005 for JOnAS by  doxygen 1.3.9.1