From: helge Date: Sun, 8 May 2005 15:12:57 +0000 (+0000) Subject: added some vCard model objects X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecf5ee0a372035502881721ce3d18834cd3ebe6c;p=sope added some vCard model objects git-svn-id: http://svn.opengroupware.org/SOPE/trunk@803 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-ical/NGiCal/ChangeLog b/sope-ical/NGiCal/ChangeLog index 6c1fe824..716f419a 100644 --- a/sope-ical/NGiCal/ChangeLog +++ b/sope-ical/NGiCal/ChangeLog @@ -1,3 +1,7 @@ +2005-05-08 Helge Hess + + * work on vCard objects (incomplete) (v4.5.52) + 2005-04-25 Helge Hess * iCalDateHolder.m, iCalDataSource.m: fixed gcc 4.0 warnings (v4.5.51) diff --git a/sope-ical/NGiCal/GNUmakefile b/sope-ical/NGiCal/GNUmakefile index 403b9863..b05baa16 100644 --- a/sope-ical/NGiCal/GNUmakefile +++ b/sope-ical/NGiCal/GNUmakefile @@ -33,6 +33,11 @@ libNGiCal_HEADER_FILES = \ iCalRecurrenceCalculator.h \ \ NSCalendarDate+ICal.h \ + \ + NGVCard.h \ + NGVCardValue.h \ + NGVCardName.h \ + NGVCardAddress.h \ # IcalResponse.h \ @@ -58,6 +63,16 @@ libNGiCal_OBJC_FILES = \ iCalRenderer.m \ iCalRecurrenceRule.m \ iCalRecurrenceCalculator.m \ + \ + NGICalSaxHandler.m \ + NGVCardSaxHandler.m \ + NGVCard.m \ + NGVCardValue.m \ + NGVCardSimpleValue.m \ + NGVCardAddress.m \ + NGVCardPhone.m \ + NGVCardCategories.m \ + NGVCardName.m \ # NSString+ICal.m \ # IcalElements.m diff --git a/sope-ical/NGiCal/NGICalSaxHandler.h b/sope-ical/NGiCal/NGICalSaxHandler.h new file mode 100644 index 00000000..16e33068 --- /dev/null +++ b/sope-ical/NGiCal/NGICalSaxHandler.h @@ -0,0 +1,42 @@ +/* + 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. +*/ + +#ifndef __NGiCal_NGICalSaxHandler_H__ +#define __NGiCal_NGICalSaxHandler_H__ + +#include + +/* + NGICalSaxHandler + + NOTE: WORK IN PROGRESS, DOES NOT WORK YET! + + This SAX handler is supposed to create the NGiCal object model from SAX + events. +*/ + +@interface NGICalSaxHandler : SaxDefaultHandler +{ +} + +@end + +#endif /* __NGiCal_NGICalSaxHandler_H__ */ diff --git a/sope-ical/NGiCal/NGICalSaxHandler.m b/sope-ical/NGiCal/NGICalSaxHandler.m new file mode 100644 index 00000000..a7f2488f --- /dev/null +++ b/sope-ical/NGiCal/NGICalSaxHandler.m @@ -0,0 +1,56 @@ +/* + 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 "NGICalSaxHandler.h" +#include "common.h" + +@implementation NGICalSaxHandler + +- (void)dealloc { + [super dealloc]; +} + +/* document events */ + +- (void)startDocument { +} +- (void)endDocument { +} + +/* element events */ + +- (void)startElement:(NSString *)_localName + namespace:(NSString *)_ns + rawName:(NSString *)_rawName + attributes:(id)_attrs +{ +} + +- (void)endElement:(NSString *)_localName + namespace:(NSString *)_ns + rawName:(NSString *)_rawName +{ +} + +- (void)characters:(unichar *)_chars length:(int)_len { +} + +@end /* NGICalSaxHandler */ diff --git a/sope-ical/NGiCal/NGVCard.h b/sope-ical/NGiCal/NGVCard.h new file mode 100644 index 00000000..c84df571 --- /dev/null +++ b/sope-ical/NGiCal/NGVCard.h @@ -0,0 +1,39 @@ +/* + 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. +*/ + +#ifndef __NGiCal_NGVCard_H__ +#define __NGiCal_NGVCard_H__ + +#import + +/* + NGVCard + + Represents a vCard object. +*/ + +@interface NGVCard : NSObject +{ +} + +@end + +#endif /* __NGiCal_NGVCard_H__ */ diff --git a/sope-ical/NGiCal/NGVCard.m b/sope-ical/NGiCal/NGVCard.m new file mode 100644 index 00000000..268d5c90 --- /dev/null +++ b/sope-ical/NGiCal/NGVCard.m @@ -0,0 +1,31 @@ +/* + 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 "NGVCard.h" +#include "common.h" + +@implementation NGVCard + +- (void)dealloc { + [super dealloc]; +} + +@end /* NGVCard */ diff --git a/sope-ical/NGiCal/NGVCardAddress.h b/sope-ical/NGiCal/NGVCardAddress.h new file mode 100644 index 00000000..6953a995 --- /dev/null +++ b/sope-ical/NGiCal/NGVCardAddress.h @@ -0,0 +1,68 @@ +/* + 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. +*/ + +#ifndef __NGiCal_NGVCardAddress_H__ +#define __NGiCal_NGVCardAddress_H__ + +#include + +@class NSDictionary; + +/* + NGVCardAddress + + Represents a vCard address as transported in the 'ADR' vCard tag. +*/ + +@interface NGVCardAddress : NGVCardValue +{ + NSString *pobox; + NSString *extadd; + NSString *street; + NSString *locality; + NSString *region; + NSString *pcode; + NSString *country; +} + +/* accessors */ + +- (NSString *)pobox; +- (NSString *)extadd; +- (NSString *)street; +- (NSString *)locality; +- (NSString *)region; +- (NSString *)pcode; +- (NSString *)country; + +/* values */ + +- (NSDictionary *)asDictionary; +- (NSArray *)asArray; + +/* fake being an array */ + +- (id)objectAtIndex:(unsigned)_idx; +- (unsigned)count; + +@end + +#endif /* __NGiCal_NGVCardAddress_H__ */ diff --git a/sope-ical/NGiCal/NGVCardAddress.m b/sope-ical/NGiCal/NGVCardAddress.m new file mode 100644 index 00000000..227c07d3 --- /dev/null +++ b/sope-ical/NGiCal/NGVCardAddress.m @@ -0,0 +1,175 @@ +/* + 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 "NGVCardAddress.h" +#include "common.h" + +@implementation NGVCardAddress + +- (void)dealloc { + [self->pobox release]; + [self->extadd release]; + [self->street release]; + [self->locality release]; + [self->region release]; + [self->pcode release]; + [self->country release]; + [super dealloc]; +} + +/* accessors */ + +- (NSString *)pobox { + return self->pobox; +} +- (NSString *)extadd { + return self->extadd; +} +- (NSString *)street { + return self->street; +} +- (NSString *)locality { + return self->locality; +} +- (NSString *)region { + return self->region; +} +- (NSString *)pcode { + return self->pcode; +} +- (NSString *)country { + return self->country; +} + +/* fake being an array */ + +- (id)objectAtIndex:(unsigned)_idx { + NSString *s; + + switch (_idx) { + case 0: return (s = [self pobox]) ? s : (NSString *)[NSNull null]; + case 1: return (s = [self extadd]) ? s : (NSString *)[NSNull null]; + case 2: return (s = [self street]) ? s : (NSString *)[NSNull null]; + case 3: return (s = [self locality]) ? s : (NSString *)[NSNull null]; + case 4: return (s = [self region]) ? s : (NSString *)[NSNull null]; + case 5: return (s = [self pcode]) ? s : (NSString *)[NSNull null]; + case 6: return (s = [self country]) ? s : (NSString *)[NSNull null]; + } + + // TODO: throw exception + return nil; +} +- (unsigned)count { + return 7; +} + +/* values */ + +- (NSString *)stringValue { + return [self vCardString]; +} + +- (NSString *)xmlString { + NSMutableString *ms; + NSString *s; + + ms = [[NSMutableString alloc] initWithCapacity:256]; + [self appendXMLTag:@"pobox" value:[self pobox] to:ms]; + [self appendXMLTag:@"extadd" value:[self extadd] to:ms]; + [self appendXMLTag:@"street" value:[self street] to:ms]; + [self appendXMLTag:@"locality" value:[self locality] to:ms]; + [self appendXMLTag:@"region" value:[self region] to:ms]; + [self appendXMLTag:@"pcode" value:[self pcode] to:ms]; + [self appendXMLTag:@"country" value:[self country] to:ms]; + s = [[ms copy] autorelease]; + [ms release]; + return s; +} + +- (NSString *)vCardString { + NSMutableString *ms; + NSString *s; + + ms = [[NSMutableString alloc] initWithCapacity:256]; + [self appendVCardValue:[self pobox] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self extadd] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self street] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self locality] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self region] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self pcode] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self country] to:ms]; + s = [[ms copy] autorelease]; + [ms release]; + return s; +} + +- (NSDictionary *)asDictionary { + static NSString *keys[] = { + @"pobox", @"extadd", @"street", @"locality", @"region", @"pcode", + @"country", nil + }; + id values[8]; + unsigned i; + + for (i = 0; i < [self count]; i++) + values[i] = [self objectAtIndex:i]; + + return [NSDictionary dictionaryWithObjects:values forKeys:keys + count:[self count]]; +} + +- (NSArray *)asArray { + id values[[self count] + 1]; + unsigned i; + + for (i = 0; i < [self count]; i++) + values[i] = [self objectAtIndex:i]; + + return [NSArray arrayWithObjects:values count:[self count]]; +} + +/* NSCoding */ + +- (void)encodeWithCoder:(NSCoder *)_coder { + [super encodeWithCoder:_coder]; + + [_coder encodeObject:self->pobox]; + [_coder encodeObject:self->extadd]; + [_coder encodeObject:self->street]; + [_coder encodeObject:self->locality]; + [_coder encodeObject:self->region]; + [_coder encodeObject:self->pcode]; + [_coder encodeObject:self->country]; +} +- (id)initWithCoder:(NSCoder *)_coder { + if ((self = [super initWithCoder:_coder]) != nil) { + self->pobox = [[_coder decodeObject] copy]; + self->extadd = [[_coder decodeObject] copy]; + self->street = [[_coder decodeObject] copy]; + self->locality = [[_coder decodeObject] copy]; + self->region = [[_coder decodeObject] copy]; + self->pcode = [[_coder decodeObject] copy]; + self->country = [[_coder decodeObject] copy]; + } + return self; +} + +@end /* NGVCardAddress */ diff --git a/sope-ical/NGiCal/NGVCardCategories.m b/sope-ical/NGiCal/NGVCardCategories.m new file mode 100644 index 00000000..c87710eb --- /dev/null +++ b/sope-ical/NGiCal/NGVCardCategories.m @@ -0,0 +1,87 @@ +/* + 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 "NGVCardValue.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]; +} + +/* 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; +} + +@end /* NGVCardCategories */ diff --git a/sope-ical/NGiCal/NGVCardName.h b/sope-ical/NGiCal/NGVCardName.h new file mode 100644 index 00000000..c5f58f39 --- /dev/null +++ b/sope-ical/NGiCal/NGVCardName.h @@ -0,0 +1,64 @@ +/* + 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. +*/ + +#ifndef __NGiCal_NGVCardName_H__ +#define __NGiCal_NGVCardName_H__ + +#include + +/* + NGVCardName + + Represents a vCard name as transported in the 'N' vCard tag. +*/ + +@class NSString, NSDictionary; + +@interface NGVCardName : NGVCardValue +{ + NSString *family; + NSString *given; + NSString *other; + NSString *prefix; + NSString *suffix; +} + +/* accessors */ + +- (NSString *)family; +- (NSString *)given; +- (NSString *)other; +- (NSString *)prefix; +- (NSString *)suffix; + +/* values */ + +- (NSDictionary *)asDictionary; +- (NSArray *)asArray; + +/* fake being an array */ + +- (id)objectAtIndex:(unsigned)_idx; +- (unsigned)count; + +@end + +#endif /* __NGiCal_NGVCardName_H__ */ diff --git a/sope-ical/NGiCal/NGVCardName.m b/sope-ical/NGiCal/NGVCardName.m new file mode 100644 index 00000000..b40d590d --- /dev/null +++ b/sope-ical/NGiCal/NGVCardName.m @@ -0,0 +1,160 @@ +/* + 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 "NGVCardName.h" +#include "common.h" + +@implementation NGVCardName + +- (void)dealloc { + [self->family release]; + [self->given release]; + [self->other release]; + [self->prefix release]; + [self->suffix release]; + [super dealloc]; +} + +/* accessors */ + +- (NSString *)family { + return self->family; +} +- (NSString *)given { + return self->given; +} +- (NSString *)other { + return self->other; +} +- (NSString *)prefix { + return self->prefix; +} +- (NSString *)suffix { + return self->suffix; +} + +/* fake being an array */ + +- (id)objectAtIndex:(unsigned)_idx { + NSString *s; + + switch (_idx) { + case 0: return (s = [self family]) ? s : (NSString *)[NSNull null]; + case 1: return (s = [self given]) ? s : (NSString *)[NSNull null]; + case 2: return (s = [self other]) ? s : (NSString *)[NSNull null]; + case 3: return (s = [self prefix]) ? s : (NSString *)[NSNull null]; + case 4: return (s = [self suffix]) ? s : (NSString *)[NSNull null]; + } + + // TODO: throw exception + return nil; +} +- (unsigned)count { + return 5; +} + +/* values */ + +- (NSString *)stringValue { + return [self vCardString]; +} + +- (NSString *)xmlString { + NSMutableString *ms; + NSString *s; + + ms = [[NSMutableString alloc] initWithCapacity:256]; + [self appendXMLTag:@"family" value:[self family] to:ms]; + [self appendXMLTag:@"given" value:[self given] to:ms]; + [self appendXMLTag:@"other" value:[self other] to:ms]; + [self appendXMLTag:@"prefix" value:[self prefix] to:ms]; + [self appendXMLTag:@"suffix" value:[self suffix] to:ms]; + s = [[ms copy] autorelease]; + [ms release]; + return s; +} + +- (NSString *)vCardString { + NSMutableString *ms; + NSString *s; + + ms = [[NSMutableString alloc] initWithCapacity:256]; + [self appendVCardValue:[self family] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self given] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self other] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self prefix] to:ms]; [ms appendString:@";"]; + [self appendVCardValue:[self suffix] to:ms]; + s = [[ms copy] autorelease]; + [ms release]; + return s; +} + +- (NSDictionary *)asDictionary { + static NSString *keys[] = { + @"family", @"given", @"other", @"prefix", @"suffix", nil + }; + id values[[self count] + 1]; + unsigned i; + + for (i = 0; i < [self count]; i++) + values[i] = [self objectAtIndex:i]; + + return [NSDictionary dictionaryWithObjects:values forKeys:keys + count:[self count]]; +} + +- (NSArray *)asArray { + id values[[self count] + 1]; + unsigned i; + + for (i = 0; i < [self count]; i++) + values[i] = [self objectAtIndex:i]; + + return [NSArray arrayWithObjects:values count:[self count]]; +} + +- (id)propertyList { + return [self asDictionary]; +} + +/* NSCoding */ + +- (void)encodeWithCoder:(NSCoder *)_coder { + [super encodeWithCoder:_coder]; + + [_coder encodeObject:self->family]; + [_coder encodeObject:self->given]; + [_coder encodeObject:self->other]; + [_coder encodeObject:self->prefix]; + [_coder encodeObject:self->suffix]; +} +- (id)initWithCoder:(NSCoder *)_coder { + if ((self = [super initWithCoder:_coder]) != nil) { + self->family = [[_coder decodeObject] copy]; + self->given = [[_coder decodeObject] copy]; + self->other = [[_coder decodeObject] copy]; + self->prefix = [[_coder decodeObject] copy]; + self->suffix = [[_coder decodeObject] copy]; + } + return self; +} + +@end /* NGVCardName */ diff --git a/sope-ical/NGiCal/NGVCardPhone.m b/sope-ical/NGiCal/NGVCardPhone.m new file mode 100644 index 00000000..2342feb2 --- /dev/null +++ b/sope-ical/NGiCal/NGVCardPhone.m @@ -0,0 +1,27 @@ +/* + 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 "NGVCardValue.h" +#include "common.h" + +@implementation NGVCardPhone + +@end /* NGVCardPhone */ diff --git a/sope-ical/NGiCal/NGVCardSaxHandler.h b/sope-ical/NGiCal/NGVCardSaxHandler.h new file mode 100644 index 00000000..98fe3da2 --- /dev/null +++ b/sope-ical/NGiCal/NGVCardSaxHandler.h @@ -0,0 +1,62 @@ +/* + 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. +*/ + +#ifndef __NGiCal_NGVCardSaxHandler_H__ +#define __NGiCal_NGVCardSaxHandler_H__ + +#include + +/* + NGVCardSaxHandler + + This SAX handler is supposed to create the NGiCal object model from SAX + events. +*/ + +@class NSString, NSMutableString, NSMutableArray; + +@interface NGVCardSaxHandler : SaxDefaultHandler +{ + NSMutableArray *vCards; + + id vCard; + NSString *currentGroup; + unichar *content; + unsigned contentLength; + + struct { + int isInVCardSet:1; + int isInVCard:1; + int isInN:1; + int isInGroup:1; + int collectContent:1; + int reserved:27; + } vcs; +} + +/* content */ + +- (void)startCollectingContent; +- (NSString *)finishCollectingContent; + +@end + +#endif /* __NGiCal_NGVCardSaxHandler_H__ */ diff --git a/sope-ical/NGiCal/NGVCardSaxHandler.m b/sope-ical/NGiCal/NGVCardSaxHandler.m new file mode 100644 index 00000000..71ccd1cf --- /dev/null +++ b/sope-ical/NGiCal/NGVCardSaxHandler.m @@ -0,0 +1,192 @@ +/* + 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 "NGVCardSaxHandler.h" +#include "common.h" + +@implementation NGVCardSaxHandler + +- (void)dealloc { + if (self->content != NULL) free(self->content); + [self->vCards release]; + [self->vCard release]; + [self->currentGroup release]; + [super dealloc]; +} + +/* state */ + +- (void)resetExceptResult { + [self->currentGroup release]; self->currentGroup = nil; + [self->vCard release]; self->vCard = nil; + + if (self->content != NULL) { + free(self->content); + self->content = NULL; + } + + self->vcs.isInVCardSet = 0; + self->vcs.isInVCard = 0; + self->vcs.isInN = 0; + self->vcs.isInGroup = 0; + self->vcs.collectContent = 0; +} + +- (void)reset { + [self resetExceptResult]; + [self->vCards removeAllObjects]; +} + +/* document events */ + +- (void)startDocument { + [self reset]; + if (self->vCards == nil) + self->vCards = [[NSMutableArray alloc] initWithCapacity:16]; +} +- (void)endDocument { + [self resetExceptResult]; +} + +/* handle elements */ + +- (void)startGroup:(NSString *)_name { + self->vcs.isInGroup = 1; + ASSIGNCOPY(self->currentGroup, _name); +} +- (void)endGroup { + self->vcs.isInGroup = 0; + [self->currentGroup release]; self->currentGroup = nil; +} + +- (void)startN { + self->vcs.isInN = 1; +} +- (void)endN { + self->vcs.isInN = 0; +} + +- (void)startVCard:(id)_attrs { + self->vcs.isInVCard = 1; +} +- (void)endVCard { + self->vcs.isInVCard = 0; +} + +- (void)startVCardSet:(id)_attrs { + self->vcs.isInVCardSet = 1; +} +- (void)endVCardSet { + self->vcs.isInVCardSet = 0; +} + +/* element events */ + +- (void)startElement:(NSString *)_localName + namespace:(NSString *)_ns + rawName:(NSString *)_rawName + attributes:(id)_attrs +{ + if ([_localName isEqualToString:@"group"]) + [self startGroup:[_attrs valueForName:@"name" uri:_ns]]; + else if ([_localName isEqualToString:@"n"]) + [self startN]; + else if ([_localName isEqualToString:@"tel"]) + ; + else if ([_localName isEqualToString:@"vCard"]) + [self startVCard:_attrs]; + else if ([_localName isEqualToString:@"vCardSet"]) + [self startVCardSet:_attrs]; + + if (self->vcs.isInN) { + } +} + +- (void)endElement:(NSString *)_localName + namespace:(NSString *)_ns + rawName:(NSString *)_rawName +{ + if (self->vcs.isInN) { + } + + if ([_localName isEqualToString:@"group"]) + [self endGroup]; + else if ([_localName isEqualToString:@"n"]) + [self endN]; + else if ([_localName isEqualToString:@"tel"]) + ; + else if ([_localName isEqualToString:@"vCard"]) + [self endVCard]; + else if ([_localName isEqualToString:@"vCardSet"]) + [self endVCardSet]; +} + +/* content */ + +- (void)startCollectingContent { + if (self->content != NULL) { + free(self->content); + self->content = NULL; + } + self->vcs.collectContent = 1; +} + +- (NSString *)finishCollectingContent { + NSString *s; + + self->vcs.collectContent = 0; + + if (self->content == NULL) + return nil; + + if (self->contentLength == 0) + return @""; + + s = [NSString stringWithCharacters:self->content length:self->contentLength]; + if (self->content != NULL) { + free(self->content); + self->content = NULL; + } + return s; +} + +- (void)characters:(unichar *)_chars length:(int)_len { + if (_len == 0 || _chars == NULL) + return; + + if (self->content == NULL) { + /* first content */ + self->contentLength = _len; + self->content = calloc(_len + 1, sizeof(unichar)); + memcpy(self->content, _chars, (_len * sizeof(unichar))); + } + else { + /* increase content */ + self->content = + realloc(self->content, (self->contentLength + _len+2) * sizeof(unichar)); + memcpy(&(self->content[self->contentLength]), _chars, + (_len * sizeof(unichar))); + self->contentLength += _len; + } + self->content[self->contentLength] = 0; +} + +@end /* NGVCardSaxHandler */ diff --git a/sope-ical/NGiCal/NGVCardSimpleValue.m b/sope-ical/NGiCal/NGVCardSimpleValue.m new file mode 100644 index 00000000..f4505ecb --- /dev/null +++ b/sope-ical/NGiCal/NGVCardSimpleValue.m @@ -0,0 +1,64 @@ +/* + 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 "NGVCardValue.h" +#include "common.h" + +@implementation NGVCardSimpleValue + +- (void)dealloc { + [self->value release]; + [super dealloc]; +} + +/* values */ + +- (NSString *)stringValue { + return self->value; +} + +- (id)propertyList { + return [self stringValue]; +} + +/* fake being a string */ + +- (unichar)characterAtIndex:(unsigned)_idx { + return [self->value characterAtIndex:_idx]; +} +- (unsigned)length { + return [self->value length]; +} + +/* NSCoding */ + +- (void)encodeWithCoder:(NSCoder *)_coder { + [super encodeWithCoder:_coder]; + [_coder encodeObject:self->value]; +} +- (id)initWithCoder:(NSCoder *)_coder { + if ((self = [super initWithCoder:_coder]) != nil) { + self->value = [[_coder decodeObject] copy]; + } + return self; +} + +@end /* NGVCardSimpleValue */ diff --git a/sope-ical/NGiCal/NGVCardValue.h b/sope-ical/NGiCal/NGVCardValue.h new file mode 100644 index 00000000..bd5fbed9 --- /dev/null +++ b/sope-ical/NGiCal/NGVCardValue.h @@ -0,0 +1,97 @@ +/* + 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. +*/ + +#ifndef __NGiCal_NGVCardValue_H__ +#define __NGiCal_NGVCardValue_H__ + +#import + +/* + NGVCardValue + + Represents a value in a vCard object. + + Note: all NGVCardValue's are treated as immutable objects. + + - types + - arguments +*/ + +@class NSString, NSMutableString, NSArray, NSDictionary; + +@interface NGVCardValue : NSObject < NSCopying, NSCoding > +{ + NSString *group; + NSArray *types; + NSDictionary *arguments; +} + +/* accessors */ + +- (NSString *)group; +- (NSArray *)types; +- (NSDictionary *)arguments; +- (BOOL)isPreferred; + +/* values */ + +- (NSString *)stringValue; +- (NSString *)xmlString; +- (NSString *)vCardString; +- (id)propertyList; + +/* misc support methods */ + +- (void)appendXMLTag:(NSString *)_tag value:(NSString *)_val + to:(NSMutableString *)_ms; +- (void)appendVCardValue:(NSString *)_val to:(NSMutableString *)_ms; + +@end + +#import + +@interface NGVCardSimpleValue : NGVCardValue +{ + NSString *value; +} + +/* fake being an NSString */ + +- (unsigned int)length; +- (unichar)characterAtIndex:(unsigned)_idx; + +@end + +@interface NGVCardPhone : NGVCardSimpleValue +@end + +@interface NGVCardCategories : NGVCardValue +{ + NSArray *categories; +} + +/* accessors */ + +- (NSArray *)categories; + +@end + +#endif /* __NGiCal_NGVCardValue_H__ */ diff --git a/sope-ical/NGiCal/NGVCardValue.m b/sope-ical/NGiCal/NGVCardValue.m new file mode 100644 index 00000000..dd4457b9 --- /dev/null +++ b/sope-ical/NGiCal/NGVCardValue.m @@ -0,0 +1,111 @@ +/* + 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 "NGVCardValue.h" +#include +#include "common.h" + +@implementation NGVCardValue + +- (void)dealloc { + [self->group release]; + [self->types release]; + [self->arguments release]; + [super dealloc]; +} + +/* accessors */ + +- (NSString *)group { + return self->group; +} +- (NSArray *)types { + return self->types; +} +- (NSDictionary *)arguments { + return self->arguments; +} +- (BOOL)isPreferred { + return [self->types containsObject:@"PREF"]; +} + +/* values */ + +- (NSString *)stringValue { + [self logWithFormat:@"ERROR(%s): subclasses should override this method!", + __PRETTY_FUNCTION__]; + return nil; +} + +- (id)propertyList { + return [self stringValue]; +} + +- (NSString *)xmlString { + return [[self stringValue] stringByEscapingXMLString]; +} + +- (NSString *)vCardString { + // TODO: apply proper escaping + return [self stringValue]; +} + +/* misc support methods */ + +- (void)appendXMLTag:(NSString *)_tag value:(NSString *)_val + to:(NSMutableString *)_ms +{ + [_ms appendString:@"<"]; + [_ms appendString:_tag]; + [_ms appendString:@">"]; + if ([_val isNotNull]) [_ms appendString:[_val stringByEscapingXMLString]]; + [_ms appendString:@""]; +} + +- (void)appendVCardValue:(NSString *)_val to:(NSMutableString *)_ms { + // TODO: properly escape! + if ([_val isNotNull]) [_ms appendString:_val]; +} + +/* NSCopying */ + +- (id)copyWithZone:(NSZone *)_zone { + /* values are considered immutable */ + return [self retain]; +} + +/* NSCoding */ + +- (void)encodeWithCoder:(NSCoder *)_coder { + [_coder encodeObject:self->group]; + [_coder encodeObject:self->types]; + [_coder encodeObject:self->arguments]; +} +- (id)initWithCoder:(NSCoder *)_coder { + self->group = [[_coder decodeObject] copy]; + self->types = [[_coder decodeObject] copy]; + self->arguments = [[_coder decodeObject] copy]; + return self; +} + +@end /* NGVCardValue */ diff --git a/sope-ical/NGiCal/Version b/sope-ical/NGiCal/Version index c7038352..3a758962 100644 --- a/sope-ical/NGiCal/Version +++ b/sope-ical/NGiCal/Version @@ -2,7 +2,7 @@ MAJOR_VERSION=4 MINOR_VERSION=5 -SUBMINOR_VERSION:=51 +SUBMINOR_VERSION:=52 # v4.5.40 requires NGExtensions v4.5.145 # v4.5.37 requires NGExtensions v4.5.140 diff --git a/sope-ical/data/apple-fullrecord.vcf b/sope-ical/data/apple-fullrecord.vcf new file mode 100644 index 00000000..1365454d --- /dev/null +++ b/sope-ical/data/apple-fullrecord.vcf @@ -0,0 +1,64 @@ +BEGIN:VCARD +VERSION:3.0 +N:Duck (AB);Dagobert;Middle;Mr.;1st +FN:Mr. Dagobert Middle Duck (AB) 1st +NICKNAME:duggy +X-MAIDENNAME:DuckyMaiden +ORG:Geldspeicher AG;Board +TITLE:Chief +EMAIL;type=INTERNET;type=WORK;type=pref:dd@entenhausen.com +EMAIL;type=INTERNET;type=HOME:dd@entenhausen.home +item1.EMAIL;type=INTERNET:dd@custom.org +item1.X-ABLabel:CustLab +TEL;type=WORK;type=pref:0123-123456789 +TEL;type=CELL:0172-2736152 +TEL;type=HOME;type=FAX:(012) 398-7654 +item2.TEL:(281) 727-3721 +item2.X-ABLabel:PhoCust +item3.ADR;type=WORK;type=pref:;;WorkStreet;Entenhausen (Work);WorkState;WorkZIP;WorkCountry +item3.X-ABADR:us +item4.ADR;type=HOME:;;HomeStreet;Entenhausen (Home);;HomeZip;HomeCountry +item4.X-ABADR:de +item5.URL;type=pref:http\://www.entenhausen.com +item5.X-ABLabel:_$!!$_ +item6.URL:http\://secondhomepage.com +item6.X-ABLabel:_$!!$_ +BDAY;value=date:2005-03-12 +X-AIM;type=WORK;type=pref:aimname +X-JABBER;type=HOME;type=pref:jab@jab.not +X-JABBER;type=WORK:jab2@jab.not +X-MSN;type=WORK;type=pref:msn@ms.com +X-YAHOO;type=HOME;type=pref:yahoo +X-ICQ;type=HOME;type=pref:78371672 +item7.X-ABDATE;type=pref:2005-02-03 +item7.X-ABLabel:_$!!$_ +item8.X-ABDATE:1987-02-02 +item8.X-ABLabel:CustDate +item9.X-ABRELATEDNAMES;type=pref:mickey +item9.X-ABLabel:_$!!$_ +item10.X-ABRELATEDNAMES:donald +item10.X-ABLabel:_$!!$_ +item11.X-ABRELATEDNAMES:dagopop +item11.X-ABLabel:_$!!$_ +item12.X-ABRELATEDNAMES:dagomom +item12.X-ABLabel:_$!!$_ +item13.X-ABRELATEDNAMES:dagoparent +item13.X-ABLabel:_$!!$_ +item14.X-ABRELATEDNAMES:dagobroth +item14.X-ABLabel:_$!!$_ +item15.X-ABRELATEDNAMES:dagosis +item15.X-ABLabel:_$!!$_ +item16.X-ABRELATEDNAMES:dagochild1 +item16.X-ABLabel:_$!!$_ +item17.X-ABRELATEDNAMES:dagochild2 +item17.X-ABLabel:_$!!$_ +item18.X-ABRELATEDNAMES:Guntel +item18.X-ABLabel:_$!!$_ +item19.X-ABRELATEDNAMES:Guntel\, Minney +item19.X-ABLabel:_$!!$_ +item20.X-ABRELATEDNAMES:NoManager +item20.X-ABLabel:_$!!$_ +item21.X-ABRELATEDNAMES:OtherName +item21.X-ABLabel:_$!!$_ +X-ABUID:6BEA0FDE-005A-4F85-83F1-16C98A142ABF\:ABPerson +END:VCARD diff --git a/sope-ical/samples/GNUmakefile b/sope-ical/samples/GNUmakefile index bdcfa5f7..e26d78bd 100644 --- a/sope-ical/samples/GNUmakefile +++ b/sope-ical/samples/GNUmakefile @@ -9,7 +9,7 @@ icalparsetest_OBJC_FILES = icalparsetest.m icalds_OBJC_FILES = icalds.m vcf2xml_OBJC_FILES = vcf2xml.m -icalparsetest_TOOL_LIBS += -lNGiCal -lSaxObjC +icalparsetest_TOOL_LIBS += -lNGiCal -lSaxObjC icalds_TOOL_LIBS += -lNGiCal -lSaxObjC vcf2xml_TOOL_LIBS += -lSaxObjC diff --git a/sope-ical/versitSaxDriver/VSSaxDriver.m b/sope-ical/versitSaxDriver/VSSaxDriver.m index 4f0881be..a82e1abd 100644 --- a/sope-ical/versitSaxDriver/VSSaxDriver.m +++ b/sope-ical/versitSaxDriver/VSSaxDriver.m @@ -381,8 +381,8 @@ static VSStringFormatter *stringFormatter = nil; if (_attrs == nil || [_attrs count] == 0) return nil; - - attributes = [[NSMutableDictionary alloc] init]; + + attributes = [[NSMutableDictionary alloc] initWithCapacity:4]; retAttrs = [[[SaxAttributes alloc] init] autorelease]; attrEnum = [_attrs objectEnumerator]; @@ -391,11 +391,14 @@ static VSStringFormatter *stringFormatter = nil; forTag:_tagName intoAttr:&mappedAttr intoValue:&mappedValue]; - if ((oldValue = [attributes objectForKey:mappedAttr])) { + if ((oldValue = [attributes objectForKey:mappedAttr]) != nil) { NSString *val; + /* ZNeK: duh! */ - val = [NSString stringWithFormat:@"%@ %@",oldValue, mappedValue]; + // TODO: hh asks: what does 'duh' is supposed to mean? + val = [[NSString alloc] initWithFormat:@"%@ %@",oldValue, mappedValue]; [attributes setObject:val forKey:mappedAttr]; + [val release]; } else [attributes setObject:mappedValue forKey:mappedAttr]; @@ -403,6 +406,16 @@ static VSStringFormatter *stringFormatter = nil; attrEnum = [attributes keyEnumerator]; while ((curAttr = [attrEnum nextObject]) != nil) { + /* + TODO: values are not always mapped to CDATA! Eg in the dawson draft: + | TYPE for TEL | tel.type | NMTOKENS | 'VOICE' | + | TYPE for EMAIL | email.type | NMTOKENS | 'INTERNET' | + | TYPE for PHOTO,| img.type | CDATA | REQUIRED | + | and LOGO | | | | + | TYPE for SOUND | aud.type | CDATA | REQUIRED | + | VALUE | value | NOTATION | See elements | + */ + [retAttrs addAttribute:curAttr uri:self->prefixURI rawName:curAttr type:@"CDATA" value:[attributes objectForKey:curAttr]]; }