String cookieString = (String) cookieEnumeration.nextElement();
int version = 0;
String previousToken = "";
boolean isValue = false;
Cookie cookie = null;
StringTokenizer st = new StringTokenizer(cookieString, "=;,", true);
while (st.hasMoreElements()) {
String token = ((String) st.nextElement()).trim();
if (token.equals("="))
isValue = true;
else if (";,".indexOf(token) != -1)
isValue = false;
else {
if (isValue) {
if (token.charAt(0) == '\"') {
int index = token.indexOf('\"', 1);
if (index == -1)
break;
token = token.substring(1, index);
}
if (previousToken.equals("$Version")) {
try {
version = Integer.parseInt(token);
} catch (Exception e) {
break;
}
} else if (previousToken.equals("$Path")) {
if (cookie == null)
break;
cookie.setPath(token);
} else if (previousToken.equals("$Domain")) {
if (cookie == null)
break;
cookie.setDomain(token);
} else {
cookie = new Cookie(previousToken, token);
cookie.setVersion(version);
cookies.put(cookie.getName(), cookie);
}
} else
previousToken = token;
}
}