2 Copyright (C) 2002-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 "SoApplication.h"
23 #include "SoClassRegistry.h"
24 #include "SoControlPanel.h"
26 #include "SoObjectRequestHandler.h"
27 #include "SoProductRegistry.h"
28 #include "SoSecurityManager.h"
29 #include "SoApplication.h"
30 #include "SoObject+SoDAV.h"
31 #include <NGObjWeb/WORequest.h>
34 @implementation SoApplication
36 static BOOL debugLookup = NO;
38 - (BOOL)loadProducts:(id)_spec {
40 // TODO: only load specified products
41 [self logWithFormat:@"load products (not implemented): %@", _spec];
45 [self->productRegistry loadAllProducts];
51 if ((self = [super init])) {
52 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
55 debugLookup = [ud boolForKey:@"SoDebugKeyLookup"];
57 /* setup global objects */
59 self->securityManager = [[SoSecurityManager sharedSecurityManager] retain];
60 self->classRegistry = [[SoClassRegistry sharedClassRegistry] retain];
61 self->productRegistry = [[SoProductRegistry sharedProductRegistry] retain];
63 /* Object Publishing */
64 tmp = [[SoObjectRequestHandler alloc] init];
65 [self registerRequestHandler:tmp forKey:@"so"];
66 [self registerRequestHandler:tmp forKey:@"dav"];
67 [self registerRequestHandler:tmp forKey:@"RPC2"];
68 [self setDefaultRequestHandler:tmp];
71 /* load products (all if SoApplicationLoadProducts is not set) */
72 if (![self loadProducts:[ud objectForKey:@"SoApplicationLoadProducts"]]) {
73 [self logWithFormat:@"failed to load the products ..."];
78 #if LIB_FOUNDATION_LIBRARY
80 if ([[ud objectForKey:@"EnableDoubleReleaseCheck"] boolValue])
81 [NSAutoreleasePool enableDoubleReleaseCheck:YES];
88 [self->securityManager release];
89 [self->classRegistry release];
90 [self->productRegistry release];
96 - (SoProductRegistry *)productRegistry {
97 return self->productRegistry;
99 - (SoClassRegistry *)classRegistry {
100 return self->classRegistry;
102 - (SoSecurityManager *)securityManager {
103 return self->securityManager;
106 /* application as the SoObject root */
108 - (id)rootObjectInContext:(id)_ctx {
112 - (NSException *)validateName:(NSString *)_key inContext:(id)_ctx {
115 if ([self hasName:_key inContext:_ctx])
116 return [super validateName:_key inContext:_ctx];
118 root = [self rootObjectInContext:_ctx];
119 return (root != self)
120 ? [root validateName:_key inContext:_ctx]
121 : [super validateName:_key inContext:_ctx];
124 - (BOOL)hasName:(NSString *)_key inContext:(id)_ctx {
127 if ([_key isEqualToString:@"ControlPanel"])
130 if ([[self registeredRequestHandlerKeys] containsObject:_key])
133 if ([super hasName:_key inContext:_ctx])
136 root = [self rootObjectInContext:_ctx];
138 return [root hasName:_key inContext:_ctx];
143 - (id)controlPanel:(NSString *)_name inContext:(id)_ctx {
144 return [[[SoControlPanel alloc] init] autorelease];
147 - (BOOL)isApplicationNameLookup:(NSString *)_name inContext:(id)_ctx {
148 static NSString *WOApplicationSuffix = nil;
151 appName = [[(WOContext *)_ctx request] applicationName];
152 if ([_name isEqual:appName]) {
153 if (debugLookup) [self logWithFormat:@" matched appname: %@", appName];
157 if (WOApplicationSuffix == nil) {
158 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
159 WOApplicationSuffix = [[ud stringForKey:@"WOApplicationSuffix"] copy];
161 appName = [appName stringByAppendingString:WOApplicationSuffix];
162 if ([_name isEqual:appName]) {
163 if (debugLookup) [self logWithFormat:@" matched appname: %@", appName];
170 - (id)lookupName:(NSString *)_name inContext:(id)_ctx acquire:(BOOL)_flag {
173 if ([_name isEqualToString:@"ControlPanel"])
174 return [self controlPanel:_name inContext:_ctx];
176 if ([[self registeredRequestHandlerKeys] containsObject:_name]) {
178 need to check registeredRequestHandlerKeys because requestHandlerForKey:
179 returns the default handler if the key could not be found ...
181 if ((v = [super requestHandlerForKey:_name]))
185 if (debugLookup) [self logWithFormat:@"lookup name: %@", _name];
187 if ((v = [super lookupName:_name inContext:_ctx acquire:NO]) == nil) {
190 root = [self rootObjectInContext:_ctx];
191 if (debugLookup) [self logWithFormat:@" lookup in root object: %@", v];
194 v = [root lookupName:_name inContext:_ctx acquire:_flag];
195 else if (debugLookup)
196 [self logWithFormat:@" root is application object"];
199 if (debugLookup) [self logWithFormat:@" GOT: %@", v];
202 hack to allow "/myapp/folder/", it is a hack because it also allows
203 /myapp/myapp/myapp/.../folder/ ...
205 if (v == nil && [self isApplicationNameLookup:_name inContext:_ctx]) {
207 if (debugLookup) [self logWithFormat:@" => rewrote value: %@", self];
213 - (NSArray *)toOneRelationshipKeys {
217 ma = ((root = [super toOneRelationshipKeys]))
218 ? [[NSMutableSet alloc] initWithArray:root]
219 : [[NSMutableSet alloc] init];
221 [ma addObjectsFromArray:[self registeredRequestHandlerKeys]];
222 [ma addObject:@"ControlPanel"];
224 root = [self rootObjectInContext:[self context]];
225 if (root != nil && (root != self))
226 [ma addObjectsFromArray:[root toOneRelationshipKeys]];
228 root = [ma allObjects];
233 /* WebDAV support for root objects */
235 - (id)davCreateObject:(NSString *)_name
236 properties:(NSDictionary *)_props
241 if ((root = [self rootObjectInContext:_ctx]) == nil)
242 return [super davCreateObject:_name properties:_props inContext:_ctx];
244 return [root davCreateObject:_name properties:_props inContext:_ctx];
247 - (NSException *)davCreateCollection:(NSString *)_name inContext:(id)_ctx {
250 if ((root = [self rootObjectInContext:_ctx]) == nil)
251 return [super davCreateCollection:_name inContext:_ctx];
253 //[self debugWithFormat:@"let root '%@' create collection '%@'", root,_name];
254 return [root davCreateCollection:_name inContext:_ctx];
257 @end /* SoApplication */