1 16 17 package org.apache.taglibs.io; 18 19 import javax.servlet.ServletContext ; 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.tagext.BodyContent ; 22 23 28 public class URLHeaderTag extends AbstractBodyTag { 29 30 31 private String name; 32 33 34 private String value; 35 36 37 public int doStartTag() throws JspException { 40 if ( value != null ) { 41 fireHeader(); 42 return SKIP_BODY; 43 } 44 return EVAL_BODY_TAG; 45 } 46 47 public int doAfterBody() throws JspException { 48 BodyContent body = getBodyContent(); 49 value = body.getString(); 50 body.clearBody(); 51 fireHeader(); 52 return EVAL_PAGE; 53 } 54 55 public void release() { 56 name = null; 57 value = null; 58 } 59 60 64 public void setName(String name) { 65 this.name = name; 66 } 67 68 71 public void setValue(String value) { 72 this.value = value; 73 } 74 75 protected void fireHeader() throws JspException { 78 URLTag tag = (URLTag) findAncestorWithClass( this, URLTag.class ); 79 if ( tag == null ) { 80 throw new JspException ("<io:header> tag must be within a <io:url> tag"); 81 } 82 tag.addHeader( name, value ); 83 } 84 85 } 86 | Popular Tags |