JonasButtonTag.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: JonasButtonTag.java,v 1.7 2004/03/19 14:31:50 sauthieg Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.taglib;
00027 
00028 import java.lang.reflect.InvocationTargetException;
00029 
00030 import javax.servlet.jsp.JspException;
00031 
00032 import org.apache.commons.beanutils.PropertyUtils;
00033 import org.apache.struts.taglib.html.LinkTag;
00034 import org.apache.struts.util.RequestUtils;
00035 import org.apache.struts.util.ResponseUtils;
00036 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
00037 
00041 public class JonasButtonTag extends LinkTag {
00042 
00043 // ----------------------------------------------------- Manifest Constants
00044 
00045     private static final String s_ImageBorder = "dot.gif";
00046 
00047 // ----------------------------------------------------- Instance Variables
00048 
00049     protected String ms_PathImage = null;
00050     protected String ms_LastStyleClass = null;
00051     protected String ms_StyleClassButton = "btn";
00052 
00053 // ------------------------------------------------------------- Properties
00054 
00055     private int widthBorder = 1;
00056     private int heightBorder = 1;
00057     private String imagesDir = null;
00058     private String styleClassBorderLight = "btnBorderLight";
00059     private String styleClassBorderShadow = "btnBorderShadow";
00060     private String styleClassBackground = "btn";
00061     private String styleClassDisabled = "btnDisabled";
00062     private String disabledName = null;
00063     private String disabledProperty = null;
00064     private String disabledValueEqual = null;
00065     private String disabledValueNotEqual = null;
00066 
00067     public int getHeightBorder() {
00068         return heightBorder;
00069     }
00070 
00071     public void setHeightBorder(int heightBorder) {
00072         this.heightBorder = heightBorder;
00073     }
00074 
00075     public String getImagesDir() {
00076         return imagesDir;
00077     }
00078 
00079     public void setImagesDir(String imagesDir) {
00080         this.imagesDir = imagesDir;
00081     }
00082 
00083     public int getWidthBorder() {
00084         return widthBorder;
00085     }
00086 
00087     public void setWidthBorder(int widthBorder) {
00088         this.widthBorder = widthBorder;
00089     }
00090 
00091     public String getStyleClassBorderLight() {
00092         return styleClassBorderLight;
00093     }
00094 
00095     public void setStyleClassBorderLight(String styleClassBorderLight) {
00096         this.styleClassBorderLight = styleClassBorderLight;
00097     }
00098 
00099     public String getStyleClassBorderShadow() {
00100         return styleClassBorderShadow;
00101     }
00102 
00103     public void setStyleClassBorderShadow(String styleClassBorderShadow) {
00104         this.styleClassBorderShadow = styleClassBorderShadow;
00105     }
00106 
00107     public String getStyleClassBackground() {
00108         return styleClassBackground;
00109     }
00110 
00111     public void setStyleClassBackground(String styleClassBackground) {
00112         this.styleClassBackground = styleClassBackground;
00113     }
00114 
00115     public String getStyleClassDisabled() {
00116         return styleClassDisabled;
00117     }
00118 
00119     public void setStyleClassDisabled(String styleClassDisabled) {
00120         this.styleClassDisabled = styleClassDisabled;
00121     }
00122 
00123     public String getDisabledName() {
00124         return disabledName;
00125     }
00126 
00127     public void setDisabledName(String disabledName) {
00128         this.disabledName = disabledName;
00129     }
00130 
00131     public String getDisabledProperty() {
00132         return disabledProperty;
00133     }
00134 
00135     public void setDisabledProperty(String disabledProperty) {
00136         this.disabledProperty = disabledProperty;
00137     }
00138 
00139     public String getDisabledValueEqual() {
00140         return disabledValueEqual;
00141     }
00142 
00143     public void setDisabledValueEqual(String disabledValueEqual) {
00144         this.disabledValueEqual = disabledValueEqual;
00145     }
00146 
00147     public String getDisabledValueNotEqual() {
00148         return disabledValueNotEqual;
00149     }
00150 
00151     public void setDisabledValueNotEqual(String disabledValueNotEqual) {
00152         this.disabledValueNotEqual = disabledValueNotEqual;
00153     }
00154 
00155 // ------------------------------------------------------------- Public methods
00156 
00162     public int doStartTag()
00163         throws JspException {
00164 
00165         // Test if button disabled
00166         boolean bDisabled = getDisabled();
00167         if ((getDisabledName() != null) &&
00168             ((getDisabledValueEqual() != null) || (getDisabledValueNotEqual() != null))) {
00169             String sValue = lookupProperty(getDisabledName(), getDisabledProperty());
00170             if (getDisabledValueEqual() != null) {
00171                 bDisabled = getDisabledValueEqual().equals(sValue);
00172             }
00173             else {
00174                 bDisabled = !getDisabledValueNotEqual().equals(sValue);
00175             }
00176         }
00177 
00178         // Force style class to the Link Tag
00179         ms_LastStyleClass = getStyleClass();
00180         if (getStyleClass() == null) {
00181             setStyleClass(ms_StyleClassButton);
00182         }
00183         // Prepare path image
00184         makePathImage();
00185         // Add the begining of render button
00186         StringBuffer sb = new StringBuffer(
00187             "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
00188         sb.append(prepareBorderTop());
00189         sb.append("<tr>");
00190         sb.append(prepareBorderColumn(styleClassBorderLight));
00191         sb.append("<td nowrap class=\"");
00192         if (bDisabled == false) {
00193             sb.append(styleClassBackground);
00194         }
00195         else {
00196             sb.append(styleClassDisabled);
00197         }
00198         sb.append("\">");
00199         ResponseUtils.write(pageContext, sb.toString());
00200 
00201         if (bDisabled == false) {
00202             // Add link if enabled
00203             return (super.doStartTag());
00204         }
00205         return (EVAL_BODY_BUFFERED);
00206     }
00207 
00213     public int doEndTag()
00214         throws JspException {
00215         StringBuffer sb = new StringBuffer();
00216         int iRet = EVAL_PAGE;
00217 
00218         // If body text exist pre-fix and post-fix with space
00219         if (text != null) {
00220             StringBuffer sbText = new StringBuffer("&nbsp;");
00221             sbText.append(text);
00222             sbText.append("&nbsp;");
00223             text = sbText.toString();
00224         }
00225 
00226         if (getDisabled() == false) {
00227             // Add link if enabled
00228             iRet = super.doEndTag();
00229         }
00230         else {
00231             sb.append(text);
00232         }
00233 
00234         // Add the end of render button
00235         sb.append("</td>");
00236         sb.append(prepareBorderColumn(styleClassBorderShadow));
00237         sb.append("</tr>");
00238         sb.append(prepareBorderBottom());
00239         sb.append("</table>");
00240         ResponseUtils.write(pageContext, sb.toString());
00241 
00242         // Force last style
00243         setStyleClass(ms_LastStyleClass);
00244         ms_LastStyleClass = null;
00245 
00246         return (iRet);
00247     }
00248 
00249     public String getImagesRoot() {
00250         String sImagesRoot = null;
00251         WhereAreYou oWhere = getWhereAreYouInstance();
00252         if (oWhere != null) {
00253             sImagesRoot = oWhere.getImagesRoot();
00254         }
00255         return sImagesRoot;
00256     }
00257 
00258     public void release() {
00259         super.release();
00260         ms_PathImage = null;
00261         imagesDir = null;
00262         ms_StyleClassButton = null;
00263         styleClassBorderLight = null;
00264         styleClassBorderShadow = null;
00265         styleClassBackground = null;
00266         styleClassDisabled = null;
00267     }
00268 
00269 // --------------------------------------------------------- Protected Methods
00270     protected void makePathImage() {
00271         // Prepare image separator
00272         if (imagesDir != null) {
00273             ms_PathImage = imagesDir + "/" + s_ImageBorder;
00274         }
00275         else if (getImagesRoot() != null) {
00276             ms_PathImage = getImagesRoot() + "/" + s_ImageBorder;
00277         }
00278         else {
00279             ms_PathImage = s_ImageBorder;
00280         }
00281     }
00282 
00287     protected String prepareImage() {
00288         StringBuffer sb = new StringBuffer("<img src=\"");
00289         sb.append(ms_PathImage);
00290         sb.append("\" width=\"");
00291         sb.append(widthBorder);
00292         sb.append("\" height=\"");
00293         sb.append(heightBorder);
00294         sb.append("\" border=\"0\">");
00295         return sb.toString();
00296     }
00297 
00302     protected String prepareBorderColumn(String ps_Class) {
00303         StringBuffer sb = new StringBuffer("<td width=\"");
00304         sb.append(widthBorder);
00305         sb.append("\" height=\"");
00306         sb.append(heightBorder);
00307         sb.append("\" class=\"");
00308         //btnBorderLight
00309         sb.append(ps_Class);
00310         sb.append("\">");
00311         sb.append(prepareImage());
00312         sb.append("</td>");
00313         return sb.toString();
00314     }
00315 
00316     protected String prepareBorderTop() {
00317         StringBuffer sb = new StringBuffer("<tr>");
00318         sb.append(prepareBorderColumn(styleClassBorderLight));
00319         sb.append(prepareBorderColumn(styleClassBorderLight));
00320         sb.append(prepareBorderColumn(styleClassBorderLight));
00321         sb.append("</tr>");
00322         return sb.toString();
00323     }
00324 
00325     protected String prepareBorderBottom() {
00326         StringBuffer sb = new StringBuffer("<tr>");
00327         sb.append(prepareBorderColumn(styleClassBorderLight));
00328         sb.append(prepareBorderColumn(styleClassBorderShadow));
00329         sb.append(prepareBorderColumn(styleClassBorderShadow));
00330         sb.append("</tr>");
00331         return sb.toString();
00332     }
00333 
00334     protected WhereAreYou getWhereAreYouInstance() {
00335         return (WhereAreYou) pageContext.getSession().getAttribute(WhereAreYou.SESSION_NAME);
00336     }
00337 
00338     protected String lookupProperty(String beanName, String property)
00339         throws JspException {
00340 
00341         Object bean = RequestUtils.lookup(this.pageContext, beanName, null);
00342         if (bean == null) {
00343             throw new JspException(messages.getMessage("getter.bean", beanName));
00344         }
00345         if (property == null) {
00346             return bean.toString();
00347         }
00348         try {
00349             return (PropertyUtils.getProperty(bean, property)).toString();
00350         }
00351         catch (IllegalAccessException e) {
00352             throw new JspException(messages.getMessage("getter.access", property, beanName));
00353 
00354         }
00355         catch (InvocationTargetException e) {
00356             Throwable t = e.getTargetException();
00357             throw new JspException(messages.getMessage("getter.result", property, t.toString()));
00358 
00359         }
00360         catch (NoSuchMethodException e) {
00361             throw new JspException(messages.getMessage("getter.method", property, beanName));
00362         }
00363     }
00364 }

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