00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import <Foundation/CPObject.j>
00024 @import <Foundation/CPString.j>
00025
00026
00030 @implementation CPCookie : CPObject
00031 {
00032 CPString _cookieName;
00033 CPString _cookieValue;
00034
00035 CPString _expires;
00036 }
00037
00042 - (id)initWithName:(CPString)aName
00043 {
00044 self = [super init];
00045
00046 _cookieName = aName;
00047 _cookieValue = [self _readCookieValue];
00048
00049 return self;
00050 }
00051
00055 - (CPString)value
00056 {
00057 return _cookieValue;
00058 }
00059
00063 - (CPString)name
00064 {
00065 return _cookieName;
00066 }
00067
00071 - (CPString)expires
00072 {
00073 return _expires;
00074 }
00075
00082 - (void)setValue:(CPString)value expires:(CPDate)date domain:(CPString)domain
00083 {
00084 if(date)
00085 var expires = "; expires="+date.toGMTString();
00086 else
00087 var expires = "";
00088
00089 if(domain)
00090 domain = "; domain="+domain;
00091 else
00092 domain = "";
00093
00094 document.cookie = _cookieName+"="+value+expires+"; path=/"+domain;
00095 }
00096
00097
00098 - (CPString)_readCookieValue
00099 {
00100 var nameEQ = _cookieName + "=";
00101 var ca = document.cookie.split(';');
00102 for(var i=0;i < ca.length;i++) {
00103 var c = ca[i];
00104 while (c.charAt(0)==' ') c = c.substring(1,c.length);
00105 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
00106 }
00107 return "";
00108 }
00109
00110 @end
00111
00112