FileDocCategorySizeDatePackage
CookieStore.javaAPI DocExample1789Sun Dec 12 10:52:28 GMT 2004com.macfaq.http

CookieStore

public class CookieStore extends CookieHandler

Fields Summary
private List
store
Constructors Summary
Methods Summary
public java.util.Mapget(java.net.URI uri, java.util.Map requestHeaders)


      
     
     
      
      Map<String,List<String>> result = new HashMap<String,List<String>>();
      StringBuffer cookies = new StringBuffer();
      for (Cookie cookie : store) {
        if (cookie.isExpired()) {
          store.remove(cookie);
        }
        else if (cookie.matches(uri)) {
              if (cookies.length() != 0) cookies.append(", ");
              cookies.append(cookie.toExternalForm());
        }
      }
      
      if (cookies.length() > 0) {
        List<String> temp = new ArrayList<String>(1);
        temp.add(cookies.toString());
        result.put("Cookie", temp);
      }
      
      return result;
      
  
public voidput(java.net.URI uri, java.util.Map responseHeaders)

      
    List<String> setCookies = responseHeaders.get("Set-Cookie");
    for (String next : setCookies) {
      try {
        Cookie cookie = Cookie.bake(next, uri);
        // Is a cookie with this name and URI already in the list? 
        // If so, we replace it
        for (Cookie existingCookie : store) {
          if (cookie.getURI().equals(existingCookie.getURI()) &&
            cookie.getName().equals(existingCookie.getName())) {
              store.remove(existingCookie);
              break;
          }
        }
        store.add(cookie);            
      }
      catch (CookieException ex) {
        // Server sent malformed header; 
        // log and ignore
        System.err.println(ex);
      }
    }