]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WODirectAction.m
removed bogus line
[sope] / sope-appserver / NGObjWeb / WODirectAction.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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: WODirectAction.m 1 2004-08-20 10:08:27Z znek $
22
23 #include <NGObjWeb/WODirectAction.h>
24 #include "NSObject+WO.h"
25 #include <NGObjWeb/WOSession.h>
26 #include <NGObjWeb/WOApplication.h>
27 #include <NGObjWeb/WOContext.h>
28 #include <NGObjWeb/WORequest.h>
29 #include <NGObjWeb/WOSession.h>
30 #include <NGObjWeb/WOSessionStore.h>
31 #include "common.h"
32
33 #if !LIB_FOUNDATION_LIBRARY
34 #  define NG_USE_KVC_FALLBACK 1
35 #endif
36
37 @implementation WODirectAction
38
39 + (int)version {
40   return 4;
41 }
42
43 - (id)initWithRequest:(WORequest *)_request {
44   if ((self = [super init])) {
45   }
46   return self;
47 }
48 - (id)initWithContext:(WOContext *)_ctx {
49   if ((self = [self initWithRequest:[_ctx request]])) {
50     self->context = [_ctx retain];
51   }
52   return self;
53 }
54 - (id)init {
55   return [self initWithRequest:nil];
56 }
57
58 - (void)dealloc {
59   [self->context release];
60   [super dealloc];
61 }
62
63 /* accessors */
64
65 - (WOContext *)context {
66   if (self->context == nil)
67     self->context = [[[WOApplication application] context] retain];
68   return self->context;
69 }
70
71 - (WORequest *)request {
72   return [[self context] request];
73 }
74
75 - (WOSession *)session {
76   return [[self context] session];
77 }
78
79 - (WOSession *)existingSession {
80   WOContext *ctx = [self context];
81   
82   /* check whether the context has a session */
83   
84   return [ctx hasSession] ? [ctx session] : nil;
85 }
86
87 /* perform actions */
88
89 - (id<WOActionResults>)performActionNamed:(NSString *)_actionName {
90   SEL actionSel;
91   NSRange rng;
92
93   /* discard everything after a point in the URL */
94   rng = [_actionName rangeOfString:@"."];
95   if (rng.length > 0)
96     _actionName = [_actionName substringToIndex:rng.location];
97
98   _actionName = [_actionName stringByAppendingString:@"Action"];
99   actionSel   = NSSelectorFromString(_actionName);
100   
101   if ([self respondsToSelector:actionSel]) 
102     return [self performSelector:actionSel];
103   else {
104     [self logWithFormat:@"DirectAction class %@ cannot handle action %@",
105             NSStringFromClass([self class]), _actionName];
106     return nil;
107   }
108 }
109
110 /* applying form values */
111
112 - (void)takeFormValuesForKeyArray:(NSArray *)_keys {
113   NSEnumerator *keys;
114   NSString     *key;
115   WORequest    *rq;
116
117   rq   = [self request];
118   keys = [_keys objectEnumerator];
119
120   while ((key = [keys nextObject])) {
121     NSString *value;
122
123     value = [rq formValueForKey:key];
124     
125     [self takeValue:value forKey:key];
126   }
127 }
128 - (void)takeFormValuesForKeys:(NSString *)_key1,... {
129   va_list   va;
130   NSString  *key;
131   WORequest *rq;
132
133   rq = [self request];
134
135   va_start(va, _key1);
136   {  
137     for (key = _key1; key; key = va_arg(va, NSString *)) {
138       NSString *value;
139
140       value = [rq formValueForKey:key];
141       [self takeValue:value forKey:key];
142     }
143   }
144   va_end(va);
145 }
146
147 - (void)takeFormValueArraysForKeyArray:(NSArray *)_keys {
148   NSEnumerator *keys;
149   NSString     *key;
150   WORequest    *rq;
151
152   rq   = [self request];
153   keys = [_keys objectEnumerator];
154
155   while ((key = [keys nextObject])) {
156     NSArray *value;
157
158     value = [rq formValuesForKey:key];
159     [self takeValue:value forKey:key];
160   }
161 }
162 - (void)takeFormValueArraysForKeys:(NSString *)_key1,... {
163   va_list   va;
164   NSString  *key;
165   WORequest *rq;
166
167   rq = [self request];
168   
169   va_start(va, _key1);
170   {  
171     for (key = _key1; key; key = va_arg(va, NSString *)) {
172       NSArray *value;
173
174       value = [rq formValuesForKey:key];
175       [self takeValue:value forKey:key];
176     }
177   }
178   va_end(va);
179 }
180
181 /* pages */
182
183 - (WOComponent *)pageWithName:(NSString *)_name {
184   return [[WOApplication application]
185                          pageWithName:_name
186                          inContext:[self context]];
187 }
188
189 /* logging */
190
191 - (NSString *)loggingPrefix {
192   return [NSString stringWithFormat:@">%@>", NSStringFromClass([self class])];
193 }
194 - (BOOL)isDebuggingEnabled {
195   static char showDebug = 2;
196   
197   if (showDebug == 2)
198     showDebug = [WOApplication isDebuggingEnabled] ? 1 : 0;
199   return showDebug ? YES : NO;
200 }
201
202 /* Key-Value coding */
203
204 - (void)takeValue:(id)_value forKey:(NSString *)_key {
205   if (!WOSetKVCValueUsingMethod(self, _key, _value))
206     [self handleTakeValue:_value forUnboundKey:_key];
207 }
208 - (id)valueForKey:(NSString *)_key {
209   return WOGetKVCValueUsingMethod(self, _key);
210 }
211
212 #if !LIB_FOUNDATION_LIBRARY
213
214 - (void)setValue:(id)_value forUndefinedKey:(NSString *)_key {
215   [self warnWithFormat:
216           @"tried to set value for undefined KVC key: '%@'", _key];
217 }
218 - (id)valueForUndefinedKey:(NSString *)_key {
219   [self warnWithFormat:
220              @"tried to access undefined KVC key: '%@'", _key];
221   return nil;
222 }
223
224 #endif
225
226 @end /* WODirectAction */