{
this();
String cookieHeader = null;
String host = "";
StringTokenizer tokens = null;
// does is start with "Set-Cookie" ?
if (setCookie.substring(0,HEADER_SETCOOKIE.length()).equalsIgnoreCase(HEADER_SETCOOKIE)) {
cookieHeader = setCookie.substring(HEADER_SETCOOKIE.length());
} else {
throw new CookieException("Not a Set-Cookie header");
}
// set defaults from the URL
if (u != null) {
this.domain = u.getHost().toLowerCase();
host = this.domain;
} else {
this.domain = "";
}
// tokenize setcookie request
tokens = new StringTokenizer(cookieHeader,";");
// there must be at least ONE token (name=value)
if (tokens.countTokens() < 1) {
throw new CookieException("Cookie contains no data");
} else {
String field = tokens.nextToken();
int pos = field.indexOf('=');
if (pos <= 0) {
throw new CookieException("First field not in the format NAME=VALUE"
+" but got "+field);
} else {
name = field.substring(0,pos).trim();
value = field.substring(pos+1);
}
}
// parse all other fields
while (tokens.hasMoreTokens()) {
String field = tokens.nextToken();
String fieldname="";
String fieldvalue="";
int pos = field.indexOf('=');
if (pos <= 0) {