| 1 21 22 package org.opensubsystems.patterns.dialoglayout.www; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.tagext.BodyContent ; 27 28 import org.opensubsystems.core.www.PageElementCacheTag; 29 import org.opensubsystems.core.www.TagUtils; 30 import org.opensubsystems.patterns.tabbeddialog.www.TabbedDialogTag; 31 32 41 public class ImageButtonControlTag extends PageElementCacheTag 42 { 43 45 48 private static final long serialVersionUID = 2954359974052918557L; 49 50 55 protected String m_strCssclass; 56 57 62 protected String m_strFakecssclass; 63 64 68 protected String m_strTitle; 69 70 73 protected String m_strType; 74 75 78 protected String m_strAccessKey; 79 80 83 protected String m_strOnclick; 84 85 88 protected String m_strDisabled; 89 90 94 protected String m_strFake; 95 96 102 protected String m_strFocus; 103 104 106 109 public ImageButtonControlTag() 110 { 111 super(); 112 113 m_strCssclass = "clsImageTextButton"; 115 m_strFakecssclass = null; 116 m_strDisabled = Boolean.FALSE.toString(); 117 m_strFake = Boolean.FALSE.toString(); 118 } 119 120 122 125 public int doStartTag( 126 ) throws JspException 127 { 128 return (EVAL_BODY_BUFFERED); 131 } 132 133 136 public int doEndTag( 137 ) throws JspException 138 { 139 StringBuffer sbHtml = new StringBuffer (); 140 BodyContent content = getBodyContent(); 141 String strContent = ""; 142 if (content != null) 143 { 144 strContent = content.getString(); 145 } 146 147 doEndTag(sbHtml, strContent); 148 149 TagUtils.write(pageContext, sbHtml.toString()); 150 151 if (isFocusedControl()) 152 { 153 cache(TabbedDialogTag.FOCUSED_CONTROL_ID, m_strId); 156 } 157 158 return (EVAL_PAGE); 159 } 160 161 170 public void doEndTag( 171 StringBuffer sbHtml, 172 String strContent 173 ) 174 { 175 if (isFakeButton()) 176 { 177 if (strContent == null) 178 { 179 strContent = ""; 180 } 181 182 String contextpath; 183 184 contextpath = ((HttpServletRequest )pageContext.getRequest()).getContextPath(); 185 194 sbHtml.append("<div"); 195 if ((m_strId != null) && (m_strId.length() > 0)) 198 { 199 sbHtml.append(" id=\""); 200 sbHtml.append(m_strId); 201 sbHtml.append("\""); 202 } 203 if ((m_strCssclass != null) && (m_strCssclass.length() > 0)) 204 { 205 sbHtml.append(" class=\""); 206 sbHtml.append(m_strCssclass); 207 sbHtml.append("\""); 208 } 209 sbHtml.append("><a HREF=\"#\""); 210 if ((m_strFakecssclass != null) && (m_strFakecssclass.length() > 0)) 211 { 212 sbHtml.append(" class=\""); 213 sbHtml.append(m_strFakecssclass); 214 sbHtml.append("\""); 215 } 216 if ((m_strOnclick != null) && (m_strOnclick.length() > 0)) 217 { 218 sbHtml.append(" onClick=\""); 219 sbHtml.append(m_strOnclick); 220 sbHtml.append(";return false;\""); 221 } 222 sbHtml.append("><img"); 223 if ((m_strId != null) && (m_strId.length() > 0)) 224 { 225 sbHtml.append(" id=\""); 226 sbHtml.append(m_strId); 227 sbHtml.append("img\""); 228 } 229 sbHtml.append(" SRC=\""); 230 sbHtml.append(contextpath); 231 sbHtml.append("/patterns/images/transparentbutton.gif\""); 232 if ((m_strTitle != null) && (m_strTitle.length() > 0)) 233 { 234 sbHtml.append(" alt=\""); 235 sbHtml.append(m_strTitle); 236 sbHtml.append("\""); 237 sbHtml.append(" title=\""); 238 sbHtml.append(m_strTitle); 239 sbHtml.append("\""); 240 } 241 sbHtml.append(">"); 242 formatButtonText(sbHtml, strContent); 244 sbHtml.append("</a></div>"); 245 } 246 else 247 { 248 253 254 if ((strContent == null) || (strContent.trim().length() == 0)) 255 { 256 strContent = "<span style=\"visibility: hidden;\">.</span>"; 260 } 261 262 sbHtml.append("<button id=\""); 264 sbHtml.append(m_strId); 265 sbHtml.append("\""); 266 if ((m_strCssclass != null) && (m_strCssclass.length() > 0)) 267 { 268 sbHtml.append(" class=\""); 269 sbHtml.append(m_strCssclass); 270 sbHtml.append("\""); 271 } 272 if ((m_strTitle != null) && (m_strTitle.length() > 0)) 273 { 274 sbHtml.append(" title=\""); 275 sbHtml.append(m_strTitle); 276 sbHtml.append("\""); 277 } 278 if ((m_strType != null) && (m_strType.length() > 0)) 279 { 280 sbHtml.append(" type=\""); 281 sbHtml.append(m_strType); 282 sbHtml.append("\""); 283 } 284 else 285 { 286 sbHtml.append(" type=\"button\""); 287 } 288 if (isDisabledButton()) 289 { 290 sbHtml.append(" disabled"); 291 } 292 if ((m_strAccessKey != null) && (m_strAccessKey.length() > 0)) 293 { 294 sbHtml.append(" accesskey=\""); 295 sbHtml.append(m_strAccessKey); 296 sbHtml.append("\""); 297 } 298 if ((m_strOnclick != null) && (m_strOnclick.length() > 0)) 299 { 300 sbHtml.append(" onClick=\""); 301 sbHtml.append(m_strOnclick); 302 sbHtml.append("\""); 303 } 304 sbHtml.append(">"); 305 306 formatButtonText(sbHtml, strContent); 308 309 sbHtml.append("</button>"); 310 } 311 } 312 313 316 public String getCssclass( 317 ) 318 { 319 return m_strCssclass; 320 } 321 322 325 public void setCssclass( 326 String strCssclass 327 ) 328 { 329 m_strCssclass = strCssclass; 330 } 331 332 335 public String getFakecssclass( 336 ) 337 { 338 return m_strFakecssclass; 339 } 340 341 345 public void setFakecssclass( 346 String strFakecssclass 347 ) 348 { 349 m_strFakecssclass = strFakecssclass; 350 } 351 352 356 public String getType( 357 ) 358 { 359 return m_strType; 360 } 361 362 366 public void setType( 367 String strType 368 ) 369 { 370 m_strType = strType; 371 } 372 373 377 public String getTitle( 378 ) 379 { 380 return m_strTitle; 381 } 382 383 386 public void setTitle( 387 String strTitle 388 ) 389 { 390 m_strTitle = strTitle; 391 } 392 393 396 public String getAccesskey( 397 ) 398 { 399 return m_strAccessKey; 400 } 401 402 406 public void setAccesskey( 407 String strAccessKey 408 ) 409 { 410 m_strAccessKey = strAccessKey; 411 } 412 413 416 public String getOnclick() 417 { 418 return m_strOnclick; 419 } 420 421 424 public void setOnclick( 425 String strOnclick 426 ) 427 { 428 if ((strOnclick != null) && (strOnclick.length() > 0)) 429 { 430 if (strOnclick.startsWith(CACHE_INDICATOR)) 431 { 432 String strTemp; 434 435 strTemp = getCachedContent(strOnclick.substring(CACHE_INDICATOR.length())); 436 if ((strTemp != null) && (strTemp.length() > 0)) 437 { 438 strOnclick = strTemp; 439 } 440 } 441 } 442 m_strOnclick = strOnclick; 443 } 444 445 449 public String getDisabled( 450 ) 451 { 452 return m_strDisabled; 453 } 454 455 459 public void setDisabled( 460 String strDisabled 461 ) 462 { 463 m_strDisabled = strDisabled; 464 } 465 466 470 public void setDisabled( 471 boolean bDisabled 472 ) 473 { 474 m_strDisabled = Boolean.toString(bDisabled); 475 } 476 477 480 public boolean isDisabledButton( 481 ) 482 { 483 return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDisabled)) 484 || ("1".equals(m_strDisabled))); 485 } 486 487 492 public String getFake( 493 ) 494 { 495 return m_strFake; 496 } 497 498 503 public void setFake( 504 String strFake 505 ) 506 { 507 m_strFake = strFake; 508 } 509 510 515 public void setFake( 516 boolean bFake 517 ) 518 { 519 m_strFake = Boolean.toString(bFake); 520 } 521 522 527 public boolean isFakeButton( 528 ) 529 { 530 return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strFake)) 531 || ("1".equals(m_strFake))); 532 } 533 534 538 public String getFocus() 539 { 540 return m_strFocus; 541 } 542 543 547 public void setFocus( 548 String strFocus 549 ) 550 { 551 m_strFocus = strFocus; 552 } 553 554 558 public void setFocus( 559 boolean bFocus 560 ) 561 { 562 m_strFocus = Boolean.toString(bFocus); 563 } 564 565 569 public boolean isFocusedControl( 570 ) 571 { 572 return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strFocus)) 573 || ("1".equals(m_strFocus))); 574 } 575 576 582 protected void formatButtonText( 583 StringBuffer sbHtml, 584 String strContent 585 ) 586 { 587 StringBuffer sbHtmlTemp = new StringBuffer (); 588 int iCharIndex = -1; 589 590 if ((m_strAccessKey != null) && (m_strAccessKey.length() > 0)) 594 { 595 iCharIndex = strContent.indexOf(m_strAccessKey); 596 if (iCharIndex == -1) 597 { 598 iCharIndex = strContent.toLowerCase().indexOf(m_strAccessKey.toLowerCase()); 599 } 600 } 601 if (iCharIndex == -1) 602 { 603 if ((m_strAccessKey != null) && (m_strAccessKey.length() > 0)) 604 { 605 sbHtmlTemp.append("\n<!-- Accesskey '"); 608 sbHtmlTemp.append(m_strAccessKey); 609 sbHtmlTemp.append("' was not found within the image button content for "); 610 sbHtmlTemp.append(m_strId); 611 sbHtmlTemp.append(" -->\n"); 612 } 613 } 614 else 615 { 616 sbHtmlTemp.append(strContent.substring(0, iCharIndex)); 619 sbHtmlTemp.append("<u>"); 620 sbHtmlTemp.append(strContent.charAt(iCharIndex)); 621 sbHtmlTemp.append("</u>"); 622 sbHtmlTemp.append(strContent.substring(iCharIndex + 1, strContent.length())); 623 strContent = sbHtmlTemp.toString(); 624 } 625 sbHtml.append(strContent); 626 } 627 } 628 | Popular Tags |