From 5f7935b66ea90fd195be7dbc0906a7705c1b0b2b Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 11 Jul 2005 13:45:44 +0000 Subject: [PATCH] added a scanning function to the resource locator added folder-type autodiscovery to GCS git-svn-id: http://svn.opengroupware.org/SOPE/trunk@882 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-core/NGExtensions/ChangeLog | 6 ++ .../NGExtensions/NGResourceLocator.h | 3 + sope-core/NGExtensions/NGResourceLocator.m | 70 ++++++++++++++++++- sope-core/NGExtensions/Version | 2 +- sope-gdl1/GDLContentStore/ChangeLog | 5 ++ sope-gdl1/GDLContentStore/GCSFolderManager.m | 45 +++++++++--- sope-gdl1/GDLContentStore/GCSFolderType.h | 5 ++ sope-gdl1/GDLContentStore/Version | 3 +- 8 files changed, 125 insertions(+), 14 deletions(-) diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index 49fae5d7..9576a1e6 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,9 @@ +2005-07-11 Helge Hess + + * NGResourceLocator.m: added -description, added method + -lookupAllFilesWithExtension:doReturnFullPath: to discover all + available files in a search hierarchy (v4.5.161) + 2005-05-20 Helge Hess * moved NGStringScanEnumerator to Recycler (was not in makefile) diff --git a/sope-core/NGExtensions/NGExtensions/NGResourceLocator.h b/sope-core/NGExtensions/NGExtensions/NGResourceLocator.h index 0f78c87f..0a079872 100644 --- a/sope-core/NGExtensions/NGExtensions/NGResourceLocator.h +++ b/sope-core/NGExtensions/NGExtensions/NGResourceLocator.h @@ -67,6 +67,9 @@ - (NSString *)lookupFileWithName:(NSString *)_name; - (NSString *)lookupFileWithName:(NSString *)_name extension:(NSString *)_ext; +- (NSArray *)lookupAllFilesWithExtension:(NSString *)_ext + doReturnFullPath:(BOOL)_withPath; + @end #endif /* __NGExtensions_NGResourceLocator_H__ */ diff --git a/sope-core/NGExtensions/NGResourceLocator.m b/sope-core/NGExtensions/NGResourceLocator.m index c2e2818a..303136d2 100644 --- a/sope-core/NGExtensions/NGResourceLocator.m +++ b/sope-core/NGExtensions/NGResourceLocator.m @@ -155,7 +155,7 @@ return [p isNotNull] ? p : nil; e = [[self searchPathes] objectEnumerator]; - while ((p = [e nextObject])) { + while ((p = [e nextObject]) != nil) { p = [p stringByAppendingPathComponent:_name]; if (![self->fileManager fileExistsAtPath:p]) @@ -176,4 +176,72 @@ return [self lookupFileWithName:_name]; } +- (NSArray *)lookupAllFilesWithExtension:(NSString *)_ext + doReturnFullPath:(BOOL)_withPath +{ + /* only deliver each filename once */ + NSMutableArray *pathes; + NSMutableSet *uniquer; + NSArray *lSearchPathes; + unsigned i, count; + + _ext = [_ext length] > 0 ? [@"." stringByAppendingString:_ext] :nil; + uniquer = [NSMutableSet setWithCapacity:128]; + pathes = _withPath ? [NSMutableArray arrayWithCapacity:64] : nil; + lSearchPathes = [self searchPathes]; + + for (i = 0, count = [lSearchPathes count]; i < count; i++) { + NSArray *filenames; + unsigned j, jcount; + + filenames = [self->fileManager directoryContentsAtPath: + [lSearchPathes objectAtIndex:i]]; + + for (j = 0, jcount = [filenames count]; j < jcount; j++) { + NSString *fn, *pn; + + fn = [filenames objectAtIndex:j]; + if (_ext != nil) { + if (![fn hasSuffix:_ext]) + continue; + } + + if ([uniquer containsObject:fn]) + continue; + + [uniquer addObject:fn]; + + /* build and cache path */ + pn = [[lSearchPathes objectAtIndex:i] stringByAppendingPathComponent:fn]; + [self cachePath:pn forName:fn]; + if (_withPath) [pathes addObject:pn]; + } + } + + return _withPath ? pathes : [uniquer allObjects]; +} + +/* description */ + +- (NSString *)description { + NSMutableString *ms; + + ms = [NSMutableString stringWithCapacity:128]; + [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; + + [ms appendFormat:@" gs=%@ fhs=%@", self->gsSubPath, self->fhsSubPath]; + + [ms appendString:@" cache"]; + if (self->flags.cacheSearchPathes) + [ms appendString:@":pathes"]; + if (self->flags.cachePathHits) + [ms appendString:@":hits"]; + if (self->flags.cachePathMisses) + [ms appendString:@":misses"]; + [ms appendFormat:@":#%d", [self->nameToPathCache count]]; + + [ms appendString:@">"]; + return ms; +} + @end /* NGResourceLocator */ diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index 0e49e8b7..f29e845e 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=160 +SUBMINOR_VERSION:=161 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39 diff --git a/sope-gdl1/GDLContentStore/ChangeLog b/sope-gdl1/GDLContentStore/ChangeLog index de899321..a043ae60 100644 --- a/sope-gdl1/GDLContentStore/ChangeLog +++ b/sope-gdl1/GDLContentStore/ChangeLog @@ -1,3 +1,8 @@ +2005-07-11 Helge Hess + + * GCSFolderManager.m: added automatic discovery of folder types by + scanning for .ocs files (v4.5.29) + 2005-04-25 Helge Hess * fixed gcc 4.0 warnings (v4.5.28) diff --git a/sope-gdl1/GDLContentStore/GCSFolderManager.m b/sope-gdl1/GDLContentStore/GCSFolderManager.m index 29b8bbf8..630c05cd 100644 --- a/sope-gdl1/GDLContentStore/GCSFolderManager.m +++ b/sope-gdl1/GDLContentStore/GCSFolderManager.m @@ -27,6 +27,7 @@ #include "EOAdaptorChannel+GCS.h" #include "common.h" #include +#include /* Required database schema: @@ -91,6 +92,38 @@ static const char *GCSPathColumnPattern = "c_path%i"; return fm; } +- (NSDictionary *)loadDefaultFolderTypes { + NSMutableDictionary *typeMap; + NSArray *types; + unsigned i, count; + + + types = [[GCSFolderType resourceLocator] lookupAllFilesWithExtension:@"ocs" + doReturnFullPath:NO]; + if ((count = [types count]) == 0) { + [self logWithFormat:@"Note: no GCS folder types found."]; + return nil; + } + + typeMap = [NSMutableDictionary dictionaryWithCapacity:count]; + + [self logWithFormat:@"Note: loading %d GCS folder types:", count]; + for (i = 0, count = [types count]; i < count; i++) { + NSString *type; + GCSFolderType *typeObject; + + type = [[types objectAtIndex:i] stringByDeletingPathExtension]; + typeObject = [[GCSFolderType alloc] initWithFolderTypeName:type]; + + [self logWithFormat:@" %@: %s", + type, [typeObject isNotNull] ? "OK" : "FAIL"]; + [typeMap setObject:typeObject forKey:type]; + [typeObject release]; + } + + return typeMap; +} + - (id)initWithFolderInfoLocation:(NSURL *)_url { if (_url == nil) { [self logWithFormat:@"ERROR(%s): missing folder info url!", @@ -99,8 +132,6 @@ static const char *GCSPathColumnPattern = "c_path%i"; return nil; } if ((self = [super init])) { - GCSFolderType *cal, *contact; - self->channelManager = [[GCSChannelManager defaultChannelManager] retain]; self->folderInfoLocation = [_url retain]; @@ -112,15 +143,7 @@ static const char *GCSPathColumnPattern = "c_path%i"; } /* register default folder types */ - - cal = [[GCSFolderType alloc] initWithFolderTypeName:@"appointment"]; - contact = [[GCSFolderType alloc] initWithFolderTypeName:@"contact"]; - self->nameToType = [[NSDictionary alloc] initWithObjectsAndKeys: - cal, @"appointment", - contact, @"contact", - nil]; - [cal release]; cal = nil; - [contact release]; contact = nil; + self->nameToType = [[self loadDefaultFolderTypes] copy]; } return self; } diff --git a/sope-gdl1/GDLContentStore/GCSFolderType.h b/sope-gdl1/GDLContentStore/GCSFolderType.h index 0009ea22..8c62e052 100644 --- a/sope-gdl1/GDLContentStore/GCSFolderType.h +++ b/sope-gdl1/GDLContentStore/GCSFolderType.h @@ -40,6 +40,7 @@ @class NSString, NSArray, NSDictionary; @class EOQualifier; +@class NGResourceLocator; @class GCSFolder, GCSFieldExtractor; @interface GCSFolderType : NSObject @@ -72,6 +73,10 @@ - (GCSFieldExtractor *)quickExtractor; +/* locator used to find .ocs files */ + ++ (NGResourceLocator *)resourceLocator; + @end #endif /* __GDLContentStore_GCSFolderType_H__ */ diff --git a/sope-gdl1/GDLContentStore/Version b/sope-gdl1/GDLContentStore/Version index 9014956b..024088a4 100644 --- a/sope-gdl1/GDLContentStore/Version +++ b/sope-gdl1/GDLContentStore/Version @@ -2,8 +2,9 @@ MAJOR_VERSION:=4 MINOR_VERSION:=5 -SUBMINOR_VERSION:=28 +SUBMINOR_VERSION:=29 +# v4.5.29 requires libNGExtensions v4.5.161 # v4.5.26 does not require libNGiCal anymore # v0.9.19 requires libNGiCal v4.5.40 # v0.9.18 requires libNGiCal v4.5.38 -- 2.39.5