From fb2535c9657d549c44b79767e7f1790e8e346476 Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 19 Oct 2004 16:57:59 +0000 Subject: [PATCH] added methods to render apts as just vevents git-svn-id: http://svn.opengroupware.org/SOGo/trunk@410 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGoLogic/ChangeLog | 9 ++++++ SOGoLogic/SOGoAppointment.h | 1 + SOGoLogic/SOGoAppointment.m | 4 +++ SOGoLogic/SOGoAppointmentICalRenderer.h | 1 + SOGoLogic/SOGoAppointmentICalRenderer.m | 38 +++++++++++++++++++------ 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/SOGoLogic/ChangeLog b/SOGoLogic/ChangeLog index 6caa5714..5e2ddc31 100644 --- a/SOGoLogic/ChangeLog +++ b/SOGoLogic/ChangeLog @@ -1,5 +1,14 @@ 2004-10-19 Helge Hess + * v0.9.21 + + * SOGoAppointment.m: added the -vEventString method (base on the new + renderer method) + + * SOGoAppointmentICalRenderer.m :added -vEventStringForAppointment: + method to render a SOGoAppointment as just a vevent (without the + vcalendar wrapper) + * SOGoAppointment.m: added a -description (v0.9.20) 2004-10-17 Marcus Mueller diff --git a/SOGoLogic/SOGoAppointment.h b/SOGoLogic/SOGoAppointment.h index d5cf0e0d..4c99db61 100644 --- a/SOGoLogic/SOGoAppointment.h +++ b/SOGoLogic/SOGoAppointment.h @@ -98,6 +98,7 @@ /* iCal generation */ - (NSString *)iCalString; +- (NSString *)vEventString; /* raw entity objects */ diff --git a/SOGoLogic/SOGoAppointment.m b/SOGoLogic/SOGoAppointment.m index de8dd2d0..a92f42f8 100644 --- a/SOGoLogic/SOGoAppointment.m +++ b/SOGoLogic/SOGoAppointment.m @@ -125,6 +125,10 @@ static SaxObjectDecoder *sax = nil; return [[SOGoAppointmentICalRenderer sharedAppointmentRenderer] stringForAppointment:self]; } +- (NSString *)vEventString { + return [[SOGoAppointmentICalRenderer sharedAppointmentRenderer] + vEventStringForAppointment:self]; +} /* forwarded methods */ diff --git a/SOGoLogic/SOGoAppointmentICalRenderer.h b/SOGoLogic/SOGoAppointmentICalRenderer.h index 3eebed2d..afdd2e6f 100644 --- a/SOGoLogic/SOGoAppointmentICalRenderer.h +++ b/SOGoLogic/SOGoAppointmentICalRenderer.h @@ -38,6 +38,7 @@ + (id)sharedAppointmentRenderer; +- (NSString *)vEventStringForAppointment:(SOGoAppointment *)_apt; - (NSString *)stringForAppointment:(SOGoAppointment *)_apt; @end diff --git a/SOGoLogic/SOGoAppointmentICalRenderer.m b/SOGoLogic/SOGoAppointmentICalRenderer.m index 57e9aa84..b95b8a10 100644 --- a/SOGoLogic/SOGoAppointmentICalRenderer.m +++ b/SOGoLogic/SOGoAppointmentICalRenderer.m @@ -35,6 +35,9 @@ static SOGoAppointmentICalRenderer *renderer = nil; +/* assume length of 1K - reasonable ? */ +static unsigned DefaultICalStringCapacity = 1024; + + (id)sharedAppointmentRenderer { if (renderer == nil) renderer = [[self alloc] init]; @@ -183,28 +186,45 @@ static SOGoAppointmentICalRenderer *renderer = nil; [s appendString:@"END:VEVENT\r\n"]; } -- (NSString *)stringForAppointment:(SOGoAppointment *)_apt { - NSMutableString *s; - - if (_apt == nil) - return nil; +- (BOOL)isValidAppointment:(SOGoAppointment *)_apt { + if (![_apt isNotNull]) + return NO; if ([[_apt uid] length] == 0) { [self logWithFormat: @"WARNING: got apt without uid, rejecting iCal generation: %@", _apt]; - return nil; + return NO; } if ([[[_apt startDate] icalString] length] == 0) { [self logWithFormat: @"WARNING: got apt without start date, " @"rejecting iCal generation: %@", _apt]; - return nil; + return NO; } - /* assume length of 1K - reasonable ? */ - s = [NSMutableString stringWithCapacity:1024]; + return YES; +} + +- (NSString *)vEventStringForAppointment:(SOGoAppointment *)_apt { + NSMutableString *s; + + if (![self isValidAppointment:_apt]) + return nil; + + s = [NSMutableString stringWithCapacity:DefaultICalStringCapacity]; + [self addVEventForAppointment:_apt toString:s]; + return s; +} + +- (NSString *)stringForAppointment:(SOGoAppointment *)_apt { + NSMutableString *s; + + if (![self isValidAppointment:_apt]) + return nil; + + s = [NSMutableString stringWithCapacity:DefaultICalStringCapacity]; [self addPreambleForAppointment:_apt toString:s]; [self addVEventForAppointment:_apt toString:s]; [self addPostambleForAppointment:_apt toString:s]; -- 2.39.5