/* Copyright (C) 2000-2004 SKYRIX Software AG This file is part of OpenGroupware.org. OGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. OGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include "WOxTemplateBuilder.h" #include #include "common.h" @implementation WOApplication(BuilderStack) - (void)scanForBuilderBundlesInDirectory:(NSString *)_path { NGBundleManager *bm; NSFileManager *fm; NSEnumerator *pathes; NSString *lPath; bm = [NGBundleManager defaultBundleManager]; fm = [NSFileManager defaultManager]; pathes = [[fm directoryContentsAtPath:_path] objectEnumerator]; while ((lPath = [pathes nextObject])) { NSBundle *bundle; BOOL isDir; lPath = [_path stringByAppendingPathComponent:lPath]; if (![fm fileExistsAtPath:lPath isDirectory:&isDir]) continue; if (!isDir) continue; if ((bundle = [bm bundleWithPath:lPath]) == nil) { [self logWithFormat:@"WARNING: could not get bundle for path: '%@'", lPath]; continue; } if (![bundle load]) { [self logWithFormat:@"WARNING: could not load bundle: '%@'", lPath]; continue; } [self debugWithFormat:@"loaded elem builder bundle: %@", [lPath lastPathComponent]]; } } - (void)loadBuilderBundles { NSFileManager *fm; NSProcessInfo *pi; NSArray *pathes; unsigned i; /* scan library pathes */ fm = [NSFileManager defaultManager]; pi = [NSProcessInfo processInfo]; #if COCOA_Foundation_LIBRARY /* TODO: (like COMPILE_FOR_GNUSTEP) This should actually check whether we are compiling in the GNUstep environment since this modifies the location of bundles. */ pathes = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES); #else pathes = [[pi environment] objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]; if (pathes == nil) pathes = [[pi environment] objectForKey:@"GNUSTEP_PATHLIST"]; pathes = [[pathes stringValue] componentsSeparatedByString:@":"]; #endif if ([pathes count] == 0) { [self debugWithFormat:@"found no builder bundle pathes."]; return; } [self debugWithFormat:@"scanning for builder bundles ..."]; for (i = 0; i < [pathes count]; i++) { NSString *lPath; BOOL isDir; lPath = [pathes objectAtIndex:i]; #if !COCOA_Foundation_LIBRARY lPath = [lPath stringByAppendingPathComponent:@"Library"]; #endif lPath = [lPath stringByAppendingPathComponent:@"WOxElemBuilders-4.3"]; if (![fm fileExistsAtPath:lPath isDirectory:&isDir]) continue; if (!isDir) continue; [self debugWithFormat:@" directory %@", lPath]; [self scanForBuilderBundlesInDirectory:lPath]; } [self debugWithFormat:@"finished scan for builders."]; } - (WOxElemBuilder *)builderForDocument:(id)_document { static WOxElemBuilder *builder = nil; static NSArray *defClasses = nil; NSUserDefaults *ud; NSArray *classes = nil; NSArray *infos; if (builder != nil) return builder; ud = [NSUserDefaults standardUserDefaults]; if (defClasses == nil) defClasses = [[ud arrayForKey:@"WOxBuilderClasses"] copy]; /* ensure that bundles are loaded */ [self loadBuilderBundles]; infos = [[NGBundleManager defaultBundleManager] providedResourcesOfType:@"WOxElemBuilder"]; if ([infos count] > 0) { classes = [NSMutableArray arrayWithCapacity:24]; [(id)classes addObjectsFromArray:[infos valueForKey:@"name"]]; [(id)classes addObjectsFromArray:defClasses]; } else classes = defClasses; if ([ud boolForKey:@"WOxLogBuilderQueue"]) { NSEnumerator *e; NSString *b; if ([classes count] > 0) { [self debugWithFormat:@"builder stack:"]; e = [classes objectEnumerator]; while ((b = [e nextObject])) [self logWithFormat:@" %@", b]; } else { [self debugWithFormat:@"empty wox-element builder stack !"]; } } builder = [[WOxElemBuilder createBuilderQueue:classes] retain]; return builder; } @end /* WOApplication(BuilderStack) */