1 25 26 package org.objectweb.jonas.webapp.taglib; 27 28 import java.lang.reflect.InvocationTargetException ; 29 30 import javax.servlet.jsp.JspException ; 31 32 import org.apache.commons.beanutils.PropertyUtils; 33 import org.apache.struts.taglib.html.LinkTag; 34 import org.apache.struts.taglib.TagUtils; 35 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou; 36 37 40 public class JonasButtonTag extends LinkTag { 41 42 44 private static final String s_ImageBorder = "dot.gif"; 45 46 48 protected String ms_PathImage = null; 49 protected String ms_LastStyleClass = null; 50 protected String ms_StyleClassButton = "btn"; 51 52 54 private int widthBorder = 1; 55 private int heightBorder = 1; 56 private String imagesDir = null; 57 private String styleClassBorderLight = "btnBorderLight"; 58 private String styleClassBorderShadow = "btnBorderShadow"; 59 private String styleClassBackground = "btn"; 60 private String styleClassDisabled = "btnDisabled"; 61 private String disabledName = null; 62 private String disabledProperty = null; 63 private String disabledValueEqual = null; 64 private String disabledValueNotEqual = null; 65 66 public int getHeightBorder() { 67 return heightBorder; 68 } 69 70 public void setHeightBorder(int heightBorder) { 71 this.heightBorder = heightBorder; 72 } 73 74 public String getImagesDir() { 75 return imagesDir; 76 } 77 78 public void setImagesDir(String imagesDir) { 79 this.imagesDir = imagesDir; 80 } 81 82 public int getWidthBorder() { 83 return widthBorder; 84 } 85 86 public void setWidthBorder(int widthBorder) { 87 this.widthBorder = widthBorder; 88 } 89 90 public String getStyleClassBorderLight() { 91 return styleClassBorderLight; 92 } 93 94 public void setStyleClassBorderLight(String styleClassBorderLight) { 95 this.styleClassBorderLight = styleClassBorderLight; 96 } 97 98 public String getStyleClassBorderShadow() { 99 return styleClassBorderShadow; 100 } 101 102 public void setStyleClassBorderShadow(String styleClassBorderShadow) { 103 this.styleClassBorderShadow = styleClassBorderShadow; 104 } 105 106 public String getStyleClassBackground() { 107 return styleClassBackground; 108 } 109 110 public void setStyleClassBackground(String styleClassBackground) { 111 this.styleClassBackground = styleClassBackground; 112 } 113 114 public String getStyleClassDisabled() { 115 return styleClassDisabled; 116 } 117 118 public void setStyleClassDisabled(String styleClassDisabled) { 119 this.styleClassDisabled = styleClassDisabled; 120 } 121 122 public String getDisabledName() { 123 return disabledName; 124 } 125 126 public void setDisabledName(String disabledName) { 127 this.disabledName = disabledName; 128 } 129 130 public String getDisabledProperty() { 131 return disabledProperty; 132 } 133 134 public void setDisabledProperty(String disabledProperty) { 135 this.disabledProperty = disabledProperty; 136 } 137 138 public String getDisabledValueEqual() { 139 return disabledValueEqual; 140 } 141 142 public void setDisabledValueEqual(String disabledValueEqual) { 143 this.disabledValueEqual = disabledValueEqual; 144 } 145 146 public String getDisabledValueNotEqual() { 147 return disabledValueNotEqual; 148 } 149 150 public void setDisabledValueNotEqual(String disabledValueNotEqual) { 151 this.disabledValueNotEqual = disabledValueNotEqual; 152 } 153 154 156 161 public int doStartTag() 162 throws JspException { 163 164 boolean bDisabled = getDisabled(); 166 TagUtils tagUtils = TagUtils.getInstance(); 167 if ((getDisabledName() != null) && 168 ((getDisabledValueEqual() != null) || (getDisabledValueNotEqual() != null))) { 169 String sValue = lookupProperty(getDisabledName(), getDisabledProperty()); 170 if (getDisabledValueEqual() != null) { 171 bDisabled = getDisabledValueEqual().equals(sValue); 172 } else { 173 bDisabled = !getDisabledValueNotEqual().equals(sValue); 174 } 175 } 176 177 ms_LastStyleClass = getStyleClass(); 179 if (getStyleClass() == null) { 180 setStyleClass(ms_StyleClassButton); 181 } 182 makePathImage(); 184 StringBuffer sb = new StringBuffer ( 186 "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"); 187 sb.append(prepareBorderTop()); 188 sb.append("<tr>"); 189 sb.append(prepareBorderColumn(styleClassBorderLight)); 190 sb.append("<td nowrap class=\""); 191 if (bDisabled == false) { 192 sb.append(styleClassBackground); 193 } else { 194 sb.append(styleClassDisabled); 195 } 196 sb.append("\">"); 197 tagUtils.write(pageContext, sb.toString()); 198 199 if (bDisabled == false) { 200 return (super.doStartTag()); 202 } 203 return (EVAL_BODY_BUFFERED); 204 } 205 206 211 public int doEndTag() 212 throws JspException { 213 StringBuffer sb = new StringBuffer (); 214 int iRet = EVAL_PAGE; 215 TagUtils tagUtils = TagUtils.getInstance(); 216 217 if (text != null) { 219 StringBuffer sbText = new StringBuffer (" "); 220 sbText.append(text); 221 sbText.append(" "); 222 text = sbText.toString(); 223 } 224 225 if (getDisabled() == false) { 226 iRet = super.doEndTag(); 228 } else { 229 sb.append(text); 230 } 231 232 sb.append("</td>"); 234 sb.append(prepareBorderColumn(styleClassBorderShadow)); 235 sb.append("</tr>"); 236 sb.append(prepareBorderBottom()); 237 sb.append("</table>"); 238 tagUtils.write(pageContext, sb.toString()); 239 240 setStyleClass(ms_LastStyleClass); 242 ms_LastStyleClass = null; 243 244 return (iRet); 245 } 246 247 public String getImagesRoot() { 248 String sImagesRoot = null; 249 WhereAreYou oWhere = getWhereAreYouInstance(); 250 if (oWhere != null) { 251 sImagesRoot = oWhere.getImagesRoot(); 252 } 253 return sImagesRoot; 254 } 255 256 public void release() { 257 super.release(); 258 ms_PathImage = null; 259 imagesDir = null; 260 ms_StyleClassButton = null; 261 styleClassBorderLight = null; 262 styleClassBorderShadow = null; 263 styleClassBackground = null; 264 styleClassDisabled = null; 265 } 266 267 protected void makePathImage() { 269 if (imagesDir != null) { 271 ms_PathImage = imagesDir + "/" + s_ImageBorder; 272 } 273 else if (getImagesRoot() != null) { 274 ms_PathImage = getImagesRoot() + "/" + s_ImageBorder; 275 } 276 else { 277 ms_PathImage = s_ImageBorder; 278 } 279 } 280 281 285 protected String prepareImage() { 286 StringBuffer sb = new StringBuffer ("<img SRC=\""); 287 sb.append(ms_PathImage); 288 sb.append("\" width=\""); 289 sb.append(widthBorder); 290 sb.append("\" height=\""); 291 sb.append(heightBorder); 292 sb.append("\" border=\"0\">"); 293 return sb.toString(); 294 } 295 296 300 protected String prepareBorderColumn(String ps_Class) { 301 StringBuffer sb = new StringBuffer ("<td width=\""); 302 sb.append(widthBorder); 303 sb.append("\" height=\""); 304 sb.append(heightBorder); 305 sb.append("\" class=\""); 306 sb.append(ps_Class); 308 sb.append("\">"); 309 sb.append(prepareImage()); 310 sb.append("</td>"); 311 return sb.toString(); 312 } 313 314 protected String prepareBorderTop() { 315 StringBuffer sb = new StringBuffer ("<tr>"); 316 sb.append(prepareBorderColumn(styleClassBorderLight)); 317 sb.append(prepareBorderColumn(styleClassBorderLight)); 318 sb.append(prepareBorderColumn(styleClassBorderLight)); 319 sb.append("</tr>"); 320 return sb.toString(); 321 } 322 323 protected String prepareBorderBottom() { 324 StringBuffer sb = new StringBuffer ("<tr>"); 325 sb.append(prepareBorderColumn(styleClassBorderLight)); 326 sb.append(prepareBorderColumn(styleClassBorderShadow)); 327 sb.append(prepareBorderColumn(styleClassBorderShadow)); 328 sb.append("</tr>"); 329 return sb.toString(); 330 } 331 332 protected WhereAreYou getWhereAreYouInstance() { 333 return (WhereAreYou) pageContext.getSession().getAttribute(WhereAreYou.SESSION_NAME); 334 } 335 336 protected String lookupProperty(String beanName, String property) 337 throws JspException { 338 339 TagUtils tagUtils = TagUtils.getInstance(); 340 Object bean = tagUtils.lookup(this.pageContext, beanName, null); 341 if (bean == null) { 342 throw new JspException (messages.getMessage("getter.bean", beanName)); 343 } 344 if (property == null) { 345 return bean.toString(); 346 } 347 try { 348 return (PropertyUtils.getProperty(bean, property)).toString(); 349 } catch (IllegalAccessException e) { 350 throw new JspException (messages.getMessage("getter.access", property, beanName)); 351 352 } catch (InvocationTargetException e) { 353 Throwable t = e.getTargetException(); 354 throw new JspException (messages.getMessage("getter.result", property, t.toString())); 355 356 } catch (NoSuchMethodException e) { 357 throw new JspException (messages.getMessage("getter.method", property, beanName)); 358 } 359 } 360 } | Popular Tags |