2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include <NGObjWeb/WODirectAction.h>
23 #include "NSObject+WO.h"
24 #include <NGObjWeb/WOSession.h>
25 #include <NGObjWeb/WOApplication.h>
26 #include <NGObjWeb/WOContext.h>
27 #include <NGObjWeb/WORequest.h>
28 #include <NGObjWeb/WOSession.h>
29 #include <NGObjWeb/WOSessionStore.h>
32 #if !LIB_FOUNDATION_LIBRARY
33 # define NG_USE_KVC_FALLBACK 1
36 @implementation WODirectAction
42 - (id)initWithRequest:(WORequest *)_request {
43 if ((self = [super init])) {
47 - (id)initWithContext:(WOContext *)_ctx {
48 if ((self = [self initWithRequest:[_ctx request]])) {
49 self->context = [_ctx retain];
54 return [self initWithRequest:nil];
58 [self->context release];
64 - (WOContext *)context {
65 if (self->context == nil)
66 self->context = [[[WOApplication application] context] retain];
70 - (WORequest *)request {
71 return [[self context] request];
74 - (WOSession *)session {
75 return [[self context] session];
78 - (WOSession *)existingSession {
79 WOContext *ctx = [self context];
81 /* check whether the context has a session */
83 return [ctx hasSession] ? [ctx session] : nil;
88 - (id<WOActionResults>)performActionNamed:(NSString *)_actionName {
92 /* discard everything after a point in the URL */
93 rng = [_actionName rangeOfString:@"."];
95 _actionName = [_actionName substringToIndex:rng.location];
97 _actionName = [_actionName stringByAppendingString:@"Action"];
98 actionSel = NSSelectorFromString(_actionName);
100 if ([self respondsToSelector:actionSel])
101 return [self performSelector:actionSel];
103 [self logWithFormat:@"DirectAction class %@ cannot handle action %@",
104 NSStringFromClass([self class]), _actionName];
109 /* applying form values */
111 - (void)takeFormValuesForKeyArray:(NSArray *)_keys {
117 keys = [_keys objectEnumerator];
119 while ((key = [keys nextObject])) {
122 value = [rq formValueForKey:key];
124 [self takeValue:value forKey:key];
127 - (void)takeFormValuesForKeys:(NSString *)_key1,... {
136 for (key = _key1; key; key = va_arg(va, NSString *)) {
139 value = [rq formValueForKey:key];
140 [self takeValue:value forKey:key];
146 - (void)takeFormValueArraysForKeyArray:(NSArray *)_keys {
152 keys = [_keys objectEnumerator];
154 while ((key = [keys nextObject])) {
157 value = [rq formValuesForKey:key];
158 [self takeValue:value forKey:key];
161 - (void)takeFormValueArraysForKeys:(NSString *)_key1,... {
170 for (key = _key1; key; key = va_arg(va, NSString *)) {
173 value = [rq formValuesForKey:key];
174 [self takeValue:value forKey:key];
182 - (WOComponent *)pageWithName:(NSString *)_name {
183 return [[WOApplication application]
185 inContext:[self context]];
190 - (NSString *)loggingPrefix {
191 return [NSString stringWithFormat:@">%@>", NSStringFromClass([self class])];
193 - (BOOL)isDebuggingEnabled {
194 static char showDebug = 2;
197 showDebug = [WOApplication isDebuggingEnabled] ? 1 : 0;
198 return showDebug ? YES : NO;
201 /* Key-Value coding */
203 - (void)takeValue:(id)_value forKey:(NSString *)_key {
204 if (!WOSetKVCValueUsingMethod(self, _key, _value))
205 [self handleTakeValue:_value forUnboundKey:_key];
207 - (id)valueForKey:(NSString *)_key {
208 return WOGetKVCValueUsingMethod(self, _key);
211 #if !LIB_FOUNDATION_LIBRARY
213 - (void)setValue:(id)_value forUndefinedKey:(NSString *)_key {
214 [self warnWithFormat:
215 @"tried to set value for undefined KVC key: '%@'", _key];
217 - (id)valueForUndefinedKey:(NSString *)_key {
218 [self warnWithFormat:
219 @"tried to access undefined KVC key: '%@'", _key];
225 @end /* WODirectAction */