]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WOCoreApplication+Bundle.m
added support for complex davResourceTypes
[sope] / sope-appserver / NGObjWeb / WOCoreApplication+Bundle.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include <NGObjWeb/WOCoreApplication.h>
23 #include "common.h"
24
25 @implementation WOCoreApplication(Bundle)
26
27 + (BOOL)didLoadDaemonBundle:(NSBundle *)_bundle {
28   return YES;
29 }
30
31 + (int)loadApplicationBundle:(NSString *)_bundleName
32   domainPath:(NSString *)_domain
33 {
34   // TODO: is this actually used somewhere?
35   NSFileManager  *fm;
36   NSString       *bp;
37   NSBundle       *bundle;
38   NSMutableArray *chkPathes;
39   NSEnumerator   *e;
40
41   fm = [NSFileManager defaultManager];
42   
43   if ([[_bundleName pathExtension] length] == 0)
44     _bundleName = [_bundleName stringByAppendingPathExtension:@"sxa"];
45   
46   chkPathes = [NSMutableArray arrayWithCapacity:16];
47   
48   if ([_bundleName isAbsolutePath]) {
49     [chkPathes addObject:_bundleName];
50   }
51   else {
52     NSDictionary *env;
53     NSEnumerator *e;
54     id tmp;
55     
56     env = [[NSProcessInfo processInfo] environment];
57     
58     [chkPathes addObject:@"."];
59 #if COCOA_FRAMEWORK
60     bp = [env objectForKey:@"HOME"];
61     bp = [bp stringByAppendingPathComponent:@"Library"];
62     bp = [bp stringByAppendingPathComponent:_domain];
63     [chkPathes addObject:bp];
64     bp = @"/Library";
65     bp = [bp stringByAppendingPathComponent:_domain];
66     [chkPathes addObject:bp];
67     bp = @"/System/Library";
68     bp = [bp stringByAppendingPathComponent:_domain];
69     [chkPathes addObject:bp];
70 #else
71     if ((tmp = [env objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]) == nil)
72       tmp = [env objectForKey:@"GNUSTEP_PATHLIST"];
73     tmp = [tmp componentsSeparatedByString:@":"];
74     e = [tmp objectEnumerator];
75     while ((tmp = [e nextObject])) {
76       bp = [tmp stringByAppendingPathComponent:@"Library"];
77       bp = [bp stringByAppendingPathComponent:_domain];
78       if ([chkPathes containsObject:bp]) continue;
79       
80       [chkPathes addObject:bp];
81     }
82 #endif
83   }
84   
85   e = [chkPathes objectEnumerator];
86   while ((bp = [e nextObject])) {
87     BOOL isDir;
88     
89     bp = [bp stringByAppendingPathComponent:_bundleName];
90     if (![fm fileExistsAtPath:bp isDirectory:&isDir]) continue;
91     if (!isDir) continue;
92     break; /* found */
93   }
94   
95   if ([bp length] == 0) {
96     NSLog(@"%s: did not find the bundle '%@' in search list %@",
97           __PRETTY_FUNCTION__, _bundleName, chkPathes);
98     return 1;
99   }
100   
101   if ((bundle = [NGBundle bundleWithPath:bp]) == nil) {
102     NSLog(@"%s: did not find %@ at %@ ...", __PRETTY_FUNCTION__, 
103           _bundleName, bp);
104     //return 1;
105   }
106   
107   if (![bundle load]) {
108     NSLog(@"%s: could not load %@ %@ (path=%@)...", __PRETTY_FUNCTION__, 
109           _bundleName, bundle, bp);
110     //return 2;
111   }
112
113   if (![self didLoadDaemonBundle:bundle]) {
114     //return 3;
115   }
116   
117   NSLog(@"hosting bundle: %@", [bundle bundleName]);
118   
119   return 0;
120 }
121
122 + (int)runApplicationBundle:(NSString *)_bundleName
123   domainPath:(NSString *)_p
124   arguments:(void *)_argv count:(int)_argc
125 {
126   NSAutoreleasePool *pool = nil;
127   int               rc;
128   NSString          *appClassName, *bundleName;
129   
130   pool = [[NSAutoreleasePool alloc] init];
131   
132 #if LIB_FOUNDATION_LIBRARY
133   {
134     extern char **environ;
135     [NSProcessInfo initializeWithArguments:_argv
136                    count:_argc
137                    environment:environ];
138   }
139 #endif
140   
141   if ((rc = [self loadApplicationBundle:_bundleName
142                   domainPath:_p]) != 0)
143     exit(rc);
144   
145   bundleName = [_bundleName lastPathComponent];
146   bundleName = [bundleName stringByDeletingPathExtension];
147   
148   appClassName = [bundleName stringByAppendingString:@"Application"];
149   
150   rc = WOWatchDogApplicationMain(appClassName, _argc, _argv);
151   
152   RELEASE(pool); pool = nil;
153
154   return rc;
155 }
156
157 + (int)runApplicationBundle:(NSString *)_bundleName
158   arguments:(void *)_args count:(int)_argc
159 {
160   return [self runApplicationBundle:_bundleName
161                domainPath:@"SxApps"
162                arguments:_args count:_argc];
163 }
164
165 @end /* WOApplication */