From: helge Date: Wed, 30 Jun 2004 00:10:07 +0000 (+0000) Subject: git-svn-id: http://svn.opengroupware.org/SOGo/trunk@88 d1b88da0-ebda-0310-925b-ed51d8... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8eba1b6f1303379bbc25c98c0961e2627329b2b4;p=scalable-opengroupware.org git-svn-id: http://svn.opengroupware.org/SOGo/trunk@88 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/OGoContentStore/OCSFieldExtractor.h b/OGoContentStore/OCSFieldExtractor.h index b32a9d31..128d67ad 100644 --- a/OGoContentStore/OCSFieldExtractor.h +++ b/OGoContentStore/OCSFieldExtractor.h @@ -25,10 +25,14 @@ #import +@class NSString, NSMutableDictionary; + @interface OCSFieldExtractor : NSObject { } +- (NSMutableDictionary *)extractQuickFieldsFromContent:(NSString *)_content; + @end #endif /* __OGoContentStore_OCSFieldExtractor_H__ */ diff --git a/OGoContentStore/OCSFieldExtractor.m b/OGoContentStore/OCSFieldExtractor.m index 1b8ed2dd..a18d4990 100644 --- a/OGoContentStore/OCSFieldExtractor.m +++ b/OGoContentStore/OCSFieldExtractor.m @@ -29,4 +29,8 @@ [super dealloc]; } +- (NSMutableDictionary *)extractQuickFieldsFromContent:(NSString *)_content { + return nil; +} + @end /* OCSFieldExtractor */ diff --git a/OGoContentStore/OCSFolder.h b/OGoContentStore/OCSFolder.h index abf36143..f47000dc 100644 --- a/OGoContentStore/OCSFolder.h +++ b/OGoContentStore/OCSFolder.h @@ -25,7 +25,7 @@ #import -@class NSString, NSURL, NSNumber, NSArray; +@class NSString, NSURL, NSNumber, NSArray, NSException; @class EOAdaptorChannel; @class OCSFolderManager, OCSFolderType, OCSChannelManager; @@ -77,6 +77,7 @@ - (NSArray *)allSubFolderNames; - (NSString *)fetchContentWithName:(NSString *)_name; +- (NSException *)writeContent:(NSString *)_content toName:(NSString *)_name; @end diff --git a/OGoContentStore/OCSFolder.m b/OGoContentStore/OCSFolder.m index 18795282..cdf7e505 100644 --- a/OGoContentStore/OCSFolder.m +++ b/OGoContentStore/OCSFolder.m @@ -24,6 +24,7 @@ #include "OCSFolderManager.h" #include "OCSFolderType.h" #include "OCSChannelManager.h" +#include "OCSFieldExtractor.h" #include "NSURL+OCS.h" #include "EOAdaptorChannel+OCS.h" #include "common.h" @@ -191,6 +192,38 @@ static BOOL debugOn = YES; return result; } +- (NSException *)writeContent:(NSString *)_content toName:(NSString *)_name { + EOAdaptorChannel *storeChannel, *quickChannel; + NSMutableDictionary *quickRow; + OCSFieldExtractor *extractor; + + /* extract info */ + + extractor = [self->folderInfo quickExtractor]; + quickRow = [extractor extractQuickFieldsFromContent:_content]; + + /* open channels */ + + if ((storeChannel = [self acquireStoreChannel]) == nil) { + [self logWithFormat:@"ERROR(%s): could not open storage channel!"]; + return nil; + } + if ((quickChannel = [self acquireQuickChannel]) == nil) { + [self logWithFormat:@"ERROR(%s): could not open quick channel!"]; + [self releaseChannel:storeChannel]; + return nil; + } + + // TODO + + [self releaseChannel:storeChannel]; + [self releaseChannel:quickChannel]; + + return [NSException exceptionWithName:@"NotYetImplemented" + reason:@"no time, no money, ..." + userInfo:nil]; +} + /* description */ - (NSString *)description { diff --git a/OGoContentStore/OCSFolderType.h b/OGoContentStore/OCSFolderType.h index 57eb7dc9..c4583f45 100644 --- a/OGoContentStore/OCSFolderType.h +++ b/OGoContentStore/OCSFolderType.h @@ -41,7 +41,7 @@ @class NSString, NSArray, NSDictionary; @class EOQualifier; -@class OCSFolder; +@class OCSFolder, OCSFieldExtractor; @interface OCSFolderType : NSObject { @@ -65,6 +65,10 @@ - (NSString *)sqlQuickCreateWithTableName:(NSString *)_tabName; +/* quick support */ + +- (OCSFieldExtractor *)quickExtractor; + @end #endif /* __OGoContentStore_OCSFolderType_H__ */ diff --git a/OGoContentStore/OCSFolderType.m b/OGoContentStore/OCSFolderType.m index 5f15e9dc..20940048 100644 --- a/OGoContentStore/OCSFolderType.m +++ b/OGoContentStore/OCSFolderType.m @@ -23,6 +23,7 @@ #include "OCSFolderType.h" #include "OCSFolder.h" #include "OCSFieldInfo.h" +#include "OCSiCalFieldExtractor.h" #include "common.h" #include @@ -132,6 +133,13 @@ return sql; } +/* quick support */ + +- (OCSFieldExtractor *)quickExtractor { + // TODO: hack + return [OCSiCalFieldExtractor sharedICalFieldExtractor]; +} + /* description */ - (NSString *)description { diff --git a/OGoContentStore/OCSiCalFieldExtractor.m b/OGoContentStore/OCSiCalFieldExtractor.m index 629da25a..135a48e0 100644 --- a/OGoContentStore/OCSiCalFieldExtractor.m +++ b/OGoContentStore/OCSiCalFieldExtractor.m @@ -22,11 +22,33 @@ #include "OCSiCalFieldExtractor.h" #include "common.h" +#include +#include @implementation OCSiCalFieldExtractor +static id parser = nil; +static SaxObjectDecoder *sax = nil; static OCSiCalFieldExtractor *extractor = nil; ++ (void)initialize { + if (parser == nil) { + parser = [[[SaxXMLReaderFactory standardXMLReaderFactory] + createXMLReaderForMimeType:@"text/calendar"] + retain]; + if (parser == nil) + NSLog(@"ERROR: did not find a parser for text/calendar!"); + } + if (sax == nil) { + sax = [[SaxObjectDecoder alloc] initWithMappingNamed:@"NGiCal"]; + if (sax == nil) + NSLog(@"ERROR: could not create the iCal SAX handler!"); + } + + [parser setContentHandler:sax]; + [parser setErrorHandler:sax]; +} + + (id)sharedICalFieldExtractor { if (extractor == nil) extractor = [[self alloc] init]; return extractor; @@ -36,4 +58,80 @@ static OCSiCalFieldExtractor *extractor = nil; [super dealloc]; } +/* operations */ + +- (NSNumber *)numberForDate:(NSCalendarDate *)_date { + return [NSNumber numberWithUnsignedInt:[_date timeIntervalSince1970]]; +} + +- (NSMutableDictionary *)extractQuickFieldsFromEvent:(iCalEvent *)_event { + NSMutableDictionary *row; + NSCalendarDate *startDate, *endDate; + NSString *uid; + NSString *title; + id participants; + + if (_event == nil) + return nil; + + /* extract values */ + + startDate = [_event startDate]; + endDate = [_event endDate]; + uid = [_event uid]; + title = [_event summary]; + + participants = [[_event attendees] valueForKey:@"cn"]; + participants = [participants componentsJoinedByString:@", "]; + + /* build row */ + + row = [NSMutableDictionary dictionaryWithCapacity:8]; + + if ([title isNotNull]) [row setObject:title forKey:@"title"]; + if ([uid isNotNull]) [row setObject:uid forKey:@"uid"]; + + if ([startDate isNotNull]) + [row setObject:[self numberForDate:startDate] forKey:@"startdate"]; + if ([endDate isNotNull]) + [row setObject:[self numberForDate:endDate] forKey:@"enddate"]; + + if ([participants length] > 0) + [row setObject:participants forKey:@"participants"]; + + return row; +} + +- (NSMutableDictionary *)extractQuickFieldsFromCalendar:(iCalCalendar *)_cal { + id event; + + if (_cal == nil) + return nil; + + event = [[_cal events] lastObject]; + return [self extractQuickFieldsFromEvent:event]; +} + +- (NSMutableDictionary *)extractQuickFieldsFromContent:(NSString *)_content { + NSAutoreleasePool *pool; + NSDictionary *fields; + id cal; + + if (parser == nil || sax == nil) + return nil; + if ([_content length] == 0) + return nil; + + pool = [[NSAutoreleasePool alloc] init]; + + [parser parseFromSource:_content]; + cal = [sax rootObject]; + fields = [[self extractQuickFieldsFromCalendar:cal] retain]; + [sax reset]; + + [pool release]; + + return [fields autorelease]; +} + @end /* OCSiCalFieldExtractor */