1 16 17 package org.apache.taglibs.xtags.xpath; 18 19 import java.io.IOException ; 20 21 import javax.servlet.ServletRequest ; 22 import javax.servlet.jsp.JspTagException ; 23 import javax.servlet.jsp.JspWriter ; 24 import javax.servlet.jsp.PageContext ; 25 import javax.servlet.jsp.tagext.Tag ; 26 27 33 public class AttributeTag extends AbstractBodyTag { 34 35 36 private String name; 37 private ElementTag elementTag; 38 39 40 public AttributeTag() { 41 } 42 43 public void release() { 46 super.release(); 47 name = null; 48 elementTag = null; 49 } 50 51 public int doStartTag() throws JspTagException { 52 getElementTag().addAttribute( getName() ); 53 return EVAL_BODY_TAG; 54 } 55 56 public int doAfterBody() throws JspTagException { 57 getElementTag().setAttributeValue( getName(), bodyContent.getString() ); 58 bodyContent.clearBody(); 59 return SKIP_BODY; 60 } 61 62 65 68 public String getName() { 69 return name; 70 } 71 74 public void setName(String name) { 75 this.name = name; 76 } 77 78 protected ElementTag getElementTag() throws JspTagException { 81 if ( elementTag != null ) { 82 return elementTag; 83 } 84 Tag tag = findAncestorWithClass( this, ElementTag.class ); 85 if ( tag != null ) { 86 if ( tag instanceof ElementTag ) { 87 elementTag = (ElementTag) tag; 88 return elementTag; 89 } 90 } 91 throw new JspTagException ( "<attribute> tag must be enclosed inside an <element> tag" ); 92 } 93 } 94 | Popular Tags |