]> err.no Git - sope/commitdiff
added a scanning function to the resource locator
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 11 Jul 2005 13:45:44 +0000 (13:45 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 11 Jul 2005 13:45:44 +0000 (13:45 +0000)
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
sope-core/NGExtensions/NGExtensions/NGResourceLocator.h
sope-core/NGExtensions/NGResourceLocator.m
sope-core/NGExtensions/Version
sope-gdl1/GDLContentStore/ChangeLog
sope-gdl1/GDLContentStore/GCSFolderManager.m
sope-gdl1/GDLContentStore/GCSFolderType.h
sope-gdl1/GDLContentStore/Version

index 49fae5d71b45aee90521a6e8cd5161d4b884ff70..9576a1e6ebf42c045f97a5c10aa7976608a4cfaa 100644 (file)
@@ -1,3 +1,9 @@
+2005-07-11  Helge Hess  <helge.hess@opengroupware.org>
+
+       * 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  <helge.hess@skyrix.com>
 
        * moved NGStringScanEnumerator to Recycler (was not in makefile)
index 0f78c87f3370ef9c49d51161ef7be3304be357b8..0a0798729056217922e48ddc4afcdbffff6932df 100644 (file)
@@ -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__ */
index c2e2818a918cfd1e77dda240ba7b48ed2fc14c80..303136d2fb5de5f30adba1c502e893b2be40eb65 100644 (file)
     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])
   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 */
index 0e49e8b7af608ebd41a89b271c5e3c7fca7c6ac1..f29e845eadd0d0c312e5ff7e20e4a3e8b178bbb2 100644 (file)
@@ -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
index de89932190a27cd352939a552df7040fbd2eba57..a043ae60efd447006695c9f37e0ae7e514593183 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-11  Helge Hess  <helge.hess@opengroupware.org>
+
+       * GCSFolderManager.m: added automatic discovery of folder types by
+         scanning for .ocs files (v4.5.29)
+
 2005-04-25  Helge Hess  <helge.hess@opengroupware.org>
 
        * fixed gcc 4.0 warnings (v4.5.28)
index 29b8bbf8e20dcf20239c909efb165467bbc09373..630c05cd2be6181f184251102e2754ca9d8bf8a1 100644 (file)
@@ -27,6 +27,7 @@
 #include "EOAdaptorChannel+GCS.h"
 #include "common.h"
 #include <GDLAccess/EOAdaptorChannel.h>
+#include <NGExtensions/NGResourceLocator.h>
 
 /*
   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;
 }
index 0009ea2228c7cd275ec702e30774ad510f57a5b2..8c62e05214ef19eaed7074abde2b7bea0b49769a 100644 (file)
@@ -40,6 +40,7 @@
 
 @class NSString, NSArray, NSDictionary;
 @class EOQualifier;
+@class NGResourceLocator;
 @class GCSFolder, GCSFieldExtractor;
 
 @interface GCSFolderType : NSObject
 
 - (GCSFieldExtractor *)quickExtractor;
 
+/* locator used to find .ocs files */
+
++ (NGResourceLocator *)resourceLocator;
+
 @end
 
 #endif /* __GDLContentStore_GCSFolderType_H__ */
index 9014956b4543f3219890552955a414336b3f25c1..024088a4170de7390ebc4bdc63401feaff743ebf 100644 (file)
@@ -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