001: // HttpSetCookie.java
002: // $Id: HttpSetCookie.java,v 1.7 2000/08/16 21:38:00 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.www.http;
007:
008: public class HttpSetCookie {
009: /**
010: * The cookie's name.
011: */
012: protected String name = null;
013: /*
014: * The cookie's value.
015: */
016: protected String value = null;
017: /**
018: * The cookie's comment.
019: */
020: protected String comment = null;
021: /**
022: * The cookie's domain name.
023: */
024: protected String domain = null;
025: /**
026: * The cookie's max age.
027: */
028: protected int maxage = -1;
029: /**
030: * The cookie's associated path.
031: */
032: protected String path = null;
033: /**
034: * Does this cookie requires special security care by client ?
035: */
036: protected boolean security = false;
037: /**
038: * This cookie's version.
039: */
040: protected int version = 1;
041:
042: /**
043: * Get this SetCookie attached comment.
044: * @return A String describing the reason for this SetCookie, or
045: * <strong>null</strong>.
046: */
047:
048: public String getComment() {
049: return comment;
050: }
051:
052: /**
053: * Set this SetCookie attached comment.
054: * @param comment A String giving the comments attached to that SetCookie,
055: * or <strong>null</strong> to reset the value.
056: */
057:
058: public void setComment(String comment) {
059: this .comment = comment;
060: }
061:
062: /**
063: * Get the domain to which this cookie applies.
064: * @return The string encoding of the domain to which this cookie applies
065: * or <strong>null</strong> if undefined.
066: */
067:
068: public String getDomain() {
069: return domain;
070: }
071:
072: /**
073: * Define the domain for this SetCookie.
074: * @param domain The String encoded domain name to which this cookie will
075: * apply.
076: */
077:
078: public void setDomain(String domain) {
079: this .domain = domain;
080: }
081:
082: /**
083: * Get the max age value for this cookie.
084: * @return A integer number of seconds giving the maximum age allowed for
085: * this cookie, or <strong>-1</strong> if undefined.
086: */
087:
088: public int getMaxAge() {
089: return maxage;
090: }
091:
092: /**
093: * Set the max age value for this cookie.
094: * @param maxage The max age value for this cookie, given as a number of
095: * seconds, or <strong>-1</strong> to reset value.
096: */
097:
098: public void setMaxAge(int maxage) {
099: this .maxage = maxage;
100: }
101:
102: /**
103: * Get the path in which this cookie will apply.
104: * @return The path to which this cookie applies, encoded as a String, or
105: * <strong>null</strong> if undefined.
106: */
107:
108: public String getPath() {
109: return path;
110: }
111:
112: /**
113: * Set the path to which this SetCookie applies.
114: * @param path The path, encoded as a String.
115: */
116:
117: public void setPath(String path) {
118: this .path = path;
119: }
120:
121: /**
122: * Get the security requirement atttached to that cookie.
123: * @return A boolean, <strong>true</strong> if the cookie requires
124: * special care from the client, <strong>false</strong> otherwise.
125: */
126:
127: public boolean getSecurity() {
128: return security;
129: }
130:
131: /**
132: * Mark/unmark this SetCookie as requiring special security when emited
133: * back by the client.
134: * @param onoff A boolean, <stronmg>true</strong> if the cookie that
135: * results should be emited with special care, <strong>false</strong>
136: * otherwise.
137: */
138:
139: public void setSecurity(boolean onoff) {
140: this .security = onoff;
141: }
142:
143: /**
144: * Get the SetCookie version number.
145: * @return An integer giving the version number of this cookie.
146: */
147:
148: public int getVersion() {
149: return version;
150: }
151:
152: /**
153: * Set the SetCookie version number.
154: * @param version The version number of this SetCookie.
155: */
156:
157: public void setVersion(int version) {
158: this .version = version;
159: }
160:
161: /**
162: * Set this SetCookie name.
163: * @param name The name of the cookie, encoded as a String.
164: */
165:
166: public void setName(String name) {
167: this .name = name;
168: }
169:
170: /**
171: * Get this SetCookie cookie's name.
172: * @return A String giving the cookie's name.
173: */
174:
175: public String getName() {
176: return name;
177: }
178:
179: /**
180: * Set this SetCookie cookie's value.
181: * @param value The value, encoded as a printable String, or <strong>
182: * null</strong> to reset the value.
183: */
184:
185: public void setValue(String value) {
186: this .value = value;
187: }
188:
189: /**
190: * Get the value associated with this SetCookie.
191: * @return The value, encoded as a String, or <strong>null</strong> if
192: * undefined.
193: */
194:
195: public String getValue() {
196: return value;
197: }
198:
199: public String toString() {
200: String cookie = name + "=" + value;
201: if (comment != null)
202: cookie = cookie + "; comment=" + comment;
203: if (maxage != -1)
204: cookie = cookie + "; maxage=" + maxage;
205: if (domain != null)
206: cookie = cookie + "; domain=" + domain;
207: if (path != null)
208: cookie = cookie + "; path=" + path;
209: if (security)
210: cookie = cookie + "; secure";
211: return cookie;
212: }
213:
214: public HttpSetCookie(boolean isValid, String name, String value) {
215: this .name = name;
216: this .value = value;
217: }
218:
219: public HttpSetCookie(String name, String value) {
220: this .name = name;
221: this .value = value;
222: }
223:
224: public HttpSetCookie() {
225: }
226: }
|