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.tag;
020
021import lucee.runtime.exp.PageException;
022import lucee.runtime.ext.tag.TagImpl;
023import lucee.runtime.type.KeyImpl;
024
025/**
026* Defines cookie variables, including expiration and security options.
027*
028*
029*
030**/
031public final class Cookie extends TagImpl {
032
033        /** Yes or No. Specifies that the variable must transmit securely. If the browser does not support
034        **      Secure Socket Layer (SSL) security, the cookie is not sent. */
035        private boolean secure=false;
036
037        /** The value assigned to the cookie variable. */
038        private String value="";
039
040        /**  */
041        private String domain=null;
042
043        /**  */
044        private String path="/";
045
046        /** Schedules the expiration of a cookie variable. Can be specified as a date (as in, 10/09/97), 
047        **      number of days (as in, 10, 100), "Now", or "Never". Using Now effectively deletes the cookie from
048        **      the client browser. */
049        private Object expires=null;
050
051        /** The name of the cookie variable. */
052        private String name;
053        
054        private boolean httponly;
055        private boolean preservecase;
056        private boolean encode=true;
057
058
059        @Override
060        public void release()   {
061                super.release();
062                secure=false;
063                value="";
064                domain=null;
065                path="/";
066                expires=null;
067                name=null;
068                httponly=false;
069                preservecase=false;
070                encode=true;
071        }
072        
073        /** set the value secure
074        *  Yes or No. Specifies that the variable must transmit securely. If the browser does not support
075        *       Secure Socket Layer (SSL) security, the cookie is not sent.
076        * @param secure value to set
077        **/
078        public void setSecure(boolean secure)   {
079                this.secure=secure;
080        }
081
082        /** set the value value
083        *  The value assigned to the cookie variable.
084        * @param value value to set
085        **/
086        public void setValue(String value)      {
087                this.value=value;
088        }
089
090        /** set the value domain
091        *  
092        * @param domain value to set
093        **/
094        public void setDomain(String domain)    {
095                this.domain=domain;
096        }
097
098        /** set the value path
099        *  
100        * @param path value to set
101        **/
102        public void setPath(String path)        {
103                this.path=path;
104        }
105
106        /** set the value expires
107        *  Schedules the expiration of a cookie variable. Can be specified as a date (as in, 10/09/97), 
108        *       number of days (as in, 10, 100), "Now", or "Never". Using Now effectively deletes the cookie from
109        *       the client browser.
110        * @param expires value to set
111        **/
112        public void setExpires(Object expires)  {
113                this.expires=expires;
114        }
115        
116        /** set the value expires
117        *  Schedules the expiration of a cookie variable. Can be specified as a date (as in, 10/09/97), 
118        *       number of days (as in, 10, 100), "Now", or "Never". Using Now effectively deletes the cookie from
119        *       the client browser.
120        * @param expires value to set
121        * @deprecated replaced with setExpires(Object expires):void
122        **/
123        public void setExpires(String expires)  {
124                this.expires=expires;
125        }
126
127        /** set the value name
128        *  The name of the cookie variable.
129        * @param name value to set
130        **/
131        public void setName(String name)        {
132                this.name=name;
133        }
134
135        public void setHttponly(boolean httponly)       {
136                this.httponly=httponly;
137        }
138
139        public void setPreservecase(boolean preservecase)       {
140                this.preservecase=preservecase;
141        }
142
143        public void setEncodevalue(boolean encode)      {
144                this.encode=encode;
145        }
146
147        public void setEncode(boolean encode)   {
148                this.encode=encode;
149        }
150
151
152        @Override
153        public int doStartTag() throws PageException    {
154                pageContext.cookieScope().setCookie(KeyImpl.getInstance(name),value,expires,secure,path,domain,httponly,preservecase,encode);
155                return SKIP_BODY;
156        }
157
158        @Override
159        public int doEndTag()   {
160                return EVAL_PAGE;
161        }
162}