001: /*
002: * Helma License Notice
003: *
004: * The contents of this file are subject to the Helma License
005: * Version 2.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://adele.helma.org/download/helma/license.txt
008: *
009: * Copyright 1998-2003 Helma Software. All Rights Reserved.
010: *
011: * $RCSfile$
012: * $Author: root $
013: * $Revision: 8604 $
014: * $Date: 2007-09-28 15:16:38 +0200 (Fre, 28 Sep 2007) $
015: */
016:
017: package helma.framework;
018:
019: import java.io.Serializable;
020: import javax.servlet.http.Cookie;
021:
022: /**
023: * Cookie Transmitter. A simple, serializable representation
024: * of an HTTP cookie.
025: */
026: public final class CookieTrans implements Serializable {
027: String name;
028: String value;
029: String path;
030: String domain;
031: int days = -1;
032:
033: CookieTrans(String name, String value) {
034: this .name = name;
035: this .value = value;
036: }
037:
038: void setValue(String value) {
039: this .value = value;
040: }
041:
042: void setDays(int days) {
043: this .days = days;
044: }
045:
046: void setPath(String path) {
047: this .path = path;
048: }
049:
050: void setDomain(String domain) {
051: this .domain = domain;
052: }
053:
054: /**
055: *
056: *
057: * @return ...
058: */
059: public String getName() {
060: return name;
061: }
062:
063: /**
064: *
065: *
066: * @return ...
067: */
068: public String getValue() {
069: return value;
070: }
071:
072: /**
073: *
074: *
075: * @return ...
076: */
077: public int getDays() {
078: return days;
079: }
080:
081: /**
082: *
083: *
084: * @return ...
085: */
086: public String getPath() {
087: return path;
088: }
089:
090: /**
091: *
092: *
093: * @return ...
094: */
095: public String getDomain() {
096: return domain;
097: }
098:
099: /**
100: *
101: *
102: * @param defaultPath ...
103: * @param defaultDomain ...
104: *
105: * @return ...
106: */
107: public Cookie getCookie(String defaultPath, String defaultDomain) {
108: Cookie c = new Cookie(name, value);
109:
110: // NOTE: If cookie version is set to 1, cookie values will be quoted.
111: // c.setVersion(1);
112:
113: if (days > -1) {
114: // Cookie time to live, days -> seconds
115: c.setMaxAge(days * 60 * 60 * 24);
116: }
117:
118: if (path != null) {
119: c.setPath(path);
120: } else if (defaultPath != null) {
121: c.setPath(defaultPath);
122: }
123:
124: if (domain != null) {
125: c.setDomain(domain);
126: } else if (defaultDomain != null) {
127: c.setDomain(defaultDomain);
128: }
129:
130: return c;
131: }
132: }
|