001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.thread; 020 021import java.io.Serializable; 022 023import javax.servlet.http.Cookie; 024 025import lucee.runtime.type.scope.CookieImpl; 026 027public class SerializableCookie implements Serializable { 028 029 private static final long serialVersionUID = -7167614871212402517L; 030 031 private String comment; 032 private String domain; 033 private int maxAge; 034 private String name; 035 private String path; 036 private boolean secure; 037 private String value; 038 private int version; 039 private boolean httpOnly; 040 041 042 public SerializableCookie(String comment, String domain, int maxAge, String name, String path, boolean secure, String value, int version, boolean httpOnly) { 043 this.comment = comment; 044 this.domain = domain; 045 this.maxAge = maxAge; 046 this.name = name; 047 this.path = path; 048 this.secure = secure; 049 this.value = value; 050 this.version = version; 051 this.httpOnly = httpOnly; 052 } 053 054 public SerializableCookie(Cookie cookie) { 055 this.comment = cookie.getComment(); 056 this.domain = cookie.getDomain(); 057 this.maxAge = cookie.getMaxAge(); 058 this.name = cookie.getName(); 059 this.path = cookie.getPath(); 060 this.secure = cookie.getSecure(); 061 this.value = cookie.getValue(); 062 this.version = cookie.getVersion(); 063 this.httpOnly = CookieImpl.isHTTPOnly(cookie); 064 } 065 066 public String getComment() { 067 return comment; 068 } 069 070 public String getDomain() { 071 return domain; 072 } 073 074 public int getMaxAge() { 075 return maxAge; 076 } 077 078 public String getName() { 079 return name; 080 } 081 082 public String getPath() { 083 return path; 084 } 085 086 public boolean getSecure() { 087 return secure; 088 } 089 090 public String getValue() { 091 return value; 092 } 093 094 public int getVersion() { 095 return version; 096 } 097 098 public boolean isHttpOnly(){ 099 return httpOnly; 100 } 101 102 public void setComment(String purpose) { 103 this.comment=purpose; 104 } 105 106 public void setDomain(String pattern) { 107 this.domain=pattern; 108 } 109 110 public void setMaxAge(int expiry) { 111 this.maxAge=expiry; 112 } 113 114 public void setPath(String uri) { 115 this.path=uri; 116 } 117 118 public void setSecure(boolean secure) { 119 this.secure=secure; 120 } 121 122 public void setValue(String value) { 123 this.value=value; 124 } 125 126 public void setVersion(int version) { 127 this.version=version; 128 } 129 130 public void setHttpOnly(boolean httpOnly){ 131 this.httpOnly=httpOnly; 132 } 133 134 135 public Cookie toCookie() { 136 Cookie c = new Cookie(name,value); 137 if(comment!=null)c.setComment(comment); 138 if(domain!=null)c.setDomain(domain); 139 c.setMaxAge(maxAge); 140 if(path!=null)c.setPath(path); 141 c.setSecure(secure); 142 c.setVersion(version); 143 if(httpOnly)CookieImpl.setHTTPOnly(c); 144 return c; 145 } 146 147 public static Cookie[] toCookies(SerializableCookie[] src) { 148 if(src==null)return new Cookie[0]; 149 Cookie[] dest=new Cookie[src.length]; 150 for(int i=0;i<src.length;i++) { 151 dest[i]=src[i].toCookie(); 152 } 153 return dest; 154 } 155 156 public static SerializableCookie[] toSerializableCookie(Cookie[] src) { 157 if(src==null)return new SerializableCookie[0]; 158 SerializableCookie[] dest=new SerializableCookie[src.length]; 159 for(int i=0;i<src.length;i++) { 160 dest[i]=new SerializableCookie(src[i]); 161 } 162 return dest; 163 } 164}