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 <SoObjects/SoApplication.h>
25 An executable which can run a SoOFS based SOPE application. When started,
26 it takes the current-directory path for constructing the SoOFS root folder
27 of the SOPE application.
28 It also reads a file ".sope.plist" in the root-path to load site-local
29 configuration settings.
32 - load defaults from root-folder
33 DONE [".sope.plist" is loaded and registered]
34 - load products from root-folder
35 - load authenticator from root-folder
38 @class NSString, NSFileManager;
40 @interface SOPE : SoApplication
48 #include <SoObjects/SoClassSecurityInfo.h>
49 #include "OFSFolder.h"
50 #include "OFSFactoryContext.h"
53 NSString *SoRootFolder = @"SoRootFolder";
57 static BOOL debugRootObject = NO;
61 Since we are a tool, we have no bundle and need to declare security info
64 SoClassSecurityInfo *si = [self soClassSecurityInfo];
65 [si declareObjectPublic];
66 [si setDefaultAccess:@"allow"];
69 - (void)loadLocalDefaults:(NSString *)_path {
72 if ((plist = [[NSDictionary alloc] initWithContentsOfFile:_path]) == nil) {
73 [self logWithFormat:@"could not read SOPE config: %@", _path];
77 TODO: we need a separate domain for this, this stuff doesn't make sense
80 [[NSUserDefaults standardUserDefaults] registerDefaults:plist];
81 [self logWithFormat:@"registered site defaults: %@", _path];
86 // TODO: create some bootstrap code to create initial user database,
87 // defaults, control-panel, etc
97 if (self->fm == nil) {
98 [self logWithFormat:@"missing SOPE storage filemanager."];
101 if ([self->rootPath length] == 0) {
102 [self logWithFormat:@"missing SOPE storage root-path."];
106 if (![self->fm fileExistsAtPath:self->rootPath isDirectory:&isDir]) {
107 [self logWithFormat:@"SOPE storage root-path does not exist: %@",
112 [self logWithFormat:@"SOPE storage root-path is not a directory: %@",
117 /* bootstrap root if necessary */
119 if (![self _bootstrap])
124 [self logWithFormat:@"starting SOPE on OFS root: %@", self->rootPath];
126 p = [self->rootPath stringByAppendingPathComponent:@".sope.plist"];
127 if ([self->fm isReadableFileAtPath:p])
128 [self loadLocalDefaults:p];
134 if ((self = [super init])) {
135 // TODO: make root-path/fm configurable ?
136 self->fm = [[NSFileManager defaultManager] retain];
137 self->rootPath = [[self->fm currentDirectoryPath] copy];
139 if (![self _setupRoot]) {
148 [self->rootPath release];
157 - (NSString *)rootPath {
158 return self->rootPath;
161 /* define the root SoObject */
163 - (OFSFolder *)rootObjectInContext:(id)_ctx {
164 OFSFactoryContext *ctx;
167 if (debugRootObject) [self logWithFormat:@"queried root object ..."];
169 if ((root = [_ctx valueForKey:SoRootFolder]) != nil) {
171 [self logWithFormat:@" using cached root object: %@", root];
175 ctx = [OFSFactoryContext contextWithFileManager:[self fileManager]
176 storagePath:[self rootPath]];
178 root = [[[OFSFolder alloc] init] autorelease];
179 [root takeStorageInfoFromContext:ctx];
180 [root awakeFromFetchInContext:ctx];
181 [_ctx takeValue:root forKey:SoRootFolder];
183 [self logWithFormat:@" created new root object: %@", root];
189 - (id)authenticatorInContext:(id)_ctx {
193 root = [self rootObjectInContext:_ctx];
194 if ((auth = [root authenticatorInContext:_ctx]))
197 return [super authenticatorInContext:_ctx];
202 - (NSArray *)manageMenuChildNames {
206 ma = [NSMutableArray arrayWithCapacity:16];
207 [ma addObject:@"ControlPanel"];
209 root = [self rootObjectInContext:[self context]];
210 if (root != nil && (root != self))
211 [ma addObjectsFromArray:[root toOneRelationshipKeys]];
218 - (id)handleQueryWithUnboundKey:(NSString *)key {
219 /* KVC on MacOSX throws an exception when an unbound key is queried ... */
225 int main(int argc, char **argv, char **env) {
226 NSAutoreleasePool *pool;
228 pool = [[NSAutoreleasePool alloc] init];
229 #if LIB_FOUNDATION_LIBRARY
230 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
233 WOWatchDogApplicationMain(@"SOPE", argc, (void*)argv);