KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > net > CookiePolicy


1 /*
2  * %W% %E%
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.net;
9
10 /**
11  * CookiePolicy implementations decide which cookies should be accepted
12  * and which should be rejected. Three pre-defined policy implementations
13  * are provided, namely ACCEPT_ALL, ACCEPT_NONE and ACCEPT_ORIGINAL_SERVER.
14  *
15  * <p>See RFC 2965 sec. 3.3 & 7 for more detail.
16  *
17  * @version %I%, %E%
18  * @author Edward Wang
19  * @since 1.6
20  */

21 public interface CookiePolicy {
22     /**
23      * One pre-defined policy which accepts all cookies.
24      */

25     public static final CookiePolicy JavaDoc ACCEPT_ALL = new CookiePolicy JavaDoc(){
26         public boolean shouldAccept(URI JavaDoc uri, HttpCookie JavaDoc cookie) {
27             return true;
28         }
29     };
30
31     /**
32      * One pre-defined policy which accepts no cookies.
33      */

34     public static final CookiePolicy JavaDoc ACCEPT_NONE = new CookiePolicy JavaDoc(){
35         public boolean shouldAccept(URI JavaDoc uri, HttpCookie JavaDoc cookie) {
36             return false;
37         }
38     };
39
40     /**
41      * One pre-defined policy which only accepts cookies from original server.
42      */

43     public static final CookiePolicy JavaDoc ACCEPT_ORIGINAL_SERVER = new CookiePolicy JavaDoc(){
44         public boolean shouldAccept(URI JavaDoc uri, HttpCookie JavaDoc cookie) {
45             return HttpCookie.domainMatches(cookie.getDomain(), uri.getHost());
46         }
47     };
48
49
50     /**
51      * Will be called to see whether or not this cookie should be accepted.
52      *
53      * @param uri the URI to consult accept policy with
54      * @param cookie the HttpCookie object in question
55      * @return <tt>true</tt> if this cookie should be accepted;
56      * otherwise, <tt>false</tt>
57      */

58     public boolean shouldAccept(URI JavaDoc uri, HttpCookie JavaDoc cookie);
59 }
60
61
Popular Tags