1 16 17 package org.apache.taglibs.request; 18 19 import java.util.*; 20 import javax.servlet.*; 21 import javax.servlet.http.*; 22 import javax.servlet.jsp.*; 23 import javax.servlet.jsp.tagext.*; 24 25 55 56 public class HeaderValuesTag extends BodyTagSupport 57 { 58 private Enumeration values = null; 60 private String value = null; 62 63 68 public final int doStartTag() throws JspException 69 { 70 values = null; 72 value = null; 73 74 HeadersTag ht; 76 try { 77 ht = (HeadersTag)this.findAncestorWithClass(this, 78 Class.forName("org.apache.taglibs.request.HeadersTag")); 79 } catch(Exception e) { 80 return SKIP_BODY; 81 } 82 83 values = ((HttpServletRequest)pageContext.getRequest()).getHeaders(ht.getName()); 85 if( values == null || !values.hasMoreElements() ) 86 return SKIP_BODY; 87 88 value = (String )values.nextElement(); 89 if( value == null ) 90 return SKIP_BODY; 91 92 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 93 return EVAL_BODY_TAG; 94 } 95 96 101 public final int doAfterBody() throws JspException 102 { 103 if( !values.hasMoreElements() ) 105 return SKIP_BODY; 106 value = (String )values.nextElement(); 108 if( value == null ) 109 return SKIP_BODY; 110 return EVAL_BODY_TAG; 111 } 112 113 118 public final int doEndTag() throws JspException 119 { 120 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 121 try 122 { 123 if(bodyContent != null) 124 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 125 } catch(java.io.IOException e) 126 { 127 throw new JspException("IO Error: " + e.getMessage()); 128 } 129 return EVAL_PAGE; 130 } 131 132 139 public final String getHeader() 140 { 141 return value; 142 } 143 144 } 145 | Popular Tags |