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
21 // $Id: WODirectAction.m 1 2004-08-20 10:08:27Z znek $
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 #if !LIB_FOUNDATION_LIBRARY
34 # define NG_USE_KVC_FALLBACK 1
37 @implementation WODirectAction
43 - (id)initWithRequest:(WORequest *)_request {
44 if ((self = [super init])) {
48 - (id)initWithContext:(WOContext *)_ctx {
49 if ((self = [self initWithRequest:[_ctx request]])) {
50 self->context = [_ctx retain];
55 return [self initWithRequest:nil];
59 [self->context release];
65 - (WOContext *)context {
66 if (self->context == nil)
67 self->context = [[[WOApplication application] context] retain];
71 - (WORequest *)request {
72 return [[self context] request];
75 - (WOSession *)session {
76 return [[self context] session];
79 - (WOSession *)existingSession {
80 WOContext *ctx = [self context];
82 /* check whether the context has a session */
84 return [ctx hasSession] ? [ctx session] : nil;
89 - (id<WOActionResults>)performActionNamed:(NSString *)_actionName {
93 /* discard everything after a point in the URL */
94 rng = [_actionName rangeOfString:@"."];
96 _actionName = [_actionName substringToIndex:rng.location];
98 _actionName = [_actionName stringByAppendingString:@"Action"];
99 actionSel = NSSelectorFromString(_actionName);
101 if ([self respondsToSelector:actionSel])
102 return [self performSelector:actionSel];
104 [self logWithFormat:@"DirectAction class %@ cannot handle action %@",
105 NSStringFromClass([self class]), _actionName];
110 /* applying form values */
112 - (void)takeFormValuesForKeyArray:(NSArray *)_keys {
118 keys = [_keys objectEnumerator];
120 while ((key = [keys nextObject])) {
123 value = [rq formValueForKey:key];
125 [self takeValue:value forKey:key];
128 - (void)takeFormValuesForKeys:(NSString *)_key1,... {
137 for (key = _key1; key; key = va_arg(va, NSString *)) {
140 value = [rq formValueForKey:key];
141 [self takeValue:value forKey:key];
147 - (void)takeFormValueArraysForKeyArray:(NSArray *)_keys {
153 keys = [_keys objectEnumerator];
155 while ((key = [keys nextObject])) {
158 value = [rq formValuesForKey:key];
159 [self takeValue:value forKey:key];
162 - (void)takeFormValueArraysForKeys:(NSString *)_key1,... {
171 for (key = _key1; key; key = va_arg(va, NSString *)) {
174 value = [rq formValuesForKey:key];
175 [self takeValue:value forKey:key];
183 - (WOComponent *)pageWithName:(NSString *)_name {
184 return [[WOApplication application]
186 inContext:[self context]];
191 - (NSString *)loggingPrefix {
192 return [NSString stringWithFormat:@">%@>", NSStringFromClass([self class])];
194 - (BOOL)isDebuggingEnabled {
195 static char showDebug = 2;
198 showDebug = [WOApplication isDebuggingEnabled] ? 1 : 0;
199 return showDebug ? YES : NO;
202 /* Key-Value coding */
204 - (void)takeValue:(id)_value forKey:(NSString *)_key {
205 if (!WOSetKVCValueUsingMethod(self, _key, _value))
206 [self handleTakeValue:_value forUnboundKey:_key];
208 - (id)valueForKey:(NSString *)_key {
209 return WOGetKVCValueUsingMethod(self, _key);
212 #if !LIB_FOUNDATION_LIBRARY
214 - (void)setValue:(id)_value forUndefinedKey:(NSString *)_key {
215 [self warnWithFormat:
216 @"tried to set value for undefined KVC key: '%@'", _key];
218 - (id)valueForUndefinedKey:(NSString *)_key {
219 [self warnWithFormat:
220 @"tried to access undefined KVC key: '%@'", _key];
226 @end /* WODirectAction */