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 <SaxObjC/SaxXMLReader.h>
25 #include <SaxObjC/SaxXMLReaderFactory.h>
28 @implementation NGVCard
30 static id<NSObject,SaxXMLReader> parser = nil; // THREAD
31 static NGVCardSaxHandler *sax = nil; // THREAD
33 + (id<NSObject,SaxXMLReader>)vCardParser {
35 sax = [[NGVCardSaxHandler alloc] init];
39 [[[SaxXMLReaderFactory standardXMLReaderFactory]
40 createXMLReaderForMimeType:@"text/x-vcard"]
43 NSLog(@"%s: did not find a parser for text/x-vcard !",
48 [parser setContentHandler:sax];
49 [parser setErrorHandler:sax];
55 + (NSArray *)parseVCardsFromSource:(id)_src {
56 static id<NSObject,SaxXMLReader> parser;
58 if ((parser = [self vCardParser]) == nil)
61 [parser parseFromSource:_src];
65 - (id)initWithUid:(NSString *)_uid version:(NSString *)_version {
66 if ((self = [super init]) != nil) {
67 self->uid = [_uid copy];
68 self->version = [_version copy];
73 return [self initWithUid:nil version:@"3.0"];
77 [self->vClass release];
78 [self->prodID release];
82 [self->email release];
83 [self->label release];
84 [self->version release];
91 - (NSString *)version {
95 - (void)setUid:(NSString *)_uid {
96 ASSIGNCOPY(self->uid, _uid);
102 - (void)setVClass:(NSString *)_vClass {
103 ASSIGNCOPY(self->vClass, _vClass);
105 - (NSString *)vClass {
109 - (void)setProdID:(NSString *)_prodID {
110 ASSIGNCOPY(self->prodID, _prodID);
112 - (NSString *)prodID {
116 - (void)setTel:(NSArray *)_tel {
117 ASSIGNCOPY(self->tel, _tel);
123 - (void)setAdr:(NSArray *)_adr {
124 ASSIGNCOPY(self->adr, _adr);
130 - (void)setEmail:(NSArray *)_email {
131 ASSIGNCOPY(self->email, _email);
137 - (void)setLabel:(NSArray *)_label {
138 ASSIGNCOPY(self->label, _label);
144 - (void)setX:(NSDictionary *)_dict {
145 ASSIGNCOPY(self->x, _dict);
147 - (NSDictionary *)x {
153 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
154 if (self->uid != nil) [_ms appendFormat:@" uid='%@'", self->uid];
156 if ([self->tel count] > 0) [_ms appendFormat:@" tel=%@", self->tel];
157 if ([self->adr count] > 0) [_ms appendFormat:@" adr=%@", self->adr];
158 if ([self->email count] > 0) [_ms appendFormat:@" email=%@", self->email];
159 if ([self->label count] > 0) [_ms appendFormat:@" label=%@", self->label];
160 if ([self->x count] > 0) [_ms appendFormat:@" x=%@", self->x];
163 - (NSString *)description {
164 NSMutableString *str = nil;
166 str = [NSMutableString stringWithCapacity:64];
167 [str appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
168 [self appendAttributesToDescription:str];
169 [str appendString:@">"];