From: helge Date: Fri, 15 Jul 2005 09:30:28 +0000 (+0000) Subject: added parsing method to iCalCalendar X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3d24c65ef3cfea596991854d73693423f6329dc;p=sope added parsing method to iCalCalendar reset sax driver in NGVCard parsing git-svn-id: http://svn.opengroupware.org/SOPE/trunk@905 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-ical/NGiCal/ChangeLog b/sope-ical/NGiCal/ChangeLog index 1d4cd5d1..6dc41f03 100644 --- a/sope-ical/NGiCal/ChangeLog +++ b/sope-ical/NGiCal/ChangeLog @@ -1,24 +1,28 @@ -2005-07-15 Marcus Mueller +2005-07-15 Helge Hess - * v4.5.52 - - * iCalEntityObject.[hm]: added -increaseSequence + * v4.5.53 - * v4.5.51 + * iCalCalendar.m: added +parseCalendarFromSource: convenience method + + * NGVCard.m: properly reset sax driver after parsing + +2005-07-15 Marcus Mueller + + * iCalEntityObject.[hm]: added -increaseSequence (v4.5.52) * iCalPerson.m: fixed -hasSameEmailAddress: to lowercase email - addresses before attempting comparison + addresses before attempting comparison (v4.5.51) 2005-07-15 Helge Hess * v4.5.50 - + * NGiCal.xmap: fixed mapping of 'method' property (is an attribute of the calendar) * iCalCalendar.m: use ASSIGNCOPY in accessors, added 'method' to -description - + 2005-07-14 Marcus Mueller * v4.5.49 diff --git a/sope-ical/NGiCal/NGVCard.m b/sope-ical/NGiCal/NGVCard.m index 5cc77213..8be6a93a 100644 --- a/sope-ical/NGiCal/NGVCard.m +++ b/sope-ical/NGiCal/NGVCard.m @@ -43,7 +43,7 @@ static NGVCardSaxHandler *sax = nil; // THREAD createXMLReaderForMimeType:@"text/x-vcard"] retain]; if (parser == nil) { - NSLog(@"%s: did not find a parser for text/x-vcard !", + NSLog(@"ERROR(%s): did not find a parser for text/x-vcard!", __PRETTY_FUNCTION__); return nil; } @@ -57,12 +57,15 @@ static NGVCardSaxHandler *sax = nil; // THREAD + (NSArray *)parseVCardsFromSource:(id)_src { static id parser; + NSArray *vCards; if ((parser = [self vCardParser]) == nil) return nil; [parser parseFromSource:_src]; - return [sax vCards]; + vCards = [[sax vCards] retain]; + [sax reset]; + return [vCards autorelease]; } - (id)initWithUid:(NSString *)_uid version:(NSString *)_version { diff --git a/sope-ical/NGiCal/Version b/sope-ical/NGiCal/Version index 3a758962..d2b964f0 100644 --- a/sope-ical/NGiCal/Version +++ b/sope-ical/NGiCal/Version @@ -2,7 +2,7 @@ MAJOR_VERSION=4 MINOR_VERSION=5 -SUBMINOR_VERSION:=52 +SUBMINOR_VERSION:=53 # v4.5.40 requires NGExtensions v4.5.145 # v4.5.37 requires NGExtensions v4.5.140 diff --git a/sope-ical/NGiCal/iCalCalendar.h b/sope-ical/NGiCal/iCalCalendar.h index 0227c88b..2170827f 100644 --- a/sope-ical/NGiCal/iCalCalendar.h +++ b/sope-ical/NGiCal/iCalCalendar.h @@ -25,7 +25,7 @@ #include @class NSString, NSMutableArray, NSArray, NSEnumerator, NSMutableDictionary; -@class iCalEvent, iCalToDo, iCalJournal, iCalFreeBusy; +@class iCalEvent, iCalToDo, iCalJournal, iCalFreeBusy, iCalEntityObject; @interface iCalCalendar : iCalObject { @@ -41,6 +41,9 @@ NSMutableDictionary *timezones; } ++ (iCalCalendar *)parseCalendarFromSource:(id)_src; +- (id)initWithEntityObject:(iCalEntityObject *)_entityObject; + /* accessors */ - (NSString *)calscale; diff --git a/sope-ical/NGiCal/iCalCalendar.m b/sope-ical/NGiCal/iCalCalendar.m index 3554848d..9bdddcba 100644 --- a/sope-ical/NGiCal/iCalCalendar.m +++ b/sope-ical/NGiCal/iCalCalendar.m @@ -20,10 +20,96 @@ */ #include "iCalCalendar.h" +#include +#include "iCalEntityObject.h" #include "common.h" +@interface iCalCalendar(Privates) +- (void)addToEvents:(iCalEvent *)_event; +- (void)addToTimezones:(id)_tz; +- (void)addToTodos:(iCalToDo *)_todo; +- (void)addToJournals:(iCalJournal *)_obj; +- (void)addToFreeBusys:(iCalFreeBusy *)_obj; +@end + @implementation iCalCalendar +static id parser = nil; // THREAD +static SaxObjectDecoder *sax = nil; // THREAD + ++ (id)iCalParser { + if (sax == nil) { + sax = [[SaxObjectDecoder alloc] initWithMappingNamed:@"NGiCal"];; + if (sax == nil) { + NSLog(@"ERROR(%s): could not create iCal SAX handler!", + __PRETTY_FUNCTION__); + } + } + if (sax != nil && parser == nil) { + parser = + [[[SaxXMLReaderFactory standardXMLReaderFactory] + createXMLReaderForMimeType:@"text/calendar"] + retain]; + if (parser == nil) { + NSLog(@"ERROR(%s): did not find a parser for text/calendar!", + __PRETTY_FUNCTION__); + return nil; + } + + [parser setContentHandler:sax]; + [parser setErrorHandler:sax]; + } + return parser; +} + ++ (iCalCalendar *)parseCalendarFromSource:(id)_src { + static id parser; + id root, cal; + + if ((parser = [self iCalParser]) == nil) + return nil; + + [parser parseFromSource:_src]; + root = [[sax rootObject] retain]; + [sax reset]; + + if (root == nil) + return nil; + if ([root isKindOfClass:self]) + return [root autorelease]; + + if (![root isKindOfClass:[iCalEntityObject class]]) { + NSLog(@"ERROR(%s): parsed object is of an unexpected class %@: %@", + __PRETTY_FUNCTION__, NSStringFromClass([root class]), root); + [root release]; + return nil; + } + + /* so we just got an iCalEntityObject, wrap that manually into a cal */ + cal = [[[self alloc] initWithEntityObject:root] autorelease]; + [root release]; root = nil; + return cal; +} + +- (id)initWithEntityObject:(iCalEntityObject *)_entityObject { + if ((self = [self init])) { + if ([_entityObject isKindOfClass:[iCalEvent class]]) + [self addToEvents:(iCalEvent *)_entityObject]; + else if ([_entityObject isKindOfClass:[iCalToDo class]]) + [self addToTodos:(iCalToDo *)_entityObject]; + else if ([_entityObject isKindOfClass:[iCalJournal class]]) + [self addToJournals:(iCalJournal *)_entityObject]; + else if ([_entityObject isKindOfClass:[iCalFreeBusy class]]) + [self addToFreeBusys:(iCalFreeBusy *)_entityObject]; + else if ([_entityObject isNotNull]) { + [self errorWithFormat:@"Unexpected entity object: %@", _entityObject]; + [self release]; + return nil; + } + } + return self; +} + - (void)dealloc { [self->version release]; [self->calscale release]; @@ -112,7 +198,7 @@ return self->journals; } -- (void)addToFreeBusys:(iCalJournal *)_obj { +- (void)addToFreeBusys:(iCalFreeBusy *)_obj { if (_obj == nil) return; if (self->freeBusys == nil) self->freeBusys = [[NSMutableArray alloc] initWithCapacity:4];