From 135b28c20c5076f3ae027162250a222303594682 Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 9 May 2005 00:10:22 +0000 Subject: [PATCH] finishing touches on the vcard parser git-svn-id: http://svn.opengroupware.org/SOPE/trunk@806 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-ical/NGiCal/ChangeLog | 4 + sope-ical/NGiCal/GNUmakefile | 4 +- sope-ical/NGiCal/NGVCard.h | 44 +++ sope-ical/NGiCal/NGVCard.m | 127 ++++++++- sope-ical/NGiCal/NGVCardCategories.m | 98 ------- sope-ical/NGiCal/NGVCardOrg.h | 3 + sope-ical/NGiCal/NGVCardOrg.m | 25 ++ sope-ical/NGiCal/NGVCardSaxHandler.h | 5 +- sope-ical/NGiCal/NGVCardSaxHandler.m | 255 +++++++++++++++--- ...ardCategories.h => NGVCardStrArrayValue.h} | 21 +- sope-ical/NGiCal/NGVCardStrArrayValue.m | 146 ++++++++++ sope-ical/NGiCal/Version | 2 +- 12 files changed, 585 insertions(+), 149 deletions(-) delete mode 100644 sope-ical/NGiCal/NGVCardCategories.m rename sope-ical/NGiCal/{NGVCardCategories.h => NGVCardStrArrayValue.h} (69%) create mode 100644 sope-ical/NGiCal/NGVCardStrArrayValue.m diff --git a/sope-ical/NGiCal/ChangeLog b/sope-ical/NGiCal/ChangeLog index cf4d0931..c63ba004 100644 --- a/sope-ical/NGiCal/ChangeLog +++ b/sope-ical/NGiCal/ChangeLog @@ -1,3 +1,7 @@ +2005-05-09 Helge Hess + + * first version of working vCard SAX handler (v4.5.54) + 2005-05-08 Helge Hess * more work on vCard parsing (v4.5.53) diff --git a/sope-ical/NGiCal/GNUmakefile b/sope-ical/NGiCal/GNUmakefile index 09c626e6..fbbf97af 100644 --- a/sope-ical/NGiCal/GNUmakefile +++ b/sope-ical/NGiCal/GNUmakefile @@ -36,7 +36,7 @@ libNGiCal_HEADER_FILES = \ \ NGVCard.h \ NGVCardAddress.h \ - NGVCardCategories.h \ + NGVCardStrArrayValue.h \ NGVCardName.h \ NGVCardOrg.h \ NGVCardPhone.h \ @@ -73,7 +73,7 @@ libNGiCal_OBJC_FILES = \ \ NGVCard.m \ NGVCardAddress.m \ - NGVCardCategories.m \ + NGVCardStrArrayValue.m \ NGVCardName.m \ NGVCardOrg.m \ NGVCardPhone.m \ diff --git a/sope-ical/NGiCal/NGVCard.h b/sope-ical/NGiCal/NGVCard.h index f6fa1661..a5d8a402 100644 --- a/sope-ical/NGiCal/NGVCard.h +++ b/sope-ical/NGiCal/NGVCard.h @@ -56,6 +56,7 @@ */ @class NSString, NSArray, NSDictionary; +@class NGVCardStrArrayValue, NGVCardOrg, NGVCardName; @interface NGVCard : NSObject { @@ -64,11 +65,26 @@ NSString *vClass; NSString *prodID; // TODO: 'rev' (datetime) + + NSString *fn; + NSString *role; + NSString *title; + NSString *bday; + NSString *note; + + NGVCardName *n; + NGVCardOrg *org; + + NGVCardStrArrayValue *nickname; + NGVCardStrArrayValue *categories; NSArray *tel; NSArray *adr; NSArray *email; NSArray *label; + NSArray *url; + NSArray *fburl; + NSArray *caluri; NSDictionary *x; } @@ -88,6 +104,27 @@ - (void)setProdID:(NSString *)_s; - (NSString *)prodID; +- (void)setFn:(NSString *)_fn; +- (NSString *)fn; +- (void)setRole:(NSString *)_s; +- (NSString *)role; +- (void)setTitle:(NSString *)_title; +- (NSString *)title; +- (void)setBday:(NSString *)_bday; +- (NSString *)bday; +- (void)setNote:(NSString *)_note; +- (NSString *)note; + +- (void)setN:(NGVCardName *)_v; +- (NGVCardName *)n; +- (void)setOrg:(NGVCardOrg *)_v; +- (NGVCardOrg *)org; + +- (void)setNickname:(id)_v; +- (NGVCardStrArrayValue *)nickname; +- (void)setCategories:(id)_v; +- (NGVCardStrArrayValue *)categories; + - (void)setTel:(NSArray *)_tel; - (NSArray *)tel; - (void)setAdr:(NSArray *)_adr; @@ -96,6 +133,13 @@ - (NSArray *)email; - (void)setLabel:(NSArray *)_array; - (NSArray *)label; +- (void)setUrl:(NSArray *)_url; +- (NSArray *)url; + +- (void)setFreeBusyURL:(NSArray *)_v; +- (NSArray *)freeBusyURL; +- (void)setCalURI:(NSArray *)_calURI; +- (NSArray *)calURI; - (void)setX:(NSDictionary *)_dict; - (NSDictionary *)x; diff --git a/sope-ical/NGiCal/NGVCard.m b/sope-ical/NGiCal/NGVCard.m index f1de3bcf..2aace43a 100644 --- a/sope-ical/NGiCal/NGVCard.m +++ b/sope-ical/NGiCal/NGVCard.m @@ -21,6 +21,9 @@ #include "NGVCard.h" #include "NGVCardSaxHandler.h" +#include "NGVCardStrArrayValue.h" +#include "NGVCardName.h" +#include "NGVCardOrg.h" #include #include #include "common.h" @@ -74,15 +77,27 @@ static NGVCardSaxHandler *sax = nil; // THREAD } - (void)dealloc { - [self->vClass release]; - [self->prodID release]; - [self->x release]; - [self->tel release]; - [self->adr release]; - [self->email release]; - [self->label release]; - [self->version release]; - [self->uid release]; + [self->n release]; + [self->org release]; + [self->nickname release]; + [self->categories release]; + [self->caluri release]; + [self->fburl release]; + [self->role release]; + [self->fn release]; + [self->title release]; + [self->bday release]; + [self->note release]; + [self->vClass release]; + [self->prodID release]; + [self->x release]; + [self->tel release]; + [self->url release]; + [self->adr release]; + [self->email release]; + [self->label release]; + [self->version release]; + [self->uid release]; [super dealloc]; } @@ -113,6 +128,78 @@ static NGVCardSaxHandler *sax = nil; // THREAD return self->prodID; } +- (void)setFn:(NSString *)_fn { + ASSIGNCOPY(self->fn, _fn); +} +- (NSString *)fn { + return self->fn; +} + +- (void)setRole:(NSString *)_role { + ASSIGNCOPY(self->role, _role); +} +- (NSString *)role { + return self->role; +} + +- (void)setTitle:(NSString *)_title { + ASSIGNCOPY(self->title, _title); +} +- (NSString *)title { + return self->title; +} + +- (void)setBday:(NSString *)_bday { + ASSIGNCOPY(self->bday, _bday); +} +- (NSString *)bday { + return self->bday; +} + +- (void)setNote:(NSString *)_note { + ASSIGNCOPY(self->note, _note); +} +- (NSString *)note { + return self->note; +} + + +- (void)setN:(NGVCardName *)_v { + ASSIGNCOPY(self->n, _v); +} +- (NGVCardName *)n { + return self->n; +} + +- (void)setOrg:(NGVCardOrg *)_v { + ASSIGNCOPY(self->org, _v); +} +- (NGVCardOrg *)org { + return self->org; +} + + +- (void)setNickname:(id)_v { + if (![_v isKindOfClass:[NGVCardStrArrayValue class]] && [_v isNotNull]) + _v = [[[NGVCardStrArrayValue alloc] initWithPropertyList:_v] autorelease]; + + ASSIGNCOPY(self->nickname, _v); +} +- (NGVCardStrArrayValue *)nickname { + return self->nickname; +} + +- (void)setCategories:(id)_v { + if (![_v isKindOfClass:[NGVCardStrArrayValue class]] && [_v isNotNull]) + _v = [[[NGVCardStrArrayValue alloc] initWithPropertyList:_v] autorelease]; + + ASSIGNCOPY(self->categories, _v); +} +- (NGVCardStrArrayValue *)categories { + return self->categories; +} + + - (void)setTel:(NSArray *)_tel { ASSIGNCOPY(self->tel, _tel); } @@ -141,6 +228,28 @@ static NGVCardSaxHandler *sax = nil; // THREAD return self->label; } +- (void)setUrl:(NSArray *)_url { + ASSIGNCOPY(self->url, _url); +} +- (NSArray *)url { + return self->url; +} + + +- (void)setFreeBusyURL:(NSArray *)_v { + ASSIGNCOPY(self->fburl, _v); +} +- (NSArray *)freeBusyURL { + return self->fburl; +} +- (void)setCalURI:(NSArray *)_v { + ASSIGNCOPY(self->caluri, _v); +} +- (NSArray *)calURI { + return self->caluri; +} + + - (void)setX:(NSDictionary *)_dict { ASSIGNCOPY(self->x, _dict); } diff --git a/sope-ical/NGiCal/NGVCardCategories.m b/sope-ical/NGiCal/NGVCardCategories.m deleted file mode 100644 index 6e50b692..00000000 --- a/sope-ical/NGiCal/NGVCardCategories.m +++ /dev/null @@ -1,98 +0,0 @@ -/* - Copyright (C) 2005 Helge Hess - - This file is part of SOPE. - - SOPE is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - SOPE is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with SOPE; see the file COPYING. If not, write to the - Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. -*/ - -#include "NGVCardCategories.h" -#include "common.h" - -@implementation NGVCardCategories - -- (void)dealloc { - [self->categories release]; - [super dealloc]; -} - -/* accessors */ - -- (NSArray *)categories { - return self->categories; -} - -/* values */ - -- (NSString *)stringValue { - return [self vCardString]; -} - -- (NSString *)xmlString { - return [[self stringValue] stringByEscapingXMLString]; -} - -- (NSString *)vCardString { - return [[self categories] componentsJoinedByString:@","]; -} - -- (id)propertyList { - return [self categories]; -} - -- (NSArray *)asArray { - return self->categories; -} - -/* fake being an array */ - -- (id)objectAtIndex:(unsigned)_idx { - return [self->categories objectAtIndex:_idx]; -} -- (unsigned)count { - return [self->categories count]; -} - -/* fake being a string */ - -- (unichar)characterAtIndex:(unsigned)_idx { - return [[self stringValue] characterAtIndex:_idx]; -} -- (unsigned)length { - return [[self stringValue] length]; -} - -/* NSCoding */ - -- (void)encodeWithCoder:(NSCoder *)_coder { - [super encodeWithCoder:_coder]; - [_coder encodeObject:self->categories]; -} -- (id)initWithCoder:(NSCoder *)_coder { - if ((self = [super initWithCoder:_coder]) != nil) { - self->categories = [[_coder decodeObject] copy]; - } - return self; -} - -/* description */ - -- (void)appendAttributesToDescription:(NSMutableString *)_ms { - [super appendAttributesToDescription:_ms]; - [_ms appendFormat:@" vcard=%@", [self vCardString]]; -} - -@end /* NGVCardCategories */ diff --git a/sope-ical/NGiCal/NGVCardOrg.h b/sope-ical/NGiCal/NGVCardOrg.h index b21ab0e7..0dbdfcf5 100644 --- a/sope-ical/NGiCal/NGVCardOrg.h +++ b/sope-ical/NGiCal/NGVCardOrg.h @@ -40,6 +40,9 @@ NSArray *orgunits; } +- (id)initWithName:(NSString *)_name units:(NSArray *)_units + group:(NSString *)_grp types:(NSArray *)_tps arguments:(NSDictionary *)_args; + /* accessors */ - (NSString *)orgnam; diff --git a/sope-ical/NGiCal/NGVCardOrg.m b/sope-ical/NGiCal/NGVCardOrg.m index e76e56b5..fb06c9e8 100644 --- a/sope-ical/NGiCal/NGVCardOrg.m +++ b/sope-ical/NGiCal/NGVCardOrg.m @@ -24,6 +24,26 @@ @implementation NGVCardOrg +- (id)initWithName:(NSString *)_name units:(NSArray *)_units + group:(NSString *)_grp types:(NSArray *)_tps arguments:(NSDictionary *)_a +{ + if ((self = [super initWithGroup:_grp types:_tps arguments:_a]) != nil) { + self->orgnam = [_name copy]; + self->orgunits = [_units copy]; + } + return self; +} + +- (id)initWithGroup:(NSString *)_group types:(NSArray *)_types + arguments:(NSDictionary *)_a +{ + return [self initWithName:nil units:nil + group:_group types:_types arguments:_a]; +} +- (id)init { + return [self initWithName:nil units:nil group:nil types:nil arguments:nil]; +} + - (void)dealloc { [self->orgnam release]; [self->orgunits release]; @@ -132,6 +152,11 @@ /* description */ - (void)appendAttributesToDescription:(NSMutableString *)_ms { + if (self->orgnam) [_ms appendFormat:@" %@", self->orgnam]; + if ([self->orgunits count] > 0) { + [_ms appendFormat:@" units=%@", + [self->orgunits componentsJoinedByString:@","]]; + } [super appendAttributesToDescription:_ms]; } diff --git a/sope-ical/NGiCal/NGVCardSaxHandler.h b/sope-ical/NGiCal/NGVCardSaxHandler.h index bbfa2c87..eb3d8e63 100644 --- a/sope-ical/NGiCal/NGVCardSaxHandler.h +++ b/sope-ical/NGiCal/NGVCardSaxHandler.h @@ -53,6 +53,8 @@ NSMutableArray *email; NSMutableArray *label; NSMutableArray *url; + NSMutableArray *fburl; + NSMutableArray *caluri; struct { int isInVCardSet:1; @@ -61,8 +63,9 @@ int isInAdr:1; int isInOrg:1; int isInGroup:1; + int isInGeo:1; int collectContent:1; - int reserved:25; + int reserved:24; } vcs; } diff --git a/sope-ical/NGiCal/NGVCardSaxHandler.m b/sope-ical/NGiCal/NGVCardSaxHandler.m index 1c0dd60d..aec3c3d4 100644 --- a/sope-ical/NGiCal/NGVCardSaxHandler.m +++ b/sope-ical/NGiCal/NGVCardSaxHandler.m @@ -27,7 +27,7 @@ #include "NGVCardPhone.h" #include "NGVCardName.h" #include "NGVCardOrg.h" -#include "NGVCardCategories.h" +#include "NGVCardStrArrayValue.h" #include "common.h" #ifndef XMLNS_VCARD_XML_03 @@ -35,6 +35,8 @@ @"http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" #endif +// TODO: this is wayyy to big and complicated ;-> + @implementation NGVCardSaxHandler - (void)dealloc { @@ -45,6 +47,9 @@ [self->adr release]; [self->email release]; [self->label release]; + [self->url release]; + [self->fburl release]; + [self->caluri release]; [self->types release]; [self->args release]; [self->vCards release]; @@ -61,16 +66,25 @@ /* state */ -- (void)resetExceptResult { - [self->currentGroup release]; self->currentGroup = nil; - [self->vCard release]; self->vCard = nil; - +- (void)resetCardState { [self->tel removeAllObjects]; [self->adr removeAllObjects]; [self->email removeAllObjects]; [self->label removeAllObjects]; + [self->url removeAllObjects]; + [self->fburl removeAllObjects]; + [self->caluri removeAllObjects]; + [self->xtags removeAllObjects]; + [self->currentGroup release]; self->currentGroup = nil; [self->types removeAllObjects]; [self->args removeAllObjects]; + [self->vCard release]; self->vCard = nil; +} + +- (void)resetExceptResult { + [self->vCard release]; self->vCard = nil; + + [self resetCardState]; if (self->content != NULL) { free(self->content); @@ -108,6 +122,13 @@ if (self->label == nil) self->label = [[NSMutableArray alloc] initWithCapacity:8]; + if (self->url == nil) + self->url = [[NSMutableArray alloc] initWithCapacity:8]; + if (self->fburl == nil) + self->fburl = [[NSMutableArray alloc] initWithCapacity:1]; + if (self->caluri == nil) + self->caluri = [[NSMutableArray alloc] initWithCapacity:1]; + if (self->types == nil) self->types = [[NSMutableArray alloc] initWithCapacity:4]; if (self->args == nil) @@ -125,6 +146,7 @@ /* common tags */ - (void)startValueTag:(NSString *)_tag attributes:(id)_attrs { + /* a tag with types and attributes */ unsigned i, count; [self->types removeAllObjects]; @@ -172,8 +194,7 @@ n = [[NGVCardName alloc] initWithPropertyList:self->subvalues group:self->currentGroup types:self->types arguments:self->args]; - NSLog(@"N: %@", n); - + [self->vCard setN:n]; [self->subvalues removeAllObjects]; [n release]; } @@ -184,14 +205,35 @@ } - (void)endOrg { NGVCardOrg *o; + NSArray *u; self->vcs.isInOrg = 0; - o = [[NGVCardOrg alloc] initWithGroup:self->currentGroup + if ((u = [self->subvalues objectForKey:@"orgunit"]) != nil) { + if (![u isKindOfClass:[NSArray class]]) + u = [NSArray arrayWithObjects:&u count:1]; + } + + // TODO: pass org values! + o = [[NGVCardOrg alloc] initWithName:[self->subvalues objectForKey:@"orgnam"] + units:u + group:self->currentGroup types:self->types arguments:self->args]; + [self->vCard setOrg:o]; + [o release]; + [self->subvalues removeAllObjects]; +} + +- (void)startGeo { + [self->subvalues removeAllObjects]; + self->vcs.isInGeo = 1; +} +- (void)endGeo { + // TODO - NSLog(@"O: %@: %@", o, self->subvalues); + self->vcs.isInGeo = 0; + [self logWithFormat:@"WARNING: not supporting geo in vCard."]; [self->subvalues removeAllObjects]; } @@ -199,11 +241,14 @@ NSString *uid, *version; NSString *t; - [self->tel removeAllObjects]; - [self->adr removeAllObjects]; - [self->email removeAllObjects]; - [self->label removeAllObjects]; - [self->xtags removeAllObjects]; + [self->tel removeAllObjects]; + [self->adr removeAllObjects]; + [self->email removeAllObjects]; + [self->label removeAllObjects]; + [self->url removeAllObjects]; + [self->fburl removeAllObjects]; + [self->caluri removeAllObjects]; + [self->xtags removeAllObjects]; self->vcs.isInVCard = 1; if (self->vCard != nil) { @@ -235,22 +280,19 @@ /* fill collected objects */ - if ([self->tel count] > 0) [self->vCard setTel:self->tel]; - if ([self->adr count] > 0) [self->vCard setAdr:self->adr]; - if ([self->email count] > 0) [self->vCard setEmail:self->email]; - if ([self->label count] > 0) [self->vCard setLabel:self->label]; - if ([self->xtags count] > 0) [self->vCard setX:self->xtags]; - [self->tel removeAllObjects]; - [self->adr removeAllObjects]; - [self->email removeAllObjects]; - [self->label removeAllObjects]; - [self->xtags removeAllObjects]; + if ([self->tel count] > 0) [self->vCard setTel:self->tel]; + if ([self->adr count] > 0) [self->vCard setAdr:self->adr]; + if ([self->email count] > 0) [self->vCard setEmail:self->email]; + if ([self->label count] > 0) [self->vCard setLabel:self->label]; + if ([self->url count] > 0) [self->vCard setUrl:self->url]; + if ([self->fburl count] > 0) [self->vCard setFreeBusyURL:self->fburl]; + if ([self->caluri count] > 0) [self->vCard setCalURI:self->caluri]; + if ([self->xtags count] > 0) [self->vCard setX:self->xtags]; - /* finish vCard, add to results */ - - [self debugWithFormat:@"finished vCard: %@", self->vCard]; [self->vCards addObject:self->vCard]; - [self->vCard release]; self->vCard = nil; + //[self debugWithFormat:@"finished vCard: %@", self->vCard]; + + [self resetCardState]; } - (void)startVCardSet:(id)_attrs { @@ -294,7 +336,6 @@ address = [[NGVCardAddress alloc] initWithPropertyList:self->subvalues group:self->currentGroup types:self->types arguments:self->args]; - NSLog(@"A: %@", address); [self->adr addObject:address]; [self->subvalues removeAllObjects]; @@ -330,6 +371,50 @@ andAddTo:self->url]; } +/* tags with comma separated values */ + +- (void)startNickname:(id)_attrs { + [self startValueTag:@"nickname" attributes:_attrs]; + [self startCollectingContent]; +} +- (void)endNickname { + NGVCardStrArrayValue *v; + NSArray *a; + + // comma unescaping? + a = [[self finishCollectingContent] componentsSeparatedByString:@","]; + + v = [[NGVCardStrArrayValue alloc] initWithArray:a + group:self->currentGroup + types:self->types arguments:self->args]; + [self->vCard setNickname:v]; + [v release]; v = nil; + + [self endValueTag]; +} + +- (void)startCategories:(id)_attrs { + [self startValueTag:@"categories" attributes:_attrs]; + [self startCollectingContent]; +} +- (void)endCategories { + NGVCardStrArrayValue *v; + NSArray *a; + + // comma unescaping? + a = [[self finishCollectingContent] componentsSeparatedByString:@","]; + + v = [[NGVCardStrArrayValue alloc] initWithArray:a + group:self->currentGroup + types:self->types arguments:self->args]; + [self->vCard setCategories:v]; + [v release]; v = nil; + + [self endValueTag]; +} + +/* generic processing of tags with subtags */ + - (void)startSubContentTag:(id)_attrs { if ([_attrs count] > 0) [self logWithFormat:@"WARNING: loosing attrs of subtag: %@", _attrs]; @@ -364,6 +449,7 @@ [s release]; } +/* extended tags (X-) */ - (void)startX:(NSString *)_name attributes:(id)_attrs { [self startValueTag:_name attributes:_attrs]; @@ -397,6 +483,71 @@ [self endValueTag]; } +/* flat tags */ + +- (void)startFN:(id)_attrs { + [self startValueTag:@"" attributes:_attrs]; + [self startCollectingContent]; +} +- (void)endFN { + [self->vCard setFn:[self finishCollectingContent]]; + [self endValueTag]; +} + +- (void)startRole:(id)_attrs { + [self startValueTag:@"" attributes:_attrs]; + [self startCollectingContent]; +} +- (void)endRole { + [self->vCard setRole:[self finishCollectingContent]]; + [self endValueTag]; +} + +- (void)startTitle:(id)_attrs { + [self startValueTag:@"" attributes:_attrs]; + [self startCollectingContent]; +} +- (void)endTitle { + [self->vCard setTitle:[self finishCollectingContent]]; + [self endValueTag]; +} + +- (void)startBDay:(id)_attrs { + [self startValueTag:@"" attributes:_attrs]; + [self startCollectingContent]; +} +- (void)endBDay { + [self->vCard setBday:[self finishCollectingContent]]; + [self endValueTag]; +} + +- (void)startNote:(id)_attrs { + [self startValueTag:@"" attributes:_attrs]; + [self startCollectingContent]; +} +- (void)endNote { + [self->vCard setNote:[self finishCollectingContent]]; + [self endValueTag]; +} + +- (void)startCalURI:(id)_attrs { + [self startValueTag:@"CALURI" attributes:_attrs]; + [self startCollectingContent]; +} +- (void)endCalURI { + [self endBaseContentTagWithClass:[NGVCardSimpleValue class] + andAddTo:self->caluri]; +} + +- (void)startFreeBusyURL:(id)_attrs { + [self startValueTag:@"FBURL" attributes:_attrs]; + [self startCollectingContent]; +} +- (void)endFreeBusyURL { + [self endBaseContentTagWithClass:[NGVCardSimpleValue class] + andAddTo:self->fburl]; +} + /* element events */ @@ -427,8 +578,29 @@ [self startVCard:_attrs]; else if (c0 == 'v' && [_localName isEqualToString:@"vCardSet"]) [self startVCardSet:_attrs]; + else if (c0 == 'n' && [_localName isEqualToString:@"nickname"]) + [self startNickname:_attrs]; + else if (c0 == 'c' && [_localName isEqualToString:@"categories"]) + [self startCategories:_attrs]; + else if (c0 == 'r' && [_localName isEqualToString:@"role"]) + [self startRole:_attrs]; + else if (c0 == 't' && [_localName isEqualToString:@"title"]) + [self startTitle:_attrs]; + else if (c0 == 'b' && [_localName isEqualToString:@"bday"]) + [self startBDay:_attrs]; + else if (c0 == 'n' && [_localName isEqualToString:@"note"]) + [self startNote:_attrs]; + else if (c0 == 'C' && [_localName isEqualToString:@"CALURI"]) + [self startCalURI:_attrs]; + else if (c0 == 'F' && [_localName isEqualToString:@"FBURL"]) + [self startFreeBusyURL:_attrs]; + else if (c0 == 'f' && [_localName isEqualToString:@"fn"]) + [self startFN:_attrs]; + else if (c0 == 'g' && [_localName isEqualToString:@"geo"]) + [self startGeo]; else { - if (self->vcs.isInN || self->vcs.isInOrg || self->vcs.isInAdr) + if (self->vcs.isInN || self->vcs.isInOrg || self->vcs.isInAdr || + self->vcs.isInGeo) [self startSubContentTag:_attrs]; else if (c0 == 'X') [self startX:_localName attributes:_attrs]; @@ -463,8 +635,29 @@ [self endVCard]; else if (c0 == 'v' && [_localName isEqualToString:@"vCardSet"]) [self endVCardSet]; + else if (c0 == 'n' && [_localName isEqualToString:@"nickname"]) + [self endNickname]; + else if (c0 == 'c' && [_localName isEqualToString:@"categories"]) + [self endCategories]; + else if (c0 == 'r' && [_localName isEqualToString:@"role"]) + [self endRole]; + else if (c0 == 't' && [_localName isEqualToString:@"title"]) + [self endTitle]; + else if (c0 == 'b' && [_localName isEqualToString:@"bday"]) + [self endBDay]; + else if (c0 == 'n' && [_localName isEqualToString:@"note"]) + [self endNote]; + else if (c0 == 'C' && [_localName isEqualToString:@"CALURI"]) + [self endCalURI]; + else if (c0 == 'F' && [_localName isEqualToString:@"FBURL"]) + [self endFreeBusyURL]; + else if (c0 == 'f' && [_localName isEqualToString:@"fn"]) + [self endFN]; + else if (c0 == 'g' && [_localName isEqualToString:@"geo"]) + [self endGeo]; else { - if (self->vcs.isInN || self->vcs.isInOrg || self->vcs.isInAdr) + if (self->vcs.isInN || self->vcs.isInOrg || self->vcs.isInAdr || + self->vcs.isInGeo) [self endSubContentTag:_localName]; else if (c0 == 'X') [self endX:_localName]; diff --git a/sope-ical/NGiCal/NGVCardCategories.h b/sope-ical/NGiCal/NGVCardStrArrayValue.h similarity index 69% rename from sope-ical/NGiCal/NGVCardCategories.h rename to sope-ical/NGiCal/NGVCardStrArrayValue.h index 05935df5..e4e607eb 100644 --- a/sope-ical/NGiCal/NGVCardCategories.h +++ b/sope-ical/NGiCal/NGVCardStrArrayValue.h @@ -19,28 +19,35 @@ 02111-1307, USA. */ -#ifndef __NGiCal_NGVCardCategories_H__ -#define __NGiCal_NGVCardCategories_H__ +#ifndef __NGiCal_NGVCardStrArrayValue_H__ +#define __NGiCal_NGVCardStrArrayValue_H__ #include /* - NGVCardCategories + NGVCardStrArrayValue + Represents a list of strings as used in vCards for 'category' or 'nickname' + tags. + Note: vCard apparently cannot represent categories which contain commas. At least Kontact and Evolution do not (no escaping of commas). */ @class NSArray; -@interface NGVCardCategories : NGVCardValue +@interface NGVCardStrArrayValue : NGVCardValue { - NSArray *categories; + NSArray *values; } +- (id)initWithArray:(NSArray *)_plist group:(NSString *)_group + types:(NSArray *)_types arguments:(NSDictionary *)_a; +- (id)initWithPropertyList:(id)_plist; + /* accessors */ -- (NSArray *)categories; +- (NSArray *)values; /* values */ @@ -53,4 +60,4 @@ @end -#endif /* __NGiCal_NGVCardCategories_H__ */ +#endif /* __NGiCal_NGVCardStrArrayValue_H__ */ diff --git a/sope-ical/NGiCal/NGVCardStrArrayValue.m b/sope-ical/NGiCal/NGVCardStrArrayValue.m new file mode 100644 index 00000000..decbbbd4 --- /dev/null +++ b/sope-ical/NGiCal/NGVCardStrArrayValue.m @@ -0,0 +1,146 @@ +/* + Copyright (C) 2005 Helge Hess + + This file is part of SOPE. + + SOPE is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOPE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "NGVCardStrArrayValue.h" +#include "common.h" + +@implementation NGVCardStrArrayValue + +- (id)initWithArray:(NSArray *)_plist group:(NSString *)_group + types:(NSArray *)_types arguments:(NSDictionary *)_a +{ + if ((self = [super initWithGroup:_group types:_types arguments:_a]) != nil) { + self->values = [_plist copy]; + } + return self; +} + +- (id)initWithString:(NSString *)_plist group:(NSString *)_group + types:(NSArray *)_types arguments:(NSDictionary *)_a +{ + // TODO: unescaping of commas? + return [self initWithArray:[_plist componentsSeparatedByString:@","] + group:_group types:_types arguments:_a]; +} + +- (id)initWithPropertyList:(id)_plist group:(NSString *)_group + types:(NSArray *)_types arguments:(NSDictionary *)_a +{ + if ([_plist isKindOfClass:[NSString class]]) { + return [self initWithString:_plist + group:_group types:_types arguments:_a]; + } + if ([_plist isKindOfClass:[NSArray class]]) { + return [self initWithArray:_plist + group:_group types:_types arguments:_a]; + } + + [self logWithFormat:@"ERROR: unexpected property list type: %@", + [_plist class]]; + [self release]; + return nil; +} +- (id)initWithPropertyList:(id)_plist { + return [self initWithPropertyList:_plist group:nil types:nil arguments:nil]; +} + +- (id)initWithGroup:(NSString *)_group types:(NSArray *)_types + arguments:(NSDictionary *)_a +{ + return [self initWithArray:nil + group:_group types:_types arguments:_a]; +} +- (id)init { + return [self initWithPropertyList:nil group:nil types:nil arguments:nil]; +} + +- (void)dealloc { + [self->values release]; + [super dealloc]; +} + +/* accessors */ + +- (NSArray *)values { + return self->values; +} + +/* values */ + +- (NSString *)stringValue { + return [self vCardString]; +} + +- (NSString *)xmlString { + return [[self stringValue] stringByEscapingXMLString]; +} + +- (NSString *)vCardString { + return [[self values] componentsJoinedByString:@","]; +} + +- (id)propertyList { + return [self values]; +} + +- (NSArray *)asArray { + return self->values; +} + +/* fake being an array */ + +- (id)objectAtIndex:(unsigned)_idx { + return [self->values objectAtIndex:_idx]; +} +- (unsigned)count { + return [self->values count]; +} + +/* fake being a string */ + +- (unichar)characterAtIndex:(unsigned)_idx { + return [[self stringValue] characterAtIndex:_idx]; +} +- (unsigned)length { + return [[self stringValue] length]; +} + +/* NSCoding */ + +- (void)encodeWithCoder:(NSCoder *)_coder { + [super encodeWithCoder:_coder]; + [_coder encodeObject:self->values]; +} +- (id)initWithCoder:(NSCoder *)_coder { + if ((self = [super initWithCoder:_coder]) != nil) { + self->values = [[_coder decodeObject] copy]; + } + return self; +} + +/* description */ + +- (void)appendAttributesToDescription:(NSMutableString *)_ms { + [super appendAttributesToDescription:_ms]; + [_ms appendFormat:@" vcard=%@", [self vCardString]]; +} + +@end /* NGVCardStrArrayValue */ diff --git a/sope-ical/NGiCal/Version b/sope-ical/NGiCal/Version index d2b964f0..632bc18a 100644 --- a/sope-ical/NGiCal/Version +++ b/sope-ical/NGiCal/Version @@ -2,7 +2,7 @@ MAJOR_VERSION=4 MINOR_VERSION=5 -SUBMINOR_VERSION:=53 +SUBMINOR_VERSION:=54 # v4.5.40 requires NGExtensions v4.5.145 # v4.5.37 requires NGExtensions v4.5.140 -- 2.39.2