forked from restlet/restlet-framework-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCookie.java
More file actions
279 lines (247 loc) · 7.23 KB
/
Cookie.java
File metadata and controls
279 lines (247 loc) · 7.23 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/**
* Copyright 2005-2013 Restlet S.A.S.
*
* The contents of this file are subject to the terms of one of the following
* open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
* 1.0 (the "Licenses"). You can select the license that you prefer but you may
* not use this file except in compliance with one of these Licenses.
*
* You can obtain a copy of the Apache 2.0 license at
* http://www.opensource.org/licenses/apache-2.0
*
* You can obtain a copy of the LGPL 3.0 license at
* http://www.opensource.org/licenses/lgpl-3.0
*
* You can obtain a copy of the LGPL 2.1 license at
* http://www.opensource.org/licenses/lgpl-2.1
*
* You can obtain a copy of the CDDL 1.0 license at
* http://www.opensource.org/licenses/cddl1
*
* You can obtain a copy of the EPL 1.0 license at
* http://www.opensource.org/licenses/eclipse-1.0
*
* See the Licenses for the specific language governing permissions and
* limitations under the Licenses.
*
* Alternatively, you can obtain a royalty free commercial license with less
* limitations, transferable or non-transferable, directly at
* http://www.restlet.com/products/restlet-framework
*
* Restlet is a registered trademark of Restlet S.A.S.
*/
package org.restlet.data;
import org.restlet.Request;
import org.restlet.engine.util.SystemUtils;
import org.restlet.util.NamedValue;
/**
* Cookie provided by a client. To get the list of all cookies sent by a client,
* you can use the {@link Request#getCookies()} method.<br>
* <br>
* Note that if you are on the server side and want to set a cookie on the
* client, you should use the {@link CookieSetting} class instead.<br>
* <br>
* Note that when used with HTTP connectors, this class maps to the "Cookie"
* header.
*
* @see Request#getCookies()
* @see <a href="http://wiki.restlet.org/docs_2.2/58-restlet.html">User Guide -
* Getting parameter values</a>
* @author Jerome Louvel
*/
public class Cookie implements NamedValue<String> {
/** The domain name. */
private volatile String domain;
/** The name. */
private volatile String name;
/** The validity path. */
private volatile String path;
/** The value. */
private volatile String value;
/** The version number. */
private volatile int version;
/**
* Default constructor.
*/
public Cookie() {
this(0, null, null, null, null);
}
/**
* Constructor.
*
* @param version
* The version number.
* @param name
* The name.
* @param value
* The value.
*/
public Cookie(int version, String name, String value) {
this(version, name, value, null, null);
}
/**
* Constructor.
*
* @param version
* The version number.
* @param name
* The name.
* @param value
* The value.
* @param path
* The validity path.
* @param domain
* The domain name.
*/
public Cookie(int version, String name, String value, String path,
String domain) {
this.version = version;
this.name = name;
this.value = value;
this.path = path;
this.domain = domain;
}
/**
* Constructor.
*
* @param name
* The name.
* @param value
* The value.
*/
public Cookie(String name, String value) {
this(0, name, value, null, null);
}
/** {@inheritDoc} */
@Override
public boolean equals(Object obj) {
// if obj == this no need to go further
boolean result = (obj == this);
if (!result) {
result = obj instanceof Cookie;
// if obj isn't a cookie or is null don't evaluate further
if (result) {
Cookie that = (Cookie) obj;
result = (((that.getName() == null) && (getName() == null)) || ((getName() != null) && getName()
.equals(that.getName())));
// if names are both null or equal continue
if (result) {
result = (((that.getValue() == null) && (getValue() == null)) || ((getValue() != null) && getValue()
.equals(that.getValue())));
// if values are both null or equal continue
if (result) {
result = (this.version == that.version);
// if versions are equal continue
if (result) {
result = (((that.getDomain() == null) && (getDomain() == null)) || ((getDomain() != null) && getDomain()
.equals(that.getDomain())));
// if domains are equal continue
if (result) {
// compare paths taking
result = (((that.getPath() == null) && (getPath() == null)) || ((getPath() != null) && getPath()
.equals(that.getPath())));
}
}
}
}
}
}
return result;
}
/**
* Returns the domain name.
*
* @return The domain name.
*/
public String getDomain() {
return this.domain;
}
/**
* Returns the name.
*
* @return The name.
*/
public String getName() {
return name;
}
/**
* Returns the validity path.
*
* @return The validity path.
*/
public String getPath() {
return this.path;
}
/**
* Returns the value.
*
* @return The value.
*/
public String getValue() {
return value;
}
/**
* Returns the cookie specification version.
*
* @return The cookie specification version.
*/
public int getVersion() {
return this.version;
}
/** {@inheritDoc} */
@Override
public int hashCode() {
return SystemUtils.hashCode(getName(), getValue(), getVersion(),
getPath(), getDomain());
}
/**
* Sets the domain name.
*
* @param domain
* The domain name.
*/
public void setDomain(String domain) {
this.domain = domain;
}
/**
* Sets the name.
*
* @param name
* The name.
*/
public void setName(String name) {
this.name = name;
}
/**
* Sets the validity path.
*
* @param path
* The validity path.
*/
public void setPath(String path) {
this.path = path;
}
/**
* Sets the value.
*
* @param value
* The value.
*/
public void setValue(String value) {
this.value = value;
}
/**
* Sets the cookie specification version.
*
* @param version
* The cookie specification version.
*/
public void setVersion(int version) {
this.version = version;
}
@Override
public String toString() {
return "Cookie [domain=" + domain + ", name=" + name + ", path=" + path
+ ", value=" + value + ", version=" + version + "]";
}
}