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