1 19 20 package com.maverick.http; 21 22 import java.text.ParseException ; 23 import java.text.SimpleDateFormat ; 24 import java.util.Date ; 25 import java.util.StringTokenizer ; 26 27 31 public class Cookie { 32 33 String name; 34 String value; 35 String path = ""; Date expires = null; 37 String domain = ""; boolean secure = false; 39 40 static SimpleDateFormat format = new SimpleDateFormat ("EEE, DD-MMM-yyyy HH:mm:ss z"); 42 public Cookie(String setCookieHeaderValue) { 43 44 StringTokenizer tokens = new StringTokenizer (setCookieHeaderValue, ";"); while (tokens.hasMoreTokens()) { 46 String pair = tokens.nextToken(); 47 int idx = pair.indexOf('='); 48 if (idx > -1) { 49 String name = pair.substring(0, idx).trim(); 50 String value = pair.substring(idx + 1).trim(); 51 52 if (name.equalsIgnoreCase("expires")) { try { 54 Integer.parseInt(value); 55 } catch (NumberFormatException ex) { 56 try { 57 expires = format.parse(value); 58 } catch (ParseException ex2) { 59 60 } 61 } 62 } else if (name.equalsIgnoreCase("path")) { this.path = value; 64 } else if (name.equalsIgnoreCase("domain")) { this.domain = path; 66 } else { 67 this.name = name; 68 this.value = value; 69 } 70 } else if (pair.trim().equalsIgnoreCase("secure")) secure = true; 72 } 73 74 } 75 76 public String getPath() { 77 return path; 78 } 79 80 public String getDomain() { 81 return domain; 82 } 83 84 public boolean isSecure() { 85 return secure; 86 } 87 88 public String getName() { 89 return name; 90 } 91 92 public String getValue() { 93 return value; 94 } 95 96 public Date getExpires() { 97 return expires; 98 } 99 100 public String toString() { 101 return name + "=" + value; 103 108 } 109 } 110 | Popular Tags |