2 Copyright (C) 2005 Helge Hess
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "NGVCardSaxHandler.h"
24 #include "NGVCardStrArrayValue.h"
25 #include "NGVCardName.h"
26 #include "NGVCardOrg.h"
27 #include <SaxObjC/SaxXMLReader.h>
28 #include <SaxObjC/SaxXMLReaderFactory.h>
31 @implementation NGVCard
33 static id<NSObject,SaxXMLReader> parser = nil; // THREAD
34 static NGVCardSaxHandler *sax = nil; // THREAD
36 + (id<NSObject,SaxXMLReader>)vCardParser {
38 sax = [[NGVCardSaxHandler alloc] init];
42 [[[SaxXMLReaderFactory standardXMLReaderFactory]
43 createXMLReaderForMimeType:@"text/x-vcard"]
46 NSLog(@"%s: did not find a parser for text/x-vcard !",
51 [parser setContentHandler:sax];
52 [parser setErrorHandler:sax];
58 + (NSArray *)parseVCardsFromSource:(id)_src {
59 static id<NSObject,SaxXMLReader> parser;
61 if ((parser = [self vCardParser]) == nil)
64 [parser parseFromSource:_src];
68 - (id)initWithUid:(NSString *)_uid version:(NSString *)_version {
69 if ((self = [super init]) != nil) {
70 self->uid = [_uid copy];
71 self->version = [_version copy];
76 return [self initWithUid:nil version:@"3.0"];
82 [self->nickname release];
83 [self->categories release];
84 [self->caluri release];
85 [self->fburl release];
88 [self->title release];
91 [self->vClass release];
92 [self->prodID release];
97 [self->email release];
98 [self->label release];
99 [self->version release];
106 - (NSString *)version {
107 return self->version;
110 - (void)setUid:(NSString *)_uid {
111 ASSIGNCOPY(self->uid, _uid);
117 - (void)setVClass:(NSString *)_vClass {
118 ASSIGNCOPY(self->vClass, _vClass);
120 - (NSString *)vClass {
124 - (void)setProdID:(NSString *)_prodID {
125 ASSIGNCOPY(self->prodID, _prodID);
127 - (NSString *)prodID {
131 - (void)setFn:(NSString *)_fn {
132 ASSIGNCOPY(self->fn, _fn);
138 - (void)setRole:(NSString *)_role {
139 ASSIGNCOPY(self->role, _role);
145 - (void)setTitle:(NSString *)_title {
146 ASSIGNCOPY(self->title, _title);
148 - (NSString *)title {
152 - (void)setBday:(NSString *)_bday {
153 ASSIGNCOPY(self->bday, _bday);
159 - (void)setNote:(NSString *)_note {
160 ASSIGNCOPY(self->note, _note);
167 - (void)setN:(NGVCardName *)_v {
168 ASSIGNCOPY(self->n, _v);
174 - (void)setOrg:(NGVCardOrg *)_v {
175 ASSIGNCOPY(self->org, _v);
177 - (NGVCardOrg *)org {
182 - (void)setNickname:(id)_v {
183 if (![_v isKindOfClass:[NGVCardStrArrayValue class]] && [_v isNotNull])
184 _v = [[[NGVCardStrArrayValue alloc] initWithPropertyList:_v] autorelease];
186 ASSIGNCOPY(self->nickname, _v);
188 - (NGVCardStrArrayValue *)nickname {
189 return self->nickname;
192 - (void)setCategories:(id)_v {
193 if (![_v isKindOfClass:[NGVCardStrArrayValue class]] && [_v isNotNull])
194 _v = [[[NGVCardStrArrayValue alloc] initWithPropertyList:_v] autorelease];
196 ASSIGNCOPY(self->categories, _v);
198 - (NGVCardStrArrayValue *)categories {
199 return self->categories;
203 - (void)setTel:(NSArray *)_tel {
204 ASSIGNCOPY(self->tel, _tel);
210 - (void)setAdr:(NSArray *)_adr {
211 ASSIGNCOPY(self->adr, _adr);
217 - (void)setEmail:(NSArray *)_email {
218 ASSIGNCOPY(self->email, _email);
224 - (void)setLabel:(NSArray *)_label {
225 ASSIGNCOPY(self->label, _label);
231 - (void)setUrl:(NSArray *)_url {
232 ASSIGNCOPY(self->url, _url);
239 - (void)setFreeBusyURL:(NSArray *)_v {
240 ASSIGNCOPY(self->fburl, _v);
242 - (NSArray *)freeBusyURL {
245 - (void)setCalURI:(NSArray *)_v {
246 ASSIGNCOPY(self->caluri, _v);
248 - (NSArray *)calURI {
253 - (void)setX:(NSDictionary *)_dict {
254 ASSIGNCOPY(self->x, _dict);
256 - (NSDictionary *)x {
262 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
263 if (self->uid != nil) [_ms appendFormat:@" uid='%@'", self->uid];
265 if ([self->tel count] > 0) [_ms appendFormat:@" tel=%@", self->tel];
266 if ([self->adr count] > 0) [_ms appendFormat:@" adr=%@", self->adr];
267 if ([self->email count] > 0) [_ms appendFormat:@" email=%@", self->email];
268 if ([self->label count] > 0) [_ms appendFormat:@" label=%@", self->label];
269 if ([self->x count] > 0) [_ms appendFormat:@" x=%@", self->x];
272 - (NSString *)description {
273 NSMutableString *str = nil;
275 str = [NSMutableString stringWithCapacity:64];
276 [str appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
277 [self appendAttributesToDescription:str];
278 [str appendString:@">"];