1 18 package org.apache.beehive.netui.tags.html; 19 20 import org.apache.beehive.netui.tags.ByRef; 21 import org.apache.beehive.netui.tags.IHtmlAccessable; 22 import org.apache.beehive.netui.tags.internal.PageFlowTagUtils; 23 import org.apache.beehive.netui.tags.javascript.CoreScriptFeature; 24 import org.apache.beehive.netui.tags.javascript.ScriptRequestState; 25 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState; 26 import org.apache.beehive.netui.tags.rendering.ImageTag; 27 import org.apache.beehive.netui.tags.rendering.TagRenderingBase; 28 import org.apache.beehive.netui.tags.rendering.WriteRenderAppender; 29 import org.apache.beehive.netui.util.Bundle; 30 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 import javax.servlet.jsp.JspException ; 34 import java.net.URISyntaxException ; 35 36 112 public class ImageAnchor 113 extends Anchor 114 implements IHtmlAccessable 115 { 116 private ImageTag.State _imgState = new ImageTag.State(); 117 private String _rolloverImage = null; 119 122 public String getTagName() 123 { 124 return "ImageAnchor"; 125 } 126 127 138 public void setAttribute(String name, String value, String facet) 139 throws JspException ![JavaDoc](../../../../../../../cmn/javadoc.gif) 140 { 141 if (name != null && name.equals(SRC)) { 142 String s = Bundle.getString("Tags_AttributeMayNotBeSet", new Object []{name}); 143 registerTagError(s, null); 144 } 145 if (facet != null) { 146 if (facet.equals("image")) { 147 setStateAttribute(name, value, _imgState); 148 return; 149 } 150 } 151 super.setAttribute(name, value, facet); 152 } 153 154 163 public void setAlign(String align) 164 { 165 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALIGN, align); 166 } 167 168 177 public void setAlt(String alt) 178 { 179 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALT, alt); 180 } 181 182 192 public void setLongdesc(String longdesc) 193 { 194 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, LONGDESC, longdesc); 195 } 196 197 206 public void setBorder(String border) 207 { 208 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, BORDER, border); 209 } 210 211 220 public void setHeight(String height) 221 { 222 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HEIGHT, height); 223 } 224 225 234 public void setHspace(String hspace) 235 { 236 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HSPACE, hspace); 237 } 238 239 248 public void setIsmap(String ismap) 249 { 250 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ISMAP, ismap); 251 } 252 253 262 public void setRolloverImage(String rolloverImage) 263 { 264 _rolloverImage = rolloverImage; 265 } 266 267 277 public void setSrc(String src) 278 throws JspException ![JavaDoc](../../../../../../../cmn/javadoc.gif) 279 { 280 _imgState.src = src; 281 } 282 283 292 public void setUsemap(String usemap) 293 { 294 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, USEMAP, usemap); 295 } 296 297 306 public void setVspace(String vspace) 307 { 308 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, VSPACE, vspace); 309 } 310 311 326 public void setImageStyle(String imageStyle) 327 { 328 _imgState.style = imageStyle; 329 } 330 331 346 public void setImageStyleClass(String imageClass) 347 { 348 _imgState.styleClass = imageClass; 349 } 350 351 360 public void setWidth(String width) 361 { 362 _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, WIDTH, width); 363 } 364 365 371 public int doStartTag() throws JspException ![JavaDoc](../../../../../../../cmn/javadoc.gif) 372 { 373 if (_rolloverImage != null && getJavaScriptAttribute(ONMOUSEOVER) == null) { 374 WriteRenderAppender writer = new WriteRenderAppender(pageContext); 376 ScriptRequestState srs = ScriptRequestState.getScriptRequestState((HttpServletRequest ) pageContext.getRequest()); 377 srs.writeFeature(getScriptReporter(), writer, CoreScriptFeature.ROLLOVER, true, false, null); 378 } 379 380 return EVAL_BODY_BUFFERED; 381 } 382 383 387 public int doEndTag() throws JspException ![JavaDoc](../../../../../../../cmn/javadoc.gif) 388 { 389 if (hasErrors()) 391 return reportAndExit(EVAL_PAGE); 392 393 HttpServletRequest req = (HttpServletRequest ) pageContext.getRequest(); 394 395 WriteRenderAppender writer = new WriteRenderAppender(pageContext); 398 TagRenderingBase trb = TagRenderingBase.Factory.getRendering(TagRenderingBase.ANCHOR_TAG, req); 399 ByRef script = new ByRef(); 400 if (!createAnchorBeginTag(req, script, trb, writer, REQUIRED_ATTR)) { 401 reportErrors(); 402 if (!script.isNull()) 403 write(script.getRef().toString()); 404 localRelease(); 405 return EVAL_PAGE; 406 } 407 408 HttpServletResponse response = (HttpServletResponse ) pageContext.getResponse(); 411 if (_imgState.src != null) { 412 try { 413 String uri = PageFlowTagUtils.rewriteResourceURL(pageContext, _imgState.src, null, null); 414 _imgState.src = response.encodeURL(uri); 415 } 416 catch (URISyntaxException e) { 417 String s = Bundle.getString("Tags_Image_URLException", 419 new Object []{_imgState.src, e.getMessage()}); 420 registerTagError(s, e); 421 } 422 } 423 424 if (_rolloverImage != null) { 426 try { 427 String uri = PageFlowTagUtils.rewriteResourceURL(pageContext, _rolloverImage, null, null); 428 _rolloverImage = response.encodeURL(qualifyUrlToContext(uri)); 429 } 430 catch (URISyntaxException e) { 431 String s = Bundle.getString("Tags_Rollover_Image_URLException", 433 new Object []{_rolloverImage, e.getMessage()}); 434 registerTagError(s, e); 435 } 436 437 if (getJavaScriptAttribute(ONMOUSEOUT) == null) { 438 String s = "swapImage(this,'" + response.encodeURL(_imgState.src) + "')"; 439 _imgState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONMOUSEOUT, s); 440 } 441 if (getJavaScriptAttribute(ONMOUSEOVER) == null) { 442 String s = "swapImage(this,'" + response.encodeURL(_rolloverImage) + "')"; 443 _imgState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONMOUSEOVER, s); 444 } 445 } 446 447 TagRenderingBase br = TagRenderingBase.Factory.getRendering(TagRenderingBase.IMAGE_TAG, req); 449 br.doStartTag(writer, _imgState); 450 br.doEndTag(writer); 451 452 trb.doEndTag(writer); 454 if (!script.isNull()) 455 write(script.getRef().toString()); 456 457 localRelease(); 458 return EVAL_PAGE; 459 } 460 461 464 protected void localRelease() 465 { 466 super.localRelease(); 467 468 _imgState.clear(); 469 _rolloverImage = null; 470 } 471 } 472 | Popular Tags |