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 <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 warnWithFormat:@"could not get bundle for path: '%@'",
57 [self warnWithFormat:@"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 || NeXT_Foundation_LIBRARY
106 relPath = @"Library/";
108 relPath = [NSString stringWithFormat:@"%@WOxElemBuilders-%i.%i/", relPath,
109 SOPE_MAJOR_VERSION, SOPE_MINOR_VERSION];
110 for (i = 0; i < [pathes count]; i++) {
114 lPath = [[pathes objectAtIndex:i] stringByAppendingPathComponent:relPath];
115 if (![fm fileExistsAtPath:lPath isDirectory:&isDir])
120 [self debugWithFormat:@" directory %@", lPath];
121 [self scanForBuilderBundlesInDirectory:lPath];
124 /* look into FHS pathes */
126 relPath = [NSString stringWithFormat:@"lib/sope-%i.%i/wox-builders/",
127 SOPE_MAJOR_VERSION, SOPE_MINOR_VERSION];
128 pathes = [NSArray arrayWithObjects:
129 [@"/usr/local/" stringByAppendingString:relPath],
130 [@"/usr/" stringByAppendingString:relPath],
132 for (i = 0; i < [pathes count]; i++) {
136 lPath = [pathes objectAtIndex:i];
137 if (![fm fileExistsAtPath:lPath isDirectory:&isDir])
142 [self debugWithFormat:@" directory %@", lPath];
143 [self scanForBuilderBundlesInDirectory:lPath];
148 [self debugWithFormat:@"finished scan for builders."];
151 - (WOxElemBuilder *)builderForDocument:(id<DOMDocument>)_document {
152 static WOxElemBuilder *builder = nil;
153 static NSArray *defClasses = nil;
155 NSArray *classes = nil;
161 ud = [NSUserDefaults standardUserDefaults];
162 if (defClasses == nil)
163 defClasses = [[ud arrayForKey:@"WOxBuilderClasses"] copy];
165 /* ensure that bundles are loaded */
166 [self loadBuilderBundles];
168 infos = [[NGBundleManager defaultBundleManager]
169 providedResourcesOfType:@"WOxElemBuilder"];
170 if ([infos count] > 0) {
171 classes = [NSMutableArray arrayWithCapacity:24];
172 [(id)classes addObjectsFromArray:[infos valueForKey:@"name"]];
173 [(id)classes addObjectsFromArray:defClasses];
176 classes = defClasses;
178 if ([ud boolForKey:@"WOxLogBuilderQueue"]) {
182 if ([classes count] > 0) {
183 [self debugWithFormat:@"builder stack:"];
184 e = [classes objectEnumerator];
185 while ((b = [e nextObject]))
186 [self logWithFormat:@" %@", b];
189 [self debugWithFormat:@"empty wox-element builder stack !"];
193 builder = [[WOxElemBuilder createBuilderQueue:classes] retain];
197 @end /* WOApplication(BuilderStack) */