1 18 package org.apache.beehive.netui.tags.html; 19 20 import org.apache.beehive.netui.tags.AbstractClassicTag; 21 import org.apache.beehive.netui.tags.IAttributeConsumer; 22 import org.apache.beehive.netui.tags.IHtmlAttrs; 23 import org.apache.beehive.netui.tags.TagConfig; 24 import org.apache.beehive.netui.tags.javascript.ScriptRequestState; 25 import org.apache.beehive.netui.tags.rendering.AbstractHtmlControlState; 26 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState; 27 import org.apache.beehive.netui.util.Bundle; 28 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.jsp.JspException ; 31 import javax.servlet.jsp.tagext.Tag ; 32 33 41 abstract public class HtmlBaseTag extends AbstractClassicTag 42 implements HtmlConstants, IAttributeConsumer, IHtmlAttrs 43 { 44 45 50 abstract protected AbstractHtmlState getState(); 51 52 54 63 public void setStyle(String style) 64 { 65 if ("".equals(style)) 66 return; 67 AbstractHtmlState tsh = getState(); 68 tsh.style = style; 69 } 70 71 80 public void setStyleClass(String styleClass) 81 { 82 if ("".equals(styleClass)) 83 return; 84 AbstractHtmlState tsh = getState(); 85 tsh.styleClass = styleClass; 86 } 87 88 132 public void setTagId(String tagId) 133 throws JspException 134 { 135 AbstractHtmlState tsh = getState(); 138 tsh.id = setRequiredValueAttribute(tagId, "tagId"); 139 } 140 141 148 public String getTagId() 149 { 150 AbstractHtmlState tsh = getState(); 151 return tsh.id; 152 } 153 154 163 public void setTitle(String title) 164 { 165 AbstractHtmlState tsh = getState(); 166 tsh.registerAttribute(AbstractHtmlState.ATTR_GENERAL, TITLE, title); 167 } 168 169 170 180 public void setLang(String lang) 181 { 182 AbstractHtmlState tsh = getState(); 183 tsh.registerAttribute(AbstractHtmlState.ATTR_GENERAL, LANG, lang); 184 } 185 186 195 public void setDir(String dir) 196 { 197 AbstractHtmlState tsh = getState(); 198 tsh.registerAttribute(AbstractHtmlState.ATTR_GENERAL, DIR, dir); 199 } 200 201 206 public String getOnClick() 207 { 208 AbstractHtmlState tsh = getState(); 209 return tsh.getAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONCLICK); 210 } 211 212 221 public void setOnClick(String onclick) 222 { 223 AbstractHtmlState tsh = getState(); 224 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONCLICK, onclick); 225 } 226 227 236 public void setOnDblClick(String ondblclick) 237 { 238 AbstractHtmlState tsh = getState(); 239 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONDBLCLICK, ondblclick); 240 } 241 242 251 public void setOnKeyDown(String onkeydown) 252 { 253 AbstractHtmlState tsh = getState(); 254 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONKEYDOWN, onkeydown); 255 } 256 257 266 public void setOnKeyPress(String onkeypress) 267 { 268 AbstractHtmlState tsh = getState(); 269 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONKEYPRESS, onkeypress); 270 } 271 272 281 public void setOnKeyUp(String onkeyup) 282 { 283 AbstractHtmlState tsh = getState(); 284 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONKEYUP, onkeyup); 285 } 286 287 296 public void setOnMouseDown(String onmousedown) 297 { 298 AbstractHtmlState tsh = getState(); 299 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONMOUSEDOWN, onmousedown); 300 } 301 302 311 public void setOnMouseMove(String onmousemove) 312 { 313 AbstractHtmlState tsh = getState(); 314 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONMOUSEMOVE, onmousemove); 315 } 316 317 326 public void setOnMouseOut(String onmouseout) 327 { 328 AbstractHtmlState tsh = getState(); 329 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONMOUSEOUT, onmouseout); 330 } 331 332 341 public void setOnMouseOver(String onmouseover) 342 { 343 AbstractHtmlState tsh = getState(); 344 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONMOUSEOVER, onmouseover); 345 } 346 347 356 public void setOnMouseUp(String onmouseup) 357 { 358 AbstractHtmlState tsh = getState(); 359 tsh.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONMOUSEUP, onmouseup); 360 } 361 362 363 365 protected String getJavaScriptAttribute(String name) 366 { 367 AbstractHtmlState tsh = getState(); 368 return tsh.getAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, name); 369 } 370 371 378 protected void setStateAttribute(String name, String value, AbstractHtmlState tsh) 379 throws JspException 380 { 381 boolean error = false; 382 383 if (name == null || name.length() <= 0) { 385 String s = Bundle.getString("Tags_AttributeNameNotSet"); 386 registerTagError(s, null); 387 error = true; 388 } 389 390 if (name != null && (name.equals(ID) || name.equals(NAME))) { 392 String s = Bundle.getString("Tags_AttributeMayNotBeSet", new Object []{name}); 393 registerTagError(s, null); 394 } 395 if (error) 396 return; 397 398 if (name.equals(CLASS)) { 400 tsh.styleClass = value; 401 return; 402 } 403 else if (name.equals(STYLE)) { 404 tsh.style = value; 405 return; 406 } 407 tsh.registerAttribute(AbstractHtmlState.ATTR_GENERAL, name, value); 408 } 409 410 421 public void setAttribute(String name, String value, String facet) 422 throws JspException 423 { 424 if (facet != null) { 425 String s = Bundle.getString("Tags_AttributeFacetNotSupported", new Object []{facet}); 426 registerTagError(s, null); 427 } 428 AbstractHtmlState tsh = getState(); 429 setStateAttribute(name, value, tsh); 430 } 431 432 435 protected Form getNearestForm() 436 { 437 Tag parentTag = getParent(); 438 while (parentTag != null) { 439 if (parentTag instanceof Form) 440 return (Form) parentTag; 441 parentTag = parentTag.getParent(); 442 } 443 return null; 444 } 445 446 456 protected final String renderNameAndId(HttpServletRequest request, AbstractHtmlState state, Form parentForm) 457 { 458 if (state.id == null) 460 return null; 461 462 boolean ctrlState = (state instanceof AbstractHtmlControlState); 464 465 if (parentForm != null && ctrlState) { 467 AbstractHtmlControlState hcs = (AbstractHtmlControlState) state; 468 if (hcs.name == null && parentForm.isFocusSet()) 469 hcs.name = state.id; 470 parentForm.addTagID(state.id, ((AbstractHtmlControlState) state).name); 471 } 472 473 String id = state.id; 475 state.id = getIdForTagId(id); 476 477 String idScript = null; 480 if (TagConfig.isLegacyJavaScript()) { 481 ScriptRequestState srs = ScriptRequestState.getScriptRequestState(request); 482 if (!ctrlState) { 483 idScript = srs.mapLegacyTagId(getScriptReporter(), id, state.id); 484 } 485 else { 486 AbstractHtmlControlState cState = (AbstractHtmlControlState) state; 487 if (cState.name != null) 488 idScript = srs.mapLegacyTagId(getScriptReporter(), id, cState.name); 489 else 490 idScript = srs.mapLegacyTagId(getScriptReporter(), id, state.id); 491 } 492 } 493 494 String name = null; 496 if (ctrlState) { 497 AbstractHtmlControlState cState = (AbstractHtmlControlState) state; 498 name = cState.name; 499 } 500 501 String script = renderDefaultNameAndId((HttpServletRequest ) pageContext.getRequest(), state, id, name); 502 if (script != null) { 503 if (idScript != null) { 504 idScript = idScript + script; 505 } 506 else { 507 idScript = script; 508 } 509 } 510 return idScript; 511 } 512 513 514 protected String renderDefaultNameAndId(HttpServletRequest request, AbstractHtmlState state, String id, String name) 515 { 516 517 String script = null; 519 if (TagConfig.isDefaultJavaScript()) { 520 ScriptRequestState srs = ScriptRequestState.getScriptRequestState(request); 521 script = srs.mapTagId(getScriptReporter(), id, state.id, name); 522 } 523 return script; 524 } 525 526 529 protected void localRelease() 530 { 531 super.localRelease(); 532 } 533 534 541 protected String qualifyUrlToContext(String url) 542 { 543 556 return url; 557 } 558 } 559 | Popular Tags |