1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.web;
20
21 import net.wotonomy.foundation.NSDate;
22
23 /***
24 * A pure java implementation of WOCookie that extends
25 * javax.servlet.httpd.Cookie for greater compatibility.
26 *
27 * @author michael@mpowers.net
28 * @author $Author: cgruber $
29 * @version $Revision: 905 $
30 */
31 public class WOCookie
32 extends javax.servlet.http.Cookie
33 {
34 /***
35 * Default constructor.
36 */
37 public WOCookie ()
38 {
39 super( "", "" );
40 }
41
42 /***
43 * Constructs a cookie with the specified name and value.
44 */
45 public WOCookie( String aName, String aValue )
46 {
47 super( aName, aValue );
48 }
49
50 /***
51 * Constructs a cookie with the specified name and value.
52 * Also sets the path to the current application's path.
53 */
54 public static WOCookie cookieWithName (String aName, String aValue)
55 {
56 WOCookie result = new WOCookie( aName, aValue );
57
58 return result;
59 }
60
61 /***
62 * Constructs a cookie with the specified attributes.
63 */
64 public static WOCookie cookieWithName (String aName, String aValue,
65 String aPath, String aDomain, NSDate expirationDate, boolean secure)
66 {
67 WOCookie result = new WOCookie( aName, aValue );
68 result.setPath( aPath );
69 result.setDomain( aDomain );
70 result.setExpires( expirationDate );
71 result.setSecure( secure );
72 return result;
73 }
74
75 /***
76 * Returns the name of the cookie.
77 */
78 public String name ()
79 {
80 return this.getName();
81 }
82
83 /***
84 * Sets the name of the cookie.
85 */
86 public void setName (String aString)
87 {
88
89 throw new RuntimeException( "Not yet implemented." );
90 }
91
92 /***
93 * Returns the value of the cookie.
94 */
95 public String value ()
96 {
97 return this.getValue();
98 }
99
100 /***
101 * Sets the value of the cookie.
102 */
103 public void setValue (String aString)
104 {
105 super.setValue( aString );
106 }
107
108 /***
109 * Gets the domain of the cookie.
110 */
111 public String domain ()
112 {
113 return this.getDomain();
114 }
115
116 /***
117 * Sets the domain of the cookie.
118 */
119 public void setDomain (String aString)
120 {
121 super.setDomain( aString );
122 }
123
124 /***
125 * Gets the path of the cookie.
126 */
127 public String path ()
128 {
129 return this.getPath();
130 }
131
132 /***
133 * Sets the path of the cookie.
134 */
135 public void setPath (String aString)
136 {
137 super.setPath( aString );
138 }
139
140 /***
141 * Gets the expiration date of the cookie.
142 * If in the past, the cookie will persist until browser shutdown.
143 */
144 public NSDate expires ()
145 {
146 return new NSDate( this.getMaxAge() );
147 }
148
149 /***
150 * Sets the expiration date of the cookie.
151 */
152 public void setExpires (NSDate aDate)
153 {
154 this.setMaxAge( (int) aDate.timeIntervalSinceNow() );
155 }
156
157 /***
158 * Returns whether the cookie will only be sent over a secure protocol.
159 */
160 public boolean isSecure ()
161 {
162 return this.getSecure();
163 }
164
165 /***
166 * Sets whether the cookie will only be sent over a secure protocol.
167 */
168 public void setIsSecure (boolean isSecure)
169 {
170 this.setSecure( isSecure );
171 }
172
173 /***
174 * Returns the string as it appears in the HTTP header of the response.
175 * This would normally be called by WOResponse, but is handled automatically
176 * by the servlet implementation.
177 */
178 public String headerString ()
179 {
180 new RuntimeException( "Not implemented yet." );
181 return null;
182 }
183 }
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203