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 58 59 public class HeadersTag extends BodyTagSupport 60 { 61 private String name = null; 63 private HttpServletRequest req = null; 65 private Enumeration headers = null; 67 private String header = null; 69 70 75 public final int doStartTag() throws JspException 76 { 77 req = (HttpServletRequest)pageContext.getRequest(); 79 80 if( name != null ) { 81 if( req.getHeader(name) != null ) 82 header = name; 83 } else { 84 headers = req.getHeaderNames(); 85 if( headers == null || !headers.hasMoreElements() ) 86 return SKIP_BODY; 87 header = (String )headers.nextElement(); 88 } 89 if( header == 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( name != null || !headers.hasMoreElements() ) 105 return SKIP_BODY; 106 header = (String )headers.nextElement(); 108 if( header == 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 137 public final void setName(String str) 138 { 139 name = str; 140 } 141 142 149 public final String getName() 150 { 151 return header; 152 } 153 154 161 public final String getHeader() 162 { 163 String value = req.getHeader(header); 164 if( value == null ) 165 return ""; 166 return value; 167 } 168 169 176 public final String getDateHeader() 177 { 178 return "" + req.getDateHeader(header); 179 } 180 181 188 public final String getIntHeader() 189 { 190 return "" + req.getIntHeader(header); 191 } 192 193 } 194 | Popular Tags |