1 31 32 package org.apache.commons.httpclient.cookie; 33 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 37 58 public abstract class CookiePolicy { 59 60 61 private static final String SYSTEM_PROPERTY = 62 "apache.commons.httpclient.cookiespec"; 63 64 68 public static final int COMPATIBILITY = 0; 69 70 71 public static final int NETSCAPE_DRAFT = 1; 72 73 74 public static final int RFC2109 = 2; 75 76 77 private static int defaultPolicy = RFC2109; 78 79 80 protected static final Log LOG = LogFactory.getLog(CookiePolicy.class); 81 82 static { 83 String s = null; 84 try { 85 s = System.getProperty(SYSTEM_PROPERTY); 86 } catch (SecurityException e) { 87 } 88 if ("COMPATIBILITY".equalsIgnoreCase(s)) { 89 setDefaultPolicy(COMPATIBILITY); 90 } else if ("NETSCAPE_DRAFT".equalsIgnoreCase(s)) { 91 setDefaultPolicy(NETSCAPE_DRAFT); 92 } else if ("RFC2109".equalsIgnoreCase(s)) { 93 setDefaultPolicy(RFC2109); 94 } else { 95 if (s != null) { 96 LOG.warn("Unrecognized cookiespec property '" + s 97 + "' - using default"); 98 } 99 setDefaultPolicy(defaultPolicy); 100 } 101 } 102 103 107 public static int getDefaultPolicy() { 108 return defaultPolicy; 109 } 110 111 112 116 public static void setDefaultPolicy(int policy) { 117 defaultPolicy = policy; 118 } 119 120 121 126 public static CookieSpec getSpecByPolicy(int policy) { 127 switch(policy) { 128 case COMPATIBILITY: 129 return new CookieSpecBase(); 130 case NETSCAPE_DRAFT: 131 return new NetscapeDraftSpec(); 132 case RFC2109: 133 return new RFC2109Spec(); 134 default: 135 return getSpecByPolicy(defaultPolicy); 136 } 137 } 138 139 140 143 public static CookieSpec getDefaultSpec() { 144 return getSpecByPolicy(defaultPolicy); 145 } 146 147 148 162 public static CookieSpec getSpecByVersion(int ver) { 163 switch(ver) { 164 case 0: 165 return new NetscapeDraftSpec(); 166 case 1: 167 return new RFC2109Spec(); 168 default: 169 return getDefaultSpec(); 170 } 171 } 172 173 177 public static CookieSpec getCompatibilitySpec() { 178 return getSpecByPolicy(COMPATIBILITY); 179 } 180 } 181 | Popular Tags |