2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
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>
33 @implementation WODirectAction
39 - (id)initWithRequest:(WORequest *)_request {
40 if ((self = [super init])) {
44 - (id)initWithContext:(WOContext *)_ctx {
45 if ((self = [self initWithRequest:[_ctx request]])) {
46 self->context = [_ctx retain];
51 return [self initWithRequest:nil];
55 [self->context release];
61 - (WOContext *)context {
62 if (self->context == nil)
63 self->context = [[[WOApplication application] context] retain];
67 - (WORequest *)request {
68 return [[self context] request];
71 - (WOSession *)session {
72 return [[self context] session];
75 - (WOSession *)existingSession {
76 WOContext *ctx = [self context];
78 /* check whether the context has a session */
80 return [ctx hasSession] ? [ctx session] : nil;
85 - (id<WOActionResults>)performActionNamed:(NSString *)_actionName {
89 /* discard everything after a point in the URL */
90 rng = [_actionName rangeOfString:@"."];
92 _actionName = [_actionName substringToIndex:rng.location];
94 _actionName = [_actionName stringByAppendingString:@"Action"];
95 actionSel = NSSelectorFromString(_actionName);
97 if ([self respondsToSelector:actionSel])
98 return [self performSelector:actionSel];
100 [self logWithFormat:@"DirectAction class %@ cannot handle action %@",
101 NSStringFromClass([self class]), _actionName];
106 /* applying form values */
108 - (void)takeFormValuesForKeyArray:(NSArray *)_keys {
114 keys = [_keys objectEnumerator];
116 while ((key = [keys nextObject])) {
119 value = [rq formValueForKey:key];
121 [self takeValue:value forKey:key];
124 - (void)takeFormValuesForKeys:(NSString *)_key1,... {
133 for (key = _key1; key; key = va_arg(va, NSString *)) {
136 value = [rq formValueForKey:key];
137 [self takeValue:value forKey:key];
143 - (void)takeFormValueArraysForKeyArray:(NSArray *)_keys {
149 keys = [_keys objectEnumerator];
151 while ((key = [keys nextObject])) {
154 value = [rq formValuesForKey:key];
155 [self takeValue:value forKey:key];
158 - (void)takeFormValueArraysForKeys:(NSString *)_key1,... {
167 for (key = _key1; key; key = va_arg(va, NSString *)) {
170 value = [rq formValuesForKey:key];
171 [self takeValue:value forKey:key];
179 - (WOComponent *)pageWithName:(NSString *)_name {
180 return [[WOApplication application]
182 inContext:[self context]];
187 - (NSString *)loggingPrefix {
188 return [NSString stringWithFormat:@">%@>", NSStringFromClass([self class])];
190 - (BOOL)isDebuggingEnabled {
191 static char showDebug = 2;
194 showDebug = [WOApplication isDebuggingEnabled] ? 1 : 0;
195 return showDebug ? YES : NO;
198 /* Key-Value coding */
200 - (void)takeValue:(id)_value forKey:(NSString *)_key {
201 if (!WOSetKVCValueUsingMethod(self, _key, _value))
202 [self handleTakeValue:_value forUnboundKey:_key];
204 - (id)valueForKey:(NSString *)_key {
205 return WOGetKVCValueUsingMethod(self, _key);
208 @end /* WODirectAction */