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
00032 @implementation CPCookie : CPObject
00033 {
00034 CPString _cookieName;
00035 CPString _cookieValue;
00036
00037 CPString _expires;
00038 }
00039
00044 - (id)initWithName:(CPString)aName
00045 {
00046 self = [super init];
00047
00048 _cookieName = aName;
00049 _cookieValue = [self _readCookieValue];
00050
00051 return self;
00052 }
00053
00057 - (CPString)value
00058 {
00059 return _cookieValue;
00060 }
00061
00065 - (CPString)name
00066 {
00067 return _cookieName;
00068 }
00069
00073 - (CPString)expires
00074 {
00075 return _expires;
00076 }
00077
00084 - (void)setValue:(CPString)value expires:(CPDate)date domain:(CPString)domain
00085 {
00086 if(date)
00087 var expires = "; expires="+date.toGMTString();
00088 else
00089 var expires = "";
00090
00091 if(domain)
00092 domain = "; domain="+domain;
00093 else
00094 domain = "";
00095
00096 document.cookie = _cookieName+"="+value+expires+"; path=/"+domain;
00097 }
00098
00099
00100 - (CPString)_readCookieValue
00101 {
00102 var nameEQ = _cookieName + "=";
00103 var ca = document.cookie.split(';');
00104 for(var i=0;i < ca.length;i++) {
00105 var c = ca[i];
00106 while (c.charAt(0)==' ') c = c.substring(1,c.length);
00107 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
00108 }
00109 return "";
00110 }
00111
00112 @end
00113
00114