2 Copyright (C) 2003-2004 Max Berger
3 Copyright (C) 2004-2005 OpenGroupware.org
5 This file is part of versitSaxDriver, written for the OpenGroupware.org
8 SOPE is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with SOPE; see the file COPYING. If not, write to the
20 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "VSvCardSaxDriver.h"
27 #define XMLNS_VSvCard \
28 @"http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt"
30 @implementation VSvCardSaxDriver
32 static NSSet *defElementNames = nil;
35 static BOOL didInit = NO;
41 defElementNames = [[NSSet alloc] initWithObjects:
42 @"class", @"prodid", @"rev", @"uid", @"version", nil];
45 + (NSDictionary *)xcardMapping {
46 static NSDictionary *dict = nil;
48 NSMutableDictionary *xcard;
50 xcard = [[NSMutableDictionary alloc] initWithCapacity:30];
52 [xcard setObject:@"vCard" forKey:@"VCARD"];
55 +----------------+------------+------------+----------------+
56 | Type | Attribute | Attribute | Default |
57 | Name | Name | Type | Value |
58 +----------------+------------+------------+----------------+
59 | CLASS | class | enumerated | 'PUBLIC' |
60 | PRODID | prodid | CDATA | IMPLIED |
61 | REV | rev | CDATA | IMPLIED |
62 | UID | uid | CDATA | IMPLIED |
63 | VERSION | version | CDATA | IMPLIED |
64 +----------------+------------+------------+----------------+
66 [xcard setObject:@"class" forKey:@"CLASS"];
67 [xcard setObject:@"prodid" forKey:@"PRODID"];
68 [xcard setObject:@"rev" forKey:@"REV"];
69 [xcard setObject:@"uid" forKey:@"UID"];
70 [xcard setObject:@"version" forKey:@"VERSION"];
75 +----------------+------------+-----------------------------+
76 | vCard | Element | Element Content Model |
77 | Type Name | Name | |
78 +----------------+------------+-----------------------------+
80 | N | n | family*,given*,other*, |
81 | | | prefix*, suffix* |
87 | NICKNAME | nickname | PCDATA |
88 | PHOTO | photo | extref or b64bin |
91 | BDAY | bday | PCDATA |
92 +----------------+------------+-----------------------------+
94 [xcard setObject:@"fn" forKey:@"FN"];
95 [xcard setObject:@"n" forKey:@"N"];
96 [xcard setObject:@"nickname" forKey:@"NICKNAME"];
97 [xcard setObject:@"photo" forKey:@"PHOTO"];
98 [xcard setObject:@"bday" forKey:@"BDAY"];
102 Delivery Addressing Types
103 +----------------+------------+-----------------------------+
104 | vCard | Element | Element Content Model |
105 | Type Name | Name | |
106 +----------------+------------+-----------------------------+
107 | ADR | adr | pobox*,extadd*,street*, |
108 | | | locality*,region*,pcode*, |
111 | | extadd | PCDATA |
112 | | street | PCDATA |
113 | | locality | PCDATA |
114 | | region | PCDATA |
116 | | country | PCDATA |
117 | LABEL | LABEL | PCDATA |
118 +----------------+------------+-----------------------------+
120 [xcard setObject:@"adr" forKey:@"ADR"];
121 [xcard setObject:@"LABEL" forKey:@"LABEL"];
124 Telecommunications Addressing Types
125 +----------------+------------+-----------------------------+
126 | vCard | Element | Element Content Model |
127 | Type Name | Name | |
128 +----------------+------------+-----------------------------+
129 | TEL | tel | PCDATA |
130 | EMAIL | email | PCDATA |
131 | MAILER | mailer | PCDATA |
132 +----------------+------------+-----------------------------+
134 [xcard setObject:@"tel" forKey:@"TEL"];
135 [xcard setObject:@"email" forKey:@"EMAIL"];
136 [xcard setObject:@"mailer" forKey:@"MAILER"];
140 +----------------+------------+-----------------------------+
141 | vCard | Element | Element Content Model |
142 | Type Name | Name | |
143 +----------------+------------+-----------------------------+
145 | GEO | geo | lat,lon |
148 +----------------+------------+-----------------------------+
150 [xcard setObject:@"tz" forKey:@"TZ"];
151 [xcard setObject:@"geo" forKey:@"GEO"];
155 +----------------+------------+-----------------------------+
156 | vCard | Element | Element Content Model |
157 | Type Name | Name | |
158 +----------------+------------+-----------------------------+
159 | TITLE | title | PCDATA |
160 | ROLE | role | PCDATA |
161 | LOGO | logo | extref or b64bin |
163 | | b64bin | PCDATA |
164 | AGENT | agent | vCard | extref |
165 | ORG | org | orgnam,orgunit* |
166 | | orgnam | PCDATA |
168 +----------------+------------+-----------------------------+
170 [xcard setObject:@"title" forKey:@"TITLE"];
171 [xcard setObject:@"role" forKey:@"ROLE"];
172 [xcard setObject:@"logo" forKey:@"LOGO"];
173 [xcard setObject:@"agent" forKey:@"AGENT"];
174 [xcard setObject:@"org" forKey:@"ORG"];
178 +----------------+------------+-----------------------------+
179 | vCard | Element | Element Content Model |
180 | Type Name | Name | |
181 +----------------+------------+-----------------------------+
182 | CATEGORIES | categories | item* |
184 | NOTE | note | PCDATA |
185 | SORT-STRING | sort | PCDATA |
186 | SOUND | sound | extref | b64bin |
188 | | b64bin | PCDATA |
189 | URL | url | PCDATA |
190 | URI | uri | PCDATA |
191 +----------------+------------+-----------------------------+
193 [xcard setObject:@"categories" forKey:@"CATEGORIES"];
194 [xcard setObject:@"note" forKey:@"NOTE"];
195 [xcard setObject:@"sort" forKey:@"SORT-STRING"];
196 [xcard setObject:@"sound" forKey:@"SOUND"];
197 [xcard setObject:@"url" forKey:@"URL"];
198 [xcard setObject:@"uri" forKey:@"URI"];
202 +----------------+------------+-----------------------------+
203 | vCard | Element | Element Content Model |
204 | Type Name | Name | |
205 +----------------+------------+-----------------------------+
206 | KEY | key | extref | b64bin |
208 | | b64bin | PCDATA |
209 +----------------+------------+-----------------------------+
211 [xcard setObject:@"key" forKey:@"KEY"];
219 - (void)_setVCardAttributeMappings {
221 +----------------+------------+-----------+-----------------+
222 | Type | Attribute | Attribute | Default |
223 | Parameter Name | Name | Type | Value |
224 +----------------+------------+-----------+-----------------+
225 | ENCODING | Not Used | n/a | n/a |
226 | LANGUAGE | lang | CDATA | IMPLIED |
227 | TYPE for ADR | del.type | NMTOKENS | 'INTL POSTAL |
228 | and LABEL | | | PARCEL WORK' |
229 | TYPE for TEL | tel.type | NMTOKENS | 'VOICE' |
230 | TYPE for EMAIL | email.type | NMTOKENS | 'INTERNET' |
231 | TYPE for PHOTO,| img.type | CDATA | REQUIRED |
233 | TYPE for SOUND | aud.type | CDATA | REQUIRED |
234 | VALUE | value | NOTATION | See elements |
235 +----------------+------------+-----------+-----------------+
237 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2];
239 [dict setObject:@"lang" forKey:@"LANGUAGE"];
240 [dict setObject:@"value" forKey:@"VALUE"];
241 [self setAttributeMapping:dict];
244 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
245 [dict setObject:@"del.type" forKey:@"TYPE"];
246 [self setAttributeMapping:dict forElement:@"ADR"];
247 [self setAttributeMapping:dict forElement:@"LABEL"];
250 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
251 [dict setObject:@"tel.type" forKey:@"TYPE"];
252 [self setAttributeMapping:dict forElement:@"TEL"];
255 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
256 [dict setObject:@"email.type" forKey:@"TYPE"];
257 [self setAttributeMapping:dict forElement:@"EMAIL"];
260 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
261 [dict setObject:@"img.type" forKey:@"TYPE"];
262 [self setAttributeMapping:dict forElement:@"PHOTO"];
263 [self setAttributeMapping:dict forElement:@"LOGO"];
266 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
267 [dict setObject:@"aud.type" forKey:@"TYPE"];
268 [self setAttributeMapping:dict forElement:@"SOUND"];
272 - (void)_setVCardSubItemMappings {
275 a = [NSArray arrayWithObjects:
282 [self setSubItemMapping:a forElement:@"n"];
284 a = [NSArray arrayWithObjects:
293 [self setSubItemMapping:a forElement:@"adr"];
295 a = [NSArray arrayWithObjects:
299 [self setSubItemMapping:a forElement:@"geo"];
301 a = [NSArray arrayWithObjects:
305 [self setSubItemMapping:a forElement:@"org"];
309 if ((self = [super init]) != nil) {
310 [self setPrefixURI:XMLNS_VSvCard];
311 [self setElementMapping:[[self class] xcardMapping]];
312 [self setAttributeElements:defElementNames];
313 [self _setVCardAttributeMappings];
314 [self _setVCardSubItemMappings];
319 /* top level parsing method */
321 - (void)reportDocStart {
322 [super reportDocStart];
324 [self->contentHandler startElement:@"vCardSet" namespace:self->prefixURI
325 rawName:@"vCardSet" attributes:nil];
327 - (void)reportDocEnd {
328 [self->contentHandler endElement:@"vCardSet" namespace:self->prefixURI
329 rawName:@"vCardSet"];
331 [super reportDocEnd];
334 @end /* VCardSaxDriver */