]> err.no Git - scalable-opengroupware.org/commitdiff
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@88 d1b88da0-ebda-0310-925b-ed51d8...
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Wed, 30 Jun 2004 00:10:07 +0000 (00:10 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Wed, 30 Jun 2004 00:10:07 +0000 (00:10 +0000)
OGoContentStore/OCSFieldExtractor.h
OGoContentStore/OCSFieldExtractor.m
OGoContentStore/OCSFolder.h
OGoContentStore/OCSFolder.m
OGoContentStore/OCSFolderType.h
OGoContentStore/OCSFolderType.m
OGoContentStore/OCSiCalFieldExtractor.m

index b32a9d31e2bb2410e964088419650f23510b6e04..128d67ad4f934be15ae278fff8703d48ede75225 100644 (file)
 
 #import <Foundation/NSObject.h>
 
+@class NSString, NSMutableDictionary;
+
 @interface OCSFieldExtractor : NSObject
 {
 }
 
+- (NSMutableDictionary *)extractQuickFieldsFromContent:(NSString *)_content;
+
 @end
 
 #endif /* __OGoContentStore_OCSFieldExtractor_H__ */
index 1b8ed2dd76858b34267ecb7569907a6c7b630978..a18d4990029e80b0b414a8b1e3217ffff078e381 100644 (file)
@@ -29,4 +29,8 @@
   [super dealloc];
 }
 
+- (NSMutableDictionary *)extractQuickFieldsFromContent:(NSString *)_content {
+  return nil;
+}
+
 @end /* OCSFieldExtractor */
index abf361433f3e255e0567b864090220ab2590ad6f..f47000dcd503ae3c7f1913e8fe09b4d146ef94f8 100644 (file)
@@ -25,7 +25,7 @@
 
 #import <Foundation/NSObject.h>
 
-@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
 
index 1879528224a89cc13362a37b4862ccf6327965bb..cdf7e5058786bb5cf0172a0c58835b50a0d05260 100644 (file)
@@ -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 {
index 57eb7dc9f416c3ced9fcc4f7abfffb824b5120e4..c4583f45b95b3185ce4ce5ae46bc460ad5fe3e54 100644 (file)
@@ -41,7 +41,7 @@
 
 @class NSString, NSArray, NSDictionary;
 @class EOQualifier;
-@class OCSFolder;
+@class OCSFolder, OCSFieldExtractor;
 
 @interface OCSFolderType : NSObject
 {
 
 - (NSString *)sqlQuickCreateWithTableName:(NSString *)_tabName;
 
+/* quick support */
+
+- (OCSFieldExtractor *)quickExtractor;
+
 @end
 
 #endif /* __OGoContentStore_OCSFolderType_H__ */
index 5f15e9dca9067bd7e206adbc936ddd82c6d4c7f2..2094004872d3561f8834639a88b3e7874c4d0d02 100644 (file)
@@ -23,6 +23,7 @@
 #include "OCSFolderType.h"
 #include "OCSFolder.h"
 #include "OCSFieldInfo.h"
+#include "OCSiCalFieldExtractor.h"
 #include "common.h"
 #include <EOControl/EOKeyValueCoding.h>
 
   return sql;
 }
 
+/* quick support */
+
+- (OCSFieldExtractor *)quickExtractor {
+  // TODO: hack
+  return [OCSiCalFieldExtractor sharedICalFieldExtractor];
+}
+
 /* description */
 
 - (NSString *)description {
index 629da25ac4edf613456dcf9c5a514b5733141138..135a48e0c9d92b00aeeaa28b7d514da57cf0197d 100644 (file)
 
 #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;
@@ -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 */