1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.impl.cookie;
29
30 import java.io.Serializable;
31 import java.util.Date;
32 import java.util.HashMap;
33 import java.util.Locale;
34 import java.util.Map;
35
36 import org.apache.http.cookie.ClientCookie;
37 import org.apache.http.cookie.SetCookie;
38 import org.apache.http.util.Args;
39
40
41
42
43
44
45 public class BasicClientCookie implements SetCookie, ClientCookie, Cloneable, Serializable {
46
47 private static final long serialVersionUID = -3869795591041535538L;
48
49
50
51
52
53
54
55 public BasicClientCookie(final String name, final String value) {
56 super();
57 Args.notNull(name, "Name");
58 this.name = name;
59 this.attribs = new HashMap<String, String>();
60 this.value = value;
61 }
62
63
64
65
66
67
68 @Override
69 public String getName() {
70 return this.name;
71 }
72
73
74
75
76
77
78 @Override
79 public String getValue() {
80 return this.value;
81 }
82
83
84
85
86
87
88 @Override
89 public void setValue(final String value) {
90 this.value = value;
91 }
92
93
94
95
96
97
98
99
100
101 @Override
102 public String getComment() {
103 return cookieComment;
104 }
105
106
107
108
109
110
111
112
113
114 @Override
115 public void setComment(final String comment) {
116 cookieComment = comment;
117 }
118
119
120
121
122
123 @Override
124 public String getCommentURL() {
125 return null;
126 }
127
128
129
130
131
132
133
134
135
136
137
138
139
140 @Override
141 public Date getExpiryDate() {
142 return cookieExpiryDate;
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156 @Override
157 public void setExpiryDate (final Date expiryDate) {
158 cookieExpiryDate = expiryDate;
159 }
160
161
162
163
164
165
166
167
168
169 @Override
170 public boolean isPersistent() {
171 return (null != cookieExpiryDate);
172 }
173
174
175
176
177
178
179
180
181
182 @Override
183 public String getDomain() {
184 return cookieDomain;
185 }
186
187
188
189
190
191
192
193
194 @Override
195 public void setDomain(final String domain) {
196 if (domain != null) {
197 cookieDomain = domain.toLowerCase(Locale.ROOT);
198 } else {
199 cookieDomain = null;
200 }
201 }
202
203
204
205
206
207
208
209
210
211 @Override
212 public String getPath() {
213 return cookiePath;
214 }
215
216
217
218
219
220
221
222
223
224 @Override
225 public void setPath(final String path) {
226 cookiePath = path;
227 }
228
229
230
231
232
233 @Override
234 public boolean isSecure() {
235 return isSecure;
236 }
237
238
239
240
241
242
243
244
245
246
247
248
249
250 @Override
251 public void setSecure (final boolean secure) {
252 isSecure = secure;
253 }
254
255
256
257
258
259 @Override
260 public int[] getPorts() {
261 return null;
262 }
263
264
265
266
267
268
269
270
271
272
273
274 @Override
275 public int getVersion() {
276 return cookieVersion;
277 }
278
279
280
281
282
283
284
285
286
287 @Override
288 public void setVersion(final int version) {
289 cookieVersion = version;
290 }
291
292
293
294
295
296
297
298 @Override
299 public boolean isExpired(final Date date) {
300 Args.notNull(date, "Date");
301 return (cookieExpiryDate != null
302 && cookieExpiryDate.getTime() <= date.getTime());
303 }
304
305
306
307
308 public Date getCreationDate() {
309 return creationDate;
310 }
311
312
313
314
315 public void setCreationDate(final Date creationDate) {
316 this.creationDate = creationDate;
317 }
318
319 public void setAttribute(final String name, final String value) {
320 this.attribs.put(name, value);
321 }
322
323 @Override
324 public String getAttribute(final String name) {
325 return this.attribs.get(name);
326 }
327
328 @Override
329 public boolean containsAttribute(final String name) {
330 return this.attribs.containsKey(name);
331 }
332
333
334
335
336 public boolean removeAttribute(final String name) {
337 return this.attribs.remove(name) != null;
338 }
339
340 @Override
341 public Object clone() throws CloneNotSupportedException {
342 final BasicClientCookie./../org/apache/http/impl/cookie/BasicClientCookie.html#BasicClientCookie">BasicClientCookie clone = (BasicClientCookie) super.clone();
343 clone.attribs = new HashMap<String, String>(this.attribs);
344 return clone;
345 }
346
347 @Override
348 public String toString() {
349 final StringBuilder buffer = new StringBuilder();
350 buffer.append("[version: ");
351 buffer.append(Integer.toString(this.cookieVersion));
352 buffer.append("]");
353 buffer.append("[name: ");
354 buffer.append(this.name);
355 buffer.append("]");
356 buffer.append("[value: ");
357 buffer.append(this.value);
358 buffer.append("]");
359 buffer.append("[domain: ");
360 buffer.append(this.cookieDomain);
361 buffer.append("]");
362 buffer.append("[path: ");
363 buffer.append(this.cookiePath);
364 buffer.append("]");
365 buffer.append("[expiry: ");
366 buffer.append(this.cookieExpiryDate);
367 buffer.append("]");
368 return buffer.toString();
369 }
370
371
372
373
374 private final String name;
375
376
377 private Map<String, String> attribs;
378
379
380 private String value;
381
382
383 private String cookieComment;
384
385
386 private String cookieDomain;
387
388
389 private Date cookieExpiryDate;
390
391
392 private String cookiePath;
393
394
395 private boolean isSecure;
396
397
398 private int cookieVersion;
399
400 private Date creationDate;
401
402 }
403