From ea6bcc5dca1e502d06bc2b8c2f90c7059cfcd9d9 Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 29 Jun 2004 09:10:44 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@72 d1b88da0-ebda-0310-925b-ed51d893ca5b --- OGoContentStore/OCSFolder.h | 7 ++-- OGoContentStore/OCSFolder.m | 37 +++++++++++++++----- OGoContentStore/OCSFolderManager.m | 56 ++++++++++++++++++++++++++---- 3 files changed, 84 insertions(+), 16 deletions(-) diff --git a/OGoContentStore/OCSFolder.h b/OGoContentStore/OCSFolder.h index ee2a27f0..18b0219f 100644 --- a/OGoContentStore/OCSFolder.h +++ b/OGoContentStore/OCSFolder.h @@ -35,17 +35,20 @@ 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; diff --git a/OGoContentStore/OCSFolder.m b/OGoContentStore/OCSFolder.m index 09e1a109..51199371 100644 --- a/OGoContentStore/OCSFolder.m +++ b/OGoContentStore/OCSFolder.m @@ -27,12 +27,34 @@ @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])]; @@ -76,9 +96,10 @@ 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; diff --git a/OGoContentStore/OCSFolderManager.m b/OGoContentStore/OCSFolderManager.m index f84bc2dd..0e2c6838 100644 --- a/OGoContentStore/OCSFolderManager.m +++ b/OGoContentStore/OCSFolderManager.m @@ -22,6 +22,8 @@ #include "OCSFolderManager.h" #include "OCSChannelManager.h" +#include "OCSFolderType.h" +#include "OCSFolder.h" #include "NSURL+OCS.h" #include "common.h" #include @@ -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; -- 2.39.5