2 Copyright (C) 2002-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 "SoApplication.h"
24 #include "SoClassRegistry.h"
25 #include "SoControlPanel.h"
27 #include "SoObjectRequestHandler.h"
28 #include "SoProductRegistry.h"
29 #include "SoSecurityManager.h"
30 #include "SoApplication.h"
31 #include "SoObject+SoDAV.h"
32 #include <NGObjWeb/WORequest.h>
35 @implementation SoApplication
37 static BOOL debugLookup = NO;
39 - (BOOL)loadProducts:(id)_spec {
41 // TODO: load specified products
42 [self logWithFormat:@"load products (not implemented): %@", _spec];
46 [self->productRegistry loadAllProducts];
52 if ((self = [super init])) {
53 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
56 debugLookup = [ud boolForKey:@"SoDebugKeyLookup"];
58 /* setup global objects */
60 self->securityManager = [[SoSecurityManager sharedSecurityManager] retain];
61 self->classRegistry = [[SoClassRegistry sharedClassRegistry] retain];
62 self->productRegistry = [[SoProductRegistry sharedProductRegistry] retain];
64 /* Object Publishing */
65 tmp = [[SoObjectRequestHandler alloc] init];
66 [self registerRequestHandler:tmp forKey:@"so"];
67 [self registerRequestHandler:tmp forKey:@"dav"];
68 [self registerRequestHandler:tmp forKey:@"RPC2"];
69 [self setDefaultRequestHandler:tmp];
73 if (![self loadProducts:[ud objectForKey:@"SoApplicationLoadProducts"]]) {
74 [self logWithFormat:@"failed to load the products ..."];
79 #if LIB_FOUNDATION_LIBRARY
81 if ([[ud objectForKey:@"EnableDoubleReleaseCheck"] boolValue])
82 [NSAutoreleasePool enableDoubleReleaseCheck:YES];
89 [self->securityManager release];
90 [self->classRegistry release];
91 [self->productRegistry release];
97 - (SoProductRegistry *)productRegistry {
98 return self->productRegistry;
100 - (SoClassRegistry *)classRegistry {
101 return self->classRegistry;
103 - (SoSecurityManager *)securityManager {
104 return self->securityManager;
107 /* application as the SoObject root */
109 - (id)rootObjectInContext:(id)_ctx {
113 - (NSException *)validateName:(NSString *)_key inContext:(id)_ctx {
116 if ([self hasName:_key inContext:_ctx])
117 return [super validateName:_key inContext:_ctx];
119 root = [self rootObjectInContext:_ctx];
120 return (root != self)
121 ? [root validateName:_key inContext:_ctx]
122 : [super validateName:_key inContext:_ctx];
125 - (BOOL)hasName:(NSString *)_key inContext:(id)_ctx {
128 if ([_key isEqualToString:@"ControlPanel"])
131 if ([[self registeredRequestHandlerKeys] containsObject:_key])
134 if ([super hasName:_key inContext:_ctx])
137 root = [self rootObjectInContext:_ctx];
139 return [root hasName:_key inContext:_ctx];
144 - (id)controlPanel:(NSString *)_name inContext:(id)_ctx {
145 return [[[SoControlPanel alloc] init] autorelease];
148 - (BOOL)isApplicationNameLookup:(NSString *)_name inContext:(id)_ctx {
149 static NSString *WOApplicationSuffix = nil;
152 appName = [[(WOContext *)_ctx request] applicationName];
153 if ([_name isEqual:appName]) {
154 if (debugLookup) [self logWithFormat:@" matched appname: %@", appName];
158 if (WOApplicationSuffix == nil) {
159 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
160 WOApplicationSuffix = [[ud stringForKey:@"WOApplicationSuffix"] copy];
162 appName = [appName stringByAppendingString:WOApplicationSuffix];
163 if ([_name isEqual:appName]) {
164 if (debugLookup) [self logWithFormat:@" matched appname: %@", appName];
171 - (id)lookupName:(NSString *)_name inContext:(id)_ctx acquire:(BOOL)_flag {
174 if ([_name isEqualToString:@"ControlPanel"])
175 return [self controlPanel:_name inContext:_ctx];
177 if ([[self registeredRequestHandlerKeys] containsObject:_name]) {
179 need to check registeredRequestHandlerKeys because requestHandlerForKey:
180 returns the default handler if the key could not be found ...
182 if ((v = [super requestHandlerForKey:_name]))
186 if (debugLookup) [self logWithFormat:@"lookup name: %@", _name];
188 if ((v = [super lookupName:_name inContext:_ctx acquire:NO]) == nil) {
191 root = [self rootObjectInContext:_ctx];
192 if (debugLookup) [self logWithFormat:@" lookup in root object: %@", v];
195 v = [root lookupName:_name inContext:_ctx acquire:_flag];
196 else if (debugLookup)
197 [self logWithFormat:@" root is application object"];
200 if (debugLookup) [self logWithFormat:@" GOT: %@", v];
203 hack to allow "/myapp/folder/", it is a hack because it also allows
204 /myapp/myapp/myapp/.../folder/ ...
206 if (v == nil && [self isApplicationNameLookup:_name inContext:_ctx])
212 - (NSArray *)toOneRelationshipKeys {
216 ma = ((root = [super toOneRelationshipKeys]))
217 ? [[NSMutableSet alloc] initWithArray:root]
218 : [[NSMutableSet alloc] init];
220 [ma addObjectsFromArray:[self registeredRequestHandlerKeys]];
221 [ma addObject:@"ControlPanel"];
223 root = [self rootObjectInContext:[self context]];
224 if (root != nil && (root != self))
225 [ma addObjectsFromArray:[root toOneRelationshipKeys]];
227 root = [ma allObjects];
232 /* WebDAV support for root objects */
234 - (id)davCreateObject:(NSString *)_name
235 properties:(NSDictionary *)_props
240 if ((root = [self rootObjectInContext:_ctx]) == nil)
241 return [super davCreateObject:_name properties:_props inContext:_ctx];
243 return [root davCreateObject:_name properties:_props inContext:_ctx];
246 - (NSException *)davCreateCollection:(NSString *)_name inContext:(id)_ctx {
249 if ((root = [self rootObjectInContext:_ctx]) == nil)
250 return [super davCreateCollection:_name inContext:_ctx];
252 //[self debugWithFormat:@"let root '%@' create collection '%@'", root,_name];
253 return [root davCreateCollection:_name inContext:_ctx];
256 @end /* SoApplication */