1 16 17 package org.apache.taglibs.request; 18 19 import javax.servlet.*; 20 import javax.servlet.http.*; 21 import javax.servlet.jsp.*; 22 import javax.servlet.jsp.tagext.*; 23 24 57 58 public class CookiesTag extends BodyTagSupport 59 { 60 private Cookie [] cookies = null; 62 private Cookie cookie = null; 64 private int cookie_num = 0; 66 private String name = null; 68 69 74 public final int doStartTag() throws JspException 75 { 76 cookies = ((HttpServletRequest)pageContext.getRequest()).getCookies(); 78 if( cookies == null || cookies.length == 0 ) 79 return SKIP_BODY; 80 81 if( name != null ) { 82 for( int i = 0; i < cookies.length; i++ ) { 84 if( cookies[i].getName().equals(name) ) { 85 cookie = cookies[i]; 86 break; 87 } 88 } 89 if( cookie == null ) return SKIP_BODY; 91 } else { 92 cookie = cookies[0]; 93 } 94 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 95 return EVAL_BODY_TAG; 96 } 97 98 103 public final int doAfterBody() throws JspException 104 { 105 cookie_num++; 107 if( name != null || cookies == null || cookie_num >= cookies.length ) 109 return SKIP_BODY; 110 cookie = cookies[cookie_num]; 112 if( cookie == null ) 113 return SKIP_BODY; 114 return EVAL_BODY_TAG; 115 } 116 117 122 public final int doEndTag() throws JspException 123 { 124 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 125 try 126 { 127 if(bodyContent != null) 128 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 129 } catch(java.io.IOException e) 130 { 131 throw new JspException("IO Error: " + e.getMessage()); 132 } 133 return EVAL_PAGE; 134 } 135 136 141 public final void setName(String str) 142 { 143 name = str; 144 } 145 146 154 public final String getComment() 155 { 156 return cookie.getComment(); 157 } 158 159 166 public final String getDomain() 167 { 168 return cookie.getDomain(); 169 } 170 171 180 public final String getMaxAge() 181 { 182 return "" + cookie.getMaxAge(); 183 } 184 185 192 public final String getName() 193 { 194 return cookie.getName(); 195 } 196 197 204 public final String getPath() 205 { 206 return cookie.getPath(); 207 } 208 209 216 public final String getValue() 217 { 218 return cookie.getValue(); 219 } 220 221 229 public final String getSecure() 230 { 231 if( cookie.getSecure() ) 232 return "1"; 233 return "0"; 234 } 235 236 243 public final String getVersion() 244 { 245 return "" + cookie.getVersion(); 246 } 247 248 } 249 | Popular Tags |