2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
21 // $Id: sope.m 4 2004-08-20 17:04:31Z helge $
23 #include "SoObjects/SoApplication.h"
26 An executable which can run a SoOFS based SOPE application. When started,
27 it takes the current-directory path for constructing the SoOFS root folder
28 of the SOPE application.
29 It also reads a file ".sope.plist" in the root-path to load site-local
30 configuration settings.
33 - load defaults from root-folder
34 DONE [".sope.plist" is loaded and registered]
35 - load products from root-folder
36 - load authenticator from root-folder
39 @class NSString, NSFileManager;
41 @interface SOPE : SoApplication
49 #include "SoObjects/SoClassSecurityInfo.h"
50 #include "SoOFS/OFSFolder.h"
51 #include "SoOFS/OFSFactoryContext.h"
54 NSString *SoRootFolder = @"SoRootFolder";
60 Since we are a tool, we have no bundle and need to declare security info
63 SoClassSecurityInfo *si = [self soClassSecurityInfo];
64 [si declareObjectPublic];
65 [si setDefaultAccess:@"allow"];
68 - (void)loadLocalDefaults:(NSString *)_path {
71 if ((plist = [[NSDictionary alloc] initWithContentsOfFile:_path]) == nil) {
72 [self logWithFormat:@"could not read SOPE config: %@", _path];
76 TODO: we need a separate domain for this, this stuff doesn't make sense
79 [[NSUserDefaults standardUserDefaults] registerDefaults:plist];
80 [self logWithFormat:@"registered site defaults: %@", _path];
85 // TODO: create some bootstrap code to create initial user database,
86 // defaults, control-panel, etc
96 if (self->fm == nil) {
97 [self logWithFormat:@"missing SOPE storage filemanager."];
100 if ([self->rootPath length] == 0) {
101 [self logWithFormat:@"missing SOPE storage root-path."];
105 if (![self->fm fileExistsAtPath:self->rootPath isDirectory:&isDir]) {
106 [self logWithFormat:@"SOPE storage root-path does not exist: %@",
111 [self logWithFormat:@"SOPE storage root-path is not a directory: %@",
116 /* bootstrap root if necessary */
118 if (![self _bootstrap])
123 [self logWithFormat:@"starting SOPE on OFS root: %@", self->rootPath];
125 p = [self->rootPath stringByAppendingPathComponent:@".sope.plist"];
126 if ([self->fm isReadableFileAtPath:p])
127 [self loadLocalDefaults:p];
133 if ((self = [super init])) {
134 // TODO: make root-path/fm configurable ?
135 self->fm = [[NSFileManager defaultManager] retain];
136 self->rootPath = [[self->fm currentDirectoryPath] copy];
138 if (![self _setupRoot]) {
147 [self->rootPath release];
156 - (NSString *)rootPath {
157 return self->rootPath;
160 /* define the root SoObject */
162 - (OFSFolder *)rootObjectInContext:(id)_ctx {
163 OFSFactoryContext *ctx;
166 if ((root = [_ctx valueForKey:SoRootFolder]))
169 ctx = [OFSFactoryContext contextWithFileManager:[self fileManager]
170 storagePath:[self rootPath]];
172 root = [[OFSFolder alloc] init];
173 [root takeStorageInfoFromContext:ctx];
174 [root awakeFromFetchInContext:ctx];
175 [_ctx takeValue:root forKey:SoRootFolder];
176 return [root autorelease];
181 - (id)authenticatorInContext:(id)_ctx {
185 root = [self rootObjectInContext:_ctx];
186 if ((auth = [root authenticatorInContext:_ctx]))
189 return [super authenticatorInContext:_ctx];
194 - (NSArray *)manageMenuChildNames {
198 ma = [NSMutableArray arrayWithCapacity:16];
199 [ma addObject:@"ControlPanel"];
201 root = [self rootObjectInContext:[self context]];
202 if (root != nil && (root != self))
203 [ma addObjectsFromArray:[root toOneRelationshipKeys]];
210 - (id)handleQueryWithUnboundKey:(NSString *)key {
211 /* KVC on MacOSX throws an exception when an unbound key is queried ... */
217 int main(int argc, char **argv, char **env) {
218 NSAutoreleasePool *pool;
220 pool = [[NSAutoreleasePool alloc] init];
221 #if LIB_FOUNDATION_LIBRARY
222 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
225 WOWatchDogApplicationMain(@"SOPE", argc, (void*)argv);