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