# include <objc/objc-class.h>
#endif
+static BOOL usePool = NO;
static BOOL perflog = NO;
+static BOOL debugOn = NO;
static Class NSDateClass = Nil;
-//#define USE_POOLS 1
-
@implementation WODirectActionRequestHandler
+ (int)version {
return [super version] + 0 /* 2 */;
}
+ (void)initialize {
+ NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
+
NSAssert2([super version] == 2,
@"invalid superclass (%@) version %i !",
NSStringFromClass([self superclass]), [super version]);
NSDateClass = [NSDate class];
- perflog = [[NSUserDefaults standardUserDefaults]
- boolForKey:@"WOProfileDirectActionRequestHandler"];
+ perflog = [ud boolForKey:@"WOProfileDirectActionRequestHandler"];
}
- (NSString *)loggingPrefix {
/*
The request handler part of a direct action URI looks like this:
-
+
[actionClass/]actionName[?key=value&key=value&...]
*/
- (BOOL)isComponentClass:(Class)_clazz {
if (_clazz == Nil)
return NO;
- while ((_clazz = _clazz->super_class)) {
+ while ((_clazz = _clazz->super_class) != Nil) {
if (_clazz == [WOComponent class]) return YES;
if (_clazz == [WODirectAction class]) return NO;
if (_clazz == [NSObject class]) return NO;
if (actionClass == Nil)
return nil;
+
if (![self isComponentClass:actionClass]) {
/* create direct action object */
id actionObject;
session:(WOSession *)session
application:(WOApplication *)app
{
-#if USE_POOLS
- NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init];
-#endif
- NSString *actionClassName;
- NSString *actionName;
- WOResponse *response;
- NSArray *handlerPath;
- Class actionClass = Nil;
+ NSAutoreleasePool *pool2;
+ NSString *actionClassName;
+ NSString *actionName;
+ WOResponse *response;
+ NSArray *handlerPath;
+ Class actionClass = Nil;
WODirectAction *actionObject = nil;
id<WOActionResults> result = nil;
+
+ pool2 = usePool ? [[NSAutoreleasePool alloc] init] : nil;
*(&result) = nil;
*(&response) = nil;
handlerPath = [_request requestHandlerPathArray];
-#if DEBUG_DIRECT_ACTION
- [self debugWithFormat:@"path=%@ array=%@",
+ if (debugOn) {
+ [self debugWithFormat:@"path=%@ array=%@",
[_request requestHandlerPath], handlerPath];
-#endif
-
+ }
+
+ // TODO: fix OGo bug #1028
switch ([handlerPath count]) {
case 0:
actionClassName = @"DirectAction";
default:
actionClassName = [handlerPath objectAtIndex:0];
actionName = [handlerPath objectAtIndex:1];
-#if 0
- NSLog(@"invalid direction action URL: %@",
- [_request requestHandlerPath]);
-#endif
+ // TODO: set path info in ctx?
+ if (debugOn) {
+ [self logWithFormat:@"invalid direction action URL: %@",
+ [_request requestHandlerPath]];
+ }
break;
}
actionClass = [WODirectAction class];
}
-#if DEBUG_DIRECT_ACTION
- [self debugWithFormat:
- @"[direct action request handler] class=%@ action=%@ ..",
- actionClassName, actionName];
-#endif
+ if (debugOn) {
+ [self debugWithFormat:
+ @"[direct action request handler] class=%@ action=%@ ..",
+ actionClassName, actionName];
+ }
/* process request */
[session lock];
}
-#if USE_POOLS
- session = [session retain];
- [pool2 release]; pool2 = nil;
- session = [session autorelease];
-#endif
+ if (usePool) {
+ session = [session retain];
+ [pool2 release]; pool2 = nil;
+ session = [session autorelease];
+ }
response = [response autorelease];
}