]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WOSession+JS.m
Xcode projects
[sope] / sope-appserver / NGObjWeb / WOSession+JS.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "common.h"
24 #include <NGObjWeb/NGObjWeb.h>
25
26 /*
27   WOSession JavaScript object
28
29   Properties
30
31     String sessionID
32     String domainForIDCookies
33     Date   expirationDateForIDCookies
34     bool   isDistributionEnabled
35     bool   isTerminating
36     Array  languages
37     Object statistics
38     Number timeOut
39     bool   storesIDsInCookies
40     bool   storesIDsInURLs
41
42   Methods
43
44     WOComponent restorePageForContextID(ctxid)
45                 savePage(page)
46                 savePageInPermanentCache(page)
47                 terminate()
48                 print(string [,..string])
49 */
50
51 static NSNumber *nYes = nil;
52 static NSNumber *nNo  = nil;
53
54 @implementation WOSession(JSFunctions)
55
56 - (id)_jsfunc_restorePageForContextID:(NSArray *)_args {
57   return [self restorePageForContextID:[[_args objectAtIndex:0] stringValue]];
58 }
59 - (id)_jsfunc_savePage:(NSArray *)_args {
60   [self savePage:[_args objectAtIndex:0]];
61   return self;
62 }
63 - (id)_jsfunc_savePageInPermanentCache:(NSArray *)_args {
64   [self savePageInPermanentCache:[_args objectAtIndex:0]];
65   return self;
66 }
67 - (id)_jsfunc_terminate:(NSArray *)_args {
68   [self terminate];
69   return self;
70 }
71
72 - (id)_jsfunc_print:(NSArray *)_args {
73   NSEnumerator    *e;
74   id              o;
75   BOOL            isFirst;
76   NSMutableString *ms;
77   
78   isFirst = YES;
79   ms = [NSMutableString stringWithCapacity:128];
80   
81   e = [_args objectEnumerator];
82   while ((o = [e nextObject])) {
83     NSString *s;
84
85     if (!isFirst) [ms appendString:@" "];
86     else isFirst = NO;
87     
88     s = [o stringValue];
89     [ms appendString:s];
90   }
91   
92   [self logWithFormat:@"%@", ms];
93   
94   return self;
95 }
96
97 @end
98
99 @implementation WOSession(JSProperties)
100
101 + (void)initialize {
102   if (nYes == nil) nYes = [[NSNumber alloc] initWithBool:YES];
103   if (nNo  == nil) nNo  = [[NSNumber alloc] initWithBool:NO];
104 }
105
106 - (id)_jsprop_sessionID {
107   return [self sessionID];
108 }
109 - (id)_jsprop_domainForIDCookies {
110   return [self domainForIDCookies];
111 }
112 - (id)_jsprop_expirationDateForIDCookies {
113   return [self expirationDateForIDCookies];
114 }
115
116 - (id)_jsprop_isDistributionEnabled:(id)_value {
117   [self setDistributionEnabled:[_value boolValue]];
118   return self;
119 }
120 - (id)_jsprop_isDistributionEnabled {
121   return [self isDistributionEnabled] ? nYes : nNo;
122 }
123
124 - (id)_jsprop_isTerminating {
125   return [self isTerminating] ? nYes : nNo;
126 }
127
128 - (id)_jsprop_languages:(id)_value {
129   [self setLanguages:_value];
130   return self;
131 }
132 - (id)_jsprop_languages {
133   return [self languages];
134 }
135
136 - (id)_jsprop_statistics {
137   return [self statistics];
138 }
139
140 - (id)_jsprop_timeOut:(id)_value {
141   [self setTimeOut:[_value doubleValue]];
142   return self;
143 }
144 - (id)_jsprop_timeOut {
145   return [NSNumber numberWithDouble:[self timeOut]];
146 }
147
148 - (id)_jsprop_storesIDsInCookies:(id)_value {
149   [self setStoresIDsInCookies:[_value boolValue]];
150   return self;
151 }
152 - (id)_jsprop_storesIDsInCookies {
153   return [self storesIDsInCookies] ? nYes : nNo;
154 }
155
156 - (id)_jsprop_storesIDsInURLs:(id)_value {
157   [self setStoresIDsInURLs:[_value boolValue]];
158   return self;
159 }
160 - (id)_jsprop_storesIDsInURLs {
161   return [self storesIDsInURLs] ? nYes : nNo;
162 }
163
164 @end /* WOSession(JSProperties) */