001    package railo.runtime.thread;
002    
003    import java.io.Serializable;
004    
005    import javax.servlet.http.Cookie;
006    
007    public class SerializableCookie implements Serializable {
008    
009            private String comment;
010            private String domain;
011            private int maxAge;
012            private String name;
013            private String path;
014            private boolean secure;
015            private String value;
016            private int version;
017    
018    
019            public SerializableCookie(String comment, String domain, int maxAge, String name, String path, boolean secure, String value, int version) {
020                    this.comment = comment;
021                    this.domain = domain;
022                    this.maxAge = maxAge;
023                    this.name = name;
024                    this.path = path;
025                    this.secure = secure;
026                    this.value = value;
027                    this.version = version;
028            }
029            
030            public SerializableCookie(Cookie cookie) {
031                    this.comment = cookie.getComment();
032                    this.domain = cookie.getDomain();
033                    this.maxAge = cookie.getMaxAge();
034                    this.name = cookie.getName();
035                    this.path = cookie.getPath();
036                    this.secure = cookie.getSecure();
037                    this.value = cookie.getValue();
038                    this.version = cookie.getVersion();
039            }
040    
041            /**
042             * @see javax.servlet.http.Cookie#getComment()
043             */
044            public String getComment() {
045                    return comment;
046            }
047    
048            /**
049             * @see javax.servlet.http.Cookie#getDomain()
050             */
051            public String getDomain() {
052                    return domain;
053            }
054    
055            /**
056             * @see javax.servlet.http.Cookie#getMaxAge()
057             */
058            public int getMaxAge() {
059                    return maxAge;
060            }
061    
062            /**
063             * @see javax.servlet.http.Cookie#getName()
064             */
065            public String getName() {
066                    return name;
067            }
068    
069            /**
070             * @see javax.servlet.http.Cookie#getPath()
071             */
072            public String getPath() {
073                    return path;
074            }
075    
076            /**
077             * @see javax.servlet.http.Cookie#getSecure()
078             */
079            public boolean getSecure() {
080                    return secure;
081            }
082    
083            /**
084             * @see javax.servlet.http.Cookie#getValue()
085             */
086            public String getValue() {
087                    return value;
088            }
089    
090            /**
091             * @see javax.servlet.http.Cookie#getVersion()
092             */
093            public int getVersion() {
094                    return version;
095            }
096    
097            /**
098             * @see javax.servlet.http.Cookie#setComment(java.lang.String)
099             */
100            public void setComment(String purpose) {
101                    this.comment=purpose;
102            }
103    
104            /**
105             * @see javax.servlet.http.Cookie#setDomain(java.lang.String)
106             */
107            public void setDomain(String pattern) {
108                    this.domain=pattern;
109            }
110    
111            /**
112             * @see javax.servlet.http.Cookie#setMaxAge(int)
113             */
114            public void setMaxAge(int expiry) {
115                    this.maxAge=expiry;
116            }
117    
118            /**
119             * @see javax.servlet.http.Cookie#setPath(java.lang.String)
120             */
121            public void setPath(String uri) {
122                    this.path=uri;
123            }
124    
125            /**
126             * @see javax.servlet.http.Cookie#setSecure(boolean)
127             */
128            public void setSecure(boolean secure) {
129                    this.secure=secure;
130            }
131    
132            /**
133             * @see javax.servlet.http.Cookie#setValue(java.lang.String)
134             */
135            public void setValue(String value) {
136                    this.value=value;
137            }
138    
139            /**
140             * @see javax.servlet.http.Cookie#setVersion(int)
141             */
142            public void setVersion(int version) {
143                    this.version=version;
144            }
145    
146            
147            public Cookie toCookie() {
148                    Cookie c = new Cookie(name,value);
149                    if(comment!=null)c.setComment(comment);
150                    if(domain!=null)c.setDomain(domain);
151                    c.setMaxAge(maxAge);
152                    if(path!=null)c.setPath(path);
153                    c.setSecure(secure);
154                    c.setVersion(version);
155                    return c;
156            }
157    
158            public static Cookie[] toCookies(SerializableCookie[] src) {
159                    if(src==null)return new Cookie[0];
160                    Cookie[] dest=new Cookie[src.length];
161                    for(int i=0;i<src.length;i++) {
162                            dest[i]=src[i].toCookie();
163                    }
164                    return dest;
165            }
166            
167            public static SerializableCookie[] toSerializableCookie(Cookie[] src) {
168                    if(src==null)return new SerializableCookie[0];
169                    SerializableCookie[] dest=new SerializableCookie[src.length];
170                    for(int i=0;i<src.length;i++) {
171                            dest[i]=new SerializableCookie(src[i]);
172                    }
173                    return dest;
174            }
175    }