1 package com.ibatis.struts.httpmap; 2 3 import com.ibatis.struts.httpmap.BaseHttpMap; 4 5 import javax.servlet.http.Cookie ; 6 import javax.servlet.http.HttpServletRequest ; 7 import java.util.Enumeration ; 8 9 16 public class CookieMap extends BaseHttpMap { 17 18 private Cookie [] cookies; 19 20 public CookieMap(HttpServletRequest request) { 21 cookies = request.getCookies(); 22 } 23 24 protected Enumeration getNames() { 25 return new CookieEnumerator(cookies); 26 } 27 28 protected Object getValue(Object key) { 29 for (int i = 0; i < cookies.length; i++) { 30 if (key.equals(cookies[i].getName())) { 31 return cookies[i].getValue(); 32 } 33 } 34 return null; 35 } 36 37 protected void putValue(Object key, Object value) { 38 throw new UnsupportedOperationException (); 39 } 40 41 protected void removeValue(Object key) { 42 throw new UnsupportedOperationException (); 43 } 44 45 48 private class CookieEnumerator implements Enumeration { 49 50 private int i = 0; 51 52 private Cookie [] cookieArray; 53 54 public CookieEnumerator(Cookie [] cookies) { 55 this.cookieArray = cookies; 56 } 57 58 public synchronized boolean hasMoreElements() { 59 return cookieArray.length > i; 60 } 61 62 public synchronized Object nextElement() { 63 Object element = cookieArray[i]; 64 i++; 65 return element; 66 } 67 68 } 69 70 } 71 | Popular Tags |