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