2 Copyright (C) 2000-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
22 #include <NGObjWeb/WOApplication.h>
23 #include "WOxTemplateBuilder.h"
24 #include <NGObjWeb/WOxElemBuilder.h>
27 @implementation WOApplication(BuilderStack)
29 - (void)scanForBuilderBundlesInDirectory:(NSString *)_path {
35 bm = [NGBundleManager defaultBundleManager];
37 fm = [NSFileManager defaultManager];
38 pathes = [[fm directoryContentsAtPath:_path] objectEnumerator];
39 while ((lPath = [pathes nextObject])) {
43 lPath = [_path stringByAppendingPathComponent:lPath];
45 if (![fm fileExistsAtPath:lPath isDirectory:&isDir])
50 if ((bundle = [bm bundleWithPath:lPath]) == nil) {
51 [self logWithFormat:@"WARNING: could not get bundle for path: '%@'",
57 [self logWithFormat:@"WARNING: could not load bundle: '%@'", lPath];
61 [self debugWithFormat:@"loaded elem builder bundle: %@",
62 [lPath lastPathComponent]];
66 - (void)loadBuilderBundles {
67 // TODO: DUP to SoProductRegistry.m
74 /* scan library pathes */
76 fm = [NSFileManager defaultManager];
77 pi = [NSProcessInfo processInfo];
79 #if COCOA_Foundation_LIBRARY
81 TODO: (like COMPILE_FOR_GNUSTEP)
82 This should actually check whether we are compiling in the
83 GNUstep environment since this modifies the location of bundles.
85 pathes = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
89 pathes = [[pi environment] objectForKey:@"GNUSTEP_PATHPREFIX_LIST"];
91 pathes = [[pi environment] objectForKey:@"GNUSTEP_PATHLIST"];
93 pathes = [[pathes stringValue] componentsSeparatedByString:@":"];
96 if ([pathes count] == 0) {
97 [self debugWithFormat:@"found no builder bundle pathes."];
101 [self debugWithFormat:@"scanning for builder bundles ..."];
103 #if !COCOA_Foundation_LIBRARY
104 relPath = @"Library/";
106 relPath = [NSString stringWithFormat:@"%@WOxElemBuilders-%i.%i/", relPath,
107 SOPE_MAJOR_VERSION, SOPE_MINOR_VERSION];
108 for (i = 0; i < [pathes count]; i++) {
112 lPath = [[pathes objectAtIndex:i] stringByAppendingPathComponent:relPath];
113 if (![fm fileExistsAtPath:lPath isDirectory:&isDir])
118 [self debugWithFormat:@" directory %@", lPath];
119 [self scanForBuilderBundlesInDirectory:lPath];
122 /* look into FHS pathes */
124 relPath = [NSString stringWithFormat:@"lib/sope-%i.%i/wox-builders/",
125 SOPE_MAJOR_VERSION, SOPE_MINOR_VERSION];
126 pathes = [NSArray arrayWithObjects:
127 [@"/usr/local/" stringByAppendingString:relPath],
128 [@"/usr/" stringByAppendingString:relPath],
130 for (i = 0; i < [pathes count]; i++) {
134 lPath = [pathes objectAtIndex:i];
135 if (![fm fileExistsAtPath:lPath isDirectory:&isDir])
140 [self debugWithFormat:@" directory %@", lPath];
141 [self scanForBuilderBundlesInDirectory:lPath];
146 [self debugWithFormat:@"finished scan for builders."];
149 - (WOxElemBuilder *)builderForDocument:(id<DOMDocument>)_document {
150 static WOxElemBuilder *builder = nil;
151 static NSArray *defClasses = nil;
153 NSArray *classes = nil;
159 ud = [NSUserDefaults standardUserDefaults];
160 if (defClasses == nil)
161 defClasses = [[ud arrayForKey:@"WOxBuilderClasses"] copy];
163 /* ensure that bundles are loaded */
164 [self loadBuilderBundles];
166 infos = [[NGBundleManager defaultBundleManager]
167 providedResourcesOfType:@"WOxElemBuilder"];
168 if ([infos count] > 0) {
169 classes = [NSMutableArray arrayWithCapacity:24];
170 [(id)classes addObjectsFromArray:[infos valueForKey:@"name"]];
171 [(id)classes addObjectsFromArray:defClasses];
174 classes = defClasses;
176 if ([ud boolForKey:@"WOxLogBuilderQueue"]) {
180 if ([classes count] > 0) {
181 [self debugWithFormat:@"builder stack:"];
182 e = [classes objectEnumerator];
183 while ((b = [e nextObject]))
184 [self logWithFormat:@" %@", b];
187 [self debugWithFormat:@"empty wox-element builder stack !"];
191 builder = [[WOxElemBuilder createBuilderQueue:classes] retain];
195 @end /* WOApplication(BuilderStack) */