]> err.no Git - scalable-opengroupware.org/commitdiff
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@72 d1b88da0-ebda-0310-925b-ed51d8...
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 29 Jun 2004 09:10:44 +0000 (09:10 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 29 Jun 2004 09:10:44 +0000 (09:10 +0000)
OGoContentStore/OCSFolder.h
OGoContentStore/OCSFolder.m
OGoContentStore/OCSFolderManager.m

index ee2a27f07ed161e32dd5de79fda94ef110b2a759..18b0219f294b709f0a12faea3a1d04c861d89e9f 100644 (file)
   
   NSNumber *folderId;
   NSString *folderName;
-  NSString *rootName;
   NSString *path;
   NSURL    *location;
   NSString *folderType;
 }
 
+- (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId
+  folderTypeName:(NSString *)_ftname folderType:(OCSFolderType *)_ftype
+  location:(NSURL *)_loc
+  folderManager:(OCSFolderManager *)_fm;
+
 /* accessors */
 
 - (NSNumber *)folderId;
 - (NSString *)folderName;
-- (NSString *)rootName;
 - (NSString *)path;
 - (NSURL    *)location;
 - (NSString *)folderTypeName;
index 09e1a109b4641f9692452f559f53e6f87dc2d57e..511993710e994ba64c910148d3e78b7afdc5ee5e 100644 (file)
 
 @implementation OCSFolder
 
+- (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId
+  folderTypeName:(NSString *)_ftname folderType:(OCSFolderType *)_ftype
+  location:(NSURL *)_loc
+  folderManager:(OCSFolderManager *)_fm
+{
+  if ((self = [super init])) {
+    self->folderManager = [_fm    retain];
+    self->folderInfo    = [_ftype retain];
+    
+    self->folderId      = [_folderId copy];
+    self->folderName    = [[_path lastPathComponent] copy];
+    self->path          = [_path   copy];
+    self->location      = [_loc    retain];
+    self->folderType    = [_ftname copy];
+  }
+  return self;
+}
+- (id)init {
+  return [self initWithPath:nil primaryKey:nil
+              folderTypeName:nil folderType:nil 
+              location:nil folderManager:nil];
+}
+
 - (void)dealloc {
   [self->folderManager release];
   [self->folderInfo    release];
   [self->folderId      release];
   [self->folderName    release];
-  [self->rootName      release];
   [self->path          release];
   [self->location      release];
   [self->folderType    release];
@@ -48,9 +70,6 @@
 - (NSString *)folderName {
   return self->folderName;
 }
-- (NSString *)rootName {
-  return self->rootName;
-}
 - (NSString *)path {
   return self->path;
 }
@@ -67,7 +86,8 @@
 
 - (NSString *)description {
   NSMutableString *ms;
-
+  id tmp;
+  
   ms = [NSMutableString stringWithCapacity:256];
   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
 
   else
     [ms appendString:@" no-id"];
 
-  if (self->path)       [ms appendFormat:@" path=%@",     self->path];
-  if (self->folderType) [ms appendFormat:@" type=%@",     self->folderType];
-  if (self->location)   [ms appendFormat:@" location=%@", self->location];
+  if ((tmp = [self path]))           [ms appendFormat:@" path=%@", tmp];
+  if ((tmp = [self folderTypeName])) [ms appendFormat:@" type=%@", tmp];
+  if ((tmp = [self location]))
+    [ms appendFormat:@" db=%@",   [tmp absoluteString]];
   
   [ms appendString:@">"];
   return ms;
index f84bc2dd36ea1246640ddfd34542d98c6970b0a0..0e2c6838e49bfaa8c744ad3f72f4b6c782a27db6 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "OCSFolderManager.h"
 #include "OCSChannelManager.h"
+#include "OCSFolderType.h"
+#include "OCSFolder.h"
 #include "NSURL+OCS.h"
 #include "common.h"
 #include <GDLAccess/EOAdaptorChannel.h>
@@ -125,15 +127,19 @@ static const char *OCSPathColumnPattern     = "c_path%i";
 
 /* checking connection */
 
+- (OCSChannelManager *)channelManager {
+  return self->channelManager;
+}
+
 - (EOAdaptorChannel *)acquireOpenChannel {
   EOAdaptorChannel *ch;
   
-  ch = [self->channelManager acquireOpenChannelForURL:
+  ch = [[self channelManager] acquireOpenChannelForURL:
              [self folderInfoLocation]];
   return ch;
 }
 - (void)releaseChannel:(EOAdaptorChannel *)_channel {
-  [self->channelManager releaseChannel:_channel];
+  [[self channelManager] releaseChannel:_channel];
   if (debugOn) [self debugWithFormat:@"released channel: %@", _channel];
 }
 
@@ -198,6 +204,45 @@ static const char *OCSPathColumnPattern     = "c_path%i";
   return rows;
 }
 
+/* row factory */
+
+- (OCSFolder *)folderForRecord:(NSDictionary *)_record {
+  OCSFolder     *folder;
+  OCSFolderType *folderType;
+  NSString      *folderTypeName, *locationString, *folderName, *path;
+  NSNumber      *folderId;
+  NSURL         *location;
+  
+  if (_record == nil) return nil;
+  
+  folderTypeName = [_record objectForKey:@"cFolderType"];
+  if ((folderType = [self folderTypeWithName:folderTypeName]) == nil) {
+    [self logWithFormat:@"ERROR(%s): got no type from folder record: %@",
+           __PRETTY_FUNCTION__, _record];
+    return nil;
+  }
+  
+  folderId   = [_record objectForKey:@"cFolderId"];
+  folderName = [_record objectForKey:@"cPath"];
+  path       = [self pathFromInternalName:folderName];
+  
+  locationString = [_record objectForKey:@"cLocation"];
+  location = [locationString isNotNull] 
+    ? [NSURL URLWithString:locationString]
+    : nil;
+  if (location == nil) {
+    [self logWithFormat:@"ERROR(%s): missing folder location in record: %@", 
+           __PRETTY_FUNCTION__, _record];
+    return nil;
+  }
+  
+  folder = [[OCSFolder alloc] initWithPath:path primaryKey:folderId
+                             folderTypeName:folderTypeName 
+                             folderType:folderType
+                             location:location folderManager:self];
+  return [folder autorelease];
+}
+
 /* path SQL */
 
 - (NSString *)generateSQLWhereForInternalNames:(NSArray *)_names
@@ -505,8 +550,7 @@ static const char *OCSPathColumnPattern     = "c_path%i";
     return nil;
   }
   
-  [self logWithFormat:@"record: %@", record];
-  return nil;
+  return [self folderForRecord:record];
 }
 
 /* folder types */
@@ -515,7 +559,7 @@ static const char *OCSPathColumnPattern     = "c_path%i";
   if ([_name length] == 0)
     _name = OCSGenericFolderTypeName;
   
-  return [self->nameToType objectForKey:_name];
+  return [self->nameToType objectForKey:[_name lowercaseString]];
 }
 
 /* cache management */
@@ -539,7 +583,7 @@ static const char *OCSPathColumnPattern     = "c_path%i";
   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
   
   [ms appendFormat:@" url=%@", [self->folderInfoLocation absoluteString]];
-  [ms appendFormat:@" channel-manager=0x%08X", self->channelManager];
+  [ms appendFormat:@" channel-manager=0x%08X", [self channelManager]];
   
   [ms appendString:@">"];
   return ms;