1 21 22 package org.opensubsystems.patterns.tabbeddialog.www; 23 24 import java.util.List ; 25 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.tagext.BodyContent ; 28 29 import org.opensubsystems.core.www.BlockElementTag; 30 import org.opensubsystems.core.www.TagUtils; 31 32 42 public class TabbedDialogTabTag extends BlockElementTag 43 { 44 46 49 public static final String TABBED_DIALOG_FORM_TAG = "</form>"; 50 51 53 56 private static final long serialVersionUID = 1918742461661215567L; 57 58 61 protected String m_strHeader; 62 63 67 protected String m_strActive; 68 69 72 protected String m_strImg; 73 74 78 protected String m_strAccessKey; 79 80 83 protected String m_strOnFocus; 84 85 87 90 public TabbedDialogTabTag() 91 { 92 super("clsTab", BlockElementTag.DIV_BLOCK_ELEMENT); 93 94 m_strHeader = null; 95 m_strActive = Boolean.FALSE.toString(); 96 m_strImg = null; 97 m_strAccessKey = ""; 98 m_strOnFocus = ""; 99 } 100 101 103 106 public int doStartTag( 107 ) throws JspException 108 { 109 StringBuffer sbHtml = new StringBuffer (); 110 StringBuffer sbHtmlTemp = new StringBuffer (); 111 112 Object objTemp; 113 String strTabbedDialogId; 114 String strHeaderUnderlined = m_strHeader; 115 String strTabbedDialogJSFunction; 116 String strActiveTab = null; 117 118 objTemp = pageContext.getAttribute(TabbedDialogTag.ACTIVE_TABBED_DIALOG_ID); 119 if (objTemp == null) 120 { 121 throw new JspException ("Cannot find tabbed dialog id on the page. Probable" + 122 " cause is that the tabbed dialog open tag is missing."); 123 } 124 strTabbedDialogId = (String )objTemp; 125 126 objTemp = getCachedContent(TabbedDialogTag.TABBED_DIALOG_ONSWITCH_JSFUNCTION, 127 false).trim(); 128 if (objTemp == null) 129 { 130 throw new JspException ("Cannot find javascript function called onswitch. Probable" + 131 " cause is that the scrollable table open tag is missing."); 132 } 133 strTabbedDialogJSFunction = (String )objTemp; 134 135 strActiveTab = pageContext.getRequest().getParameter("activetab"); 138 if (strActiveTab == null) 139 { 140 strActiveTab = (String )pageContext.getRequest().getAttribute("activetab"); 141 } 142 143 144 if ((m_strHeader != null) && (m_strHeader.length() > 0)) 146 { 147 int iCharIndex = -1; 148 if ((m_strAccessKey != null) && (m_strAccessKey.length() > 0)) 152 { 153 iCharIndex = m_strHeader.indexOf(m_strAccessKey); 154 if (iCharIndex == -1) 155 { 156 iCharIndex = m_strHeader.toLowerCase().indexOf(m_strAccessKey.toLowerCase()); 157 } 158 } 159 if (iCharIndex == -1) 160 { 161 if ((m_strAccessKey != null) && (m_strAccessKey.length() > 0)) 162 { 163 sbHtmlTemp.append("<!-- Accesskey '"); 166 sbHtmlTemp.append(m_strAccessKey); 167 sbHtmlTemp.append("' was not found within the label content for "); 168 sbHtmlTemp.append(strTabbedDialogId); 169 sbHtmlTemp.append(m_strId); 170 sbHtmlTemp.append(" -->"); 171 } 172 } 173 else 174 { 175 sbHtmlTemp.append(m_strHeader.substring(0, iCharIndex)); 178 sbHtmlTemp.append("<u>"); 179 sbHtmlTemp.append(m_strHeader.charAt(iCharIndex)); 180 sbHtmlTemp.append("</u>"); 181 sbHtmlTemp.append(m_strHeader.substring(iCharIndex + 1, m_strHeader.length())); 182 strHeaderUnderlined = sbHtmlTemp.toString(); 183 sbHtmlTemp.delete(0, sbHtmlTemp.length()); 184 } 185 } 186 187 195 196 sbHtml.append("<div id=\""); 198 sbHtml.append(strTabbedDialogId); 199 sbHtml.append(m_strId); 200 sbHtml.append("header\""); 201 if ((m_strCssclass != null) && (m_strCssclass.length() > 0)) 202 { 203 sbHtml.append(" class=\""); 204 sbHtml.append(m_strCssclass); 205 sbHtml.append("Header"); 206 if (((isActiveTab()) && ((strActiveTab == null) 207 || ((strActiveTab != null) && (strActiveTab.length() == 0)))) 208 || ((strActiveTab != null) && (strActiveTab.equals(m_strId)))) 209 { 210 sbHtml.append("Active"); 211 } 212 sbHtml.append("\""); 213 } 214 sbHtml.append(">\n"); 215 216 sbHtml.append("<a HREF=\"#"); 219 sbHtml.append(m_strId); 220 sbHtml.append("\" rel=\"Subsection\" rev=\"Subsection\""); 221 if ((m_strAccessKey != null) && (m_strAccessKey.length() > 0)) 224 { 225 sbHtml.append(" accesskey=\""); 226 sbHtml.append(m_strAccessKey); 227 sbHtml.append("\""); 228 } 229 sbHtml.append(" onfocus=\"switchTabTo('"); 231 sbHtml.append(strTabbedDialogId); 232 sbHtml.append(m_strId); 233 sbHtml.append("header', '"); 234 sbHtml.append(strTabbedDialogId); 235 sbHtml.append("', "); 236 sbHtml.append(strTabbedDialogJSFunction); 237 sbHtml.append(");dialogHelp(event);"); 238 if ((m_strOnFocus != null) && (m_strOnFocus.length() > 0)) 240 { 241 sbHtml.append(m_strOnFocus); 242 } 243 sbHtml.append("\">"); 244 if ((m_strImg != null) && (m_strImg.length() > 0)) 246 { 247 sbHtml.append("<img SRC=\""); 248 sbHtml.append(m_strImg); 249 sbHtml.append("\" border=\"0\" alt=\"\""); 250 if ((m_strHeader != null) && (m_strHeader.length() > 0)) 251 { 252 sbHtml.append(" title=\""); 253 sbHtml.append(m_strHeader); 254 sbHtml.append("\""); 255 } 256 sbHtml.append(" align=\"middle\">"); 257 if ((m_strHeader != null) && (m_strHeader.length() > 0)) 258 { 259 sbHtml.append(" "); 260 } 261 } 262 263 if ((m_strHeader != null) && (m_strHeader.length() > 0)) 265 { 266 sbHtml.append(strHeaderUnderlined); 267 } 268 269 sbHtml.append("</a>\n"); 270 sbHtml.append(sbHtmlTemp); 272 sbHtml.append("</div>\n"); 274 275 sbHtml.append("<div id=\""); 277 sbHtml.append(strTabbedDialogId); 278 sbHtml.append(m_strId); 279 sbHtml.append("\""); 280 if ((m_strCssclass != null) && (m_strCssclass.length() > 0)) 281 { 282 sbHtml.append(" class=\""); 283 sbHtml.append(m_strCssclass); 284 sbHtml.append("Body"); 285 if (((isActiveTab()) && ((strActiveTab == null) 286 || ((strActiveTab != null) && (strActiveTab.length() == 0)))) 287 || ((strActiveTab != null) && (strActiveTab.equals(m_strId)))) 288 { 289 sbHtml.append("Active"); 290 } 291 sbHtml.append("\""); 292 } 293 sbHtml.append(">"); 294 295 TagUtils.write(pageContext, sbHtml.toString()); 296 297 return (EVAL_BODY_BUFFERED); 298 } 299 300 303 public int doEndTag( 304 ) throws JspException 305 { 306 StringBuffer sbHtml = new StringBuffer (); 307 Object objTemp; 308 String strTabbedDialogId; 309 310 BodyContent content = getBodyContent(); 313 StringBuffer sbContent = new StringBuffer (); 314 315 objTemp = pageContext.getAttribute(TabbedDialogTag.ACTIVE_TABBED_DIALOG_ID); 316 if (objTemp == null) 317 { 318 throw new JspException ("Cannot find tabbed dialog id on the page. Probable" + 319 " cause is that the tabbed dialog open tag is missing."); 320 } 321 strTabbedDialogId = (String )objTemp; 322 323 List items = getCachedContentElements(TabbedDialogTag.FOCUSED_CONTROL_ID, 326 true); 327 328 if (!items.isEmpty()) 329 { 330 String strControlId; 331 332 if (items.size() > 1) 333 { 334 sbHtml.append("<!-- Multiple controls were set as focus in" + 335 " this tab, using only the first one-->\n"); 336 } 337 strControlId = items.get(0).toString(); 338 339 sbHtml.append("<input id=\""); 340 sbHtml.append(strTabbedDialogId); 341 sbHtml.append(m_strId); 342 sbHtml.append("focus\" type=\"hidden\" value=\""); 343 sbHtml.append(strControlId); 344 sbHtml.append("\">\n"); 345 } 346 347 if (content != null) 348 { 349 sbContent.append(content.getString()); 350 351 int iIndex; 352 int iFormIndex = 0; 353 int iNextIndex; 354 boolean bHasMoreForms = false; 355 356 360 iIndex = sbContent.toString().toLowerCase().indexOf(TABBED_DIALOG_FORM_TAG); 362 if (iIndex != -1) 363 { 364 do 365 { 366 iNextIndex = sbContent.toString().toLowerCase().indexOf( 371 TABBED_DIALOG_FORM_TAG, iIndex + 1); 372 if (!bHasMoreForms) 375 { 376 bHasMoreForms = (iNextIndex != -1); 377 } 378 379 sbHtml.append("<input id=\"activetab_"); 382 sbHtml.append(m_strId); 383 if (bHasMoreForms) 384 { 385 sbHtml.append("_"); 386 sbHtml.append(iFormIndex); 387 } 388 sbHtml.append("\" type=\"hidden\""); 389 sbHtml.append(" name=\"activetab_"); 390 sbHtml.append(m_strId); 391 if (bHasMoreForms) 392 { 393 sbHtml.append("_"); 394 sbHtml.append(iFormIndex++); 395 } 396 sbHtml.append("\" value=\""); 397 sbHtml.append(m_strId); 398 sbHtml.append("\">\n"); 399 400 sbContent.insert(iIndex, sbHtml.toString()); 402 iIndex = iNextIndex + sbHtml.length(); 404 sbHtml.delete(0, sbHtml.length()); 406 } 407 while (iNextIndex != -1); 408 } 409 else 410 { 411 sbContent.append(sbHtml); 414 } 415 416 sbContent.append("</div>"); 417 } 418 419 TagUtils.write(pageContext, sbContent.toString()); 421 422 return (EVAL_PAGE); 423 } 424 425 428 public String getHeader( 429 ) 430 { 431 return m_strHeader; 432 } 433 434 438 public String getActive( 439 ) 440 { 441 return m_strActive; 442 } 443 444 447 public String getImg() 448 { 449 return m_strImg; 450 } 451 452 455 public void setHeader( 456 String strHeader 457 ) 458 { 459 m_strHeader = strHeader; 460 } 461 462 466 public void setActive( 467 String strActive 468 ) 469 { 470 m_strActive = strActive; 471 } 472 473 477 public void setActive( 478 boolean bActive 479 ) 480 { 481 m_strActive = Boolean.toString(bActive); 482 } 483 484 487 public void setImg( 488 String strImg 489 ) 490 { 491 m_strImg = strImg; 492 } 493 494 497 public boolean isActiveTab( 498 ) 499 { 500 return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strActive)) 501 || ("1".equals(m_strActive))); 502 } 503 504 507 public String getAccesskey( 508 ) 509 { 510 return m_strAccessKey; 511 } 512 513 516 public void setAccesskey( 517 String strAccessKey 518 ) 519 { 520 m_strAccessKey = strAccessKey; 521 } 522 523 526 public String getOnfocus( 527 ) 528 { 529 return m_strOnFocus; 530 } 531 532 535 public void setOnfocus( 536 String strOnFocus 537 ) 538 { 539 m_strOnFocus = strOnFocus; 540 } 541 } 542 | Popular Tags |