#import <Foundation/NSObject.h>
-@class NSString, NSURL, NSNumber, NSArray;
+@class NSString, NSURL, NSNumber, NSArray, NSException;
@class EOAdaptorChannel;
@class OCSFolderManager, OCSFolderType, OCSChannelManager;
- (NSArray *)allSubFolderNames;
- (NSString *)fetchContentWithName:(NSString *)_name;
+- (NSException *)writeContent:(NSString *)_content toName:(NSString *)_name;
@end
#include "OCSFolderManager.h"
#include "OCSFolderType.h"
#include "OCSChannelManager.h"
+#include "OCSFieldExtractor.h"
#include "NSURL+OCS.h"
#include "EOAdaptorChannel+OCS.h"
#include "common.h"
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 {
#include "OCSiCalFieldExtractor.h"
#include "common.h"
+#include <SaxObjC/SaxObjC.h>
+#include <NGiCal/NGiCal.h>
@implementation OCSiCalFieldExtractor
+static id<NSObject,SaxXMLReader> 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;
[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 */