2 Copyright (C) 2003-2004 Max Berger
3 Copyright (C) 2004 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 @implementation VSvCardSaxDriver
29 static NSSet *defElementNames = nil;
32 static BOOL didInit = NO;
38 defElementNames = [[NSSet alloc] initWithObjects:
47 + (NSDictionary *)xcardMapping {
48 static NSDictionary *dict = nil;
50 NSMutableDictionary *xcard;
52 xcard = [[NSMutableDictionary alloc] initWithCapacity:30];
54 [xcard setObject:@"vCard" forKey:@"VCARD"];
57 +----------------+------------+------------+----------------+
58 | Type | Attribute | Attribute | Default |
59 | Name | Name | Type | Value |
60 +----------------+------------+------------+----------------+
61 | CLASS | class | enumerated | 'PUBLIC' |
62 | PRODID | prodid | CDATA | IMPLIED |
63 | REV | rev | CDATA | IMPLIED |
64 | UID | uid | CDATA | IMPLIED |
65 | VERSION | version | CDATA | IMPLIED |
66 +----------------+------------+------------+----------------+
68 [xcard setObject:@"class" forKey:@"CLASS"];
69 [xcard setObject:@"prodid" forKey:@"PRODID"];
70 [xcard setObject:@"rev" forKey:@"REV"];
71 [xcard setObject:@"uid" forKey:@"UID"];
72 [xcard setObject:@"version" forKey:@"VERSION"];
77 +----------------+------------+-----------------------------+
78 | vCard | Element | Element Content Model |
79 | Type Name | Name | |
80 +----------------+------------+-----------------------------+
82 | N | n | family*,given*,other*, |
83 | | | prefix*, suffix* |
89 | NICKNAME | nickname | PCDATA |
90 | PHOTO | photo | extref or b64bin |
93 | BDAY | bday | PCDATA |
94 +----------------+------------+-----------------------------+
96 [xcard setObject:@"fn" forKey:@"FN"];
97 [xcard setObject:@"n" forKey:@"N"];
98 [xcard setObject:@"nickname" forKey:@"NICKNAME"];
99 [xcard setObject:@"photo" forKey:@"PHOTO"];
100 [xcard setObject:@"bday" forKey:@"BDAY"];
104 Delivery Addressing Types
105 +----------------+------------+-----------------------------+
106 | vCard | Element | Element Content Model |
107 | Type Name | Name | |
108 +----------------+------------+-----------------------------+
109 | ADR | adr | pobox*,extadd*,street*, |
110 | | | locality*,region*,pcode*, |
113 | | extadd | PCDATA |
114 | | street | PCDATA |
115 | | locality | PCDATA |
116 | | region | PCDATA |
118 | | country | PCDATA |
119 | LABEL | LABEL | PCDATA |
120 +----------------+------------+-----------------------------+
122 [xcard setObject:@"adr" forKey:@"ADR"];
123 [xcard setObject:@"LABEL" forKey:@"LABEL"];
126 Telecommunications Addressing Types
127 +----------------+------------+-----------------------------+
128 | vCard | Element | Element Content Model |
129 | Type Name | Name | |
130 +----------------+------------+-----------------------------+
131 | TEL | tel | PCDATA |
132 | EMAIL | email | PCDATA |
133 | MAILER | mailer | PCDATA |
134 +----------------+------------+-----------------------------+
136 [xcard setObject:@"tel" forKey:@"TEL"];
137 [xcard setObject:@"email" forKey:@"EMAIL"];
138 [xcard setObject:@"mailer" forKey:@"MAILER"];
142 +----------------+------------+-----------------------------+
143 | vCard | Element | Element Content Model |
144 | Type Name | Name | |
145 +----------------+------------+-----------------------------+
147 | GEO | geo | lat,lon |
150 +----------------+------------+-----------------------------+
152 [xcard setObject:@"tz" forKey:@"TZ"];
153 [xcard setObject:@"geo" forKey:@"GEO"];
157 +----------------+------------+-----------------------------+
158 | vCard | Element | Element Content Model |
159 | Type Name | Name | |
160 +----------------+------------+-----------------------------+
161 | TITLE | title | PCDATA |
162 | ROLE | role | PCDATA |
163 | LOGO | logo | extref or b64bin |
165 | | b64bin | PCDATA |
166 | AGENT | agent | vCard | extref |
167 | ORG | org | orgnam,orgunit* |
168 | | orgnam | PCDATA |
170 +----------------+------------+-----------------------------+
172 [xcard setObject:@"title" forKey:@"TITLE"];
173 [xcard setObject:@"role" forKey:@"ROLE"];
174 [xcard setObject:@"logo" forKey:@"LOGO"];
175 [xcard setObject:@"agent" forKey:@"AGENT"];
176 [xcard setObject:@"org" forKey:@"ORG"];
180 +----------------+------------+-----------------------------+
181 | vCard | Element | Element Content Model |
182 | Type Name | Name | |
183 +----------------+------------+-----------------------------+
184 | CATEGORIES | categories | item* |
186 | NOTE | note | PCDATA |
187 | SORT-STRING | sort | PCDATA |
188 | SOUND | sound | extref | b64bin |
190 | | b64bin | PCDATA |
191 | URL | url | PCDATA |
192 | URI | uri | PCDATA |
193 +----------------+------------+-----------------------------+
195 [xcard setObject:@"categories" forKey:@"CATEGORIES"];
196 [xcard setObject:@"note" forKey:@"NOTE"];
197 [xcard setObject:@"sort" forKey:@"SORT-STRING"];
198 [xcard setObject:@"sound" forKey:@"SOUND"];
199 [xcard setObject:@"url" forKey:@"URL"];
200 [xcard setObject:@"uri" forKey:@"URI"];
204 +----------------+------------+-----------------------------+
205 | vCard | Element | Element Content Model |
206 | Type Name | Name | |
207 +----------------+------------+-----------------------------+
208 | KEY | key | extref | b64bin |
210 | | b64bin | PCDATA |
211 +----------------+------------+-----------------------------+
213 [xcard setObject:@"key" forKey:@"KEY"];
221 - (void)_setVCardAttributeMappings {
223 +----------------+------------+-----------+-----------------+
224 | Type | Attribute | Attribute | Default |
225 | Parameter Name | Name | Type | Value |
226 +----------------+------------+-----------+-----------------+
227 | ENCODING | Not Used | n/a | n/a |
228 | LANGUAGE | lang | CDATA | IMPLIED |
229 | TYPE for ADR | del.type | NMTOKENS | 'INTL POSTAL |
230 | and LABEL | | | PARCEL WORK' |
231 | TYPE for TEL | tel.type | NMTOKENS | 'VOICE' |
232 | TYPE for EMAIL | email.type | NMTOKENS | 'INTERNET' |
233 | TYPE for PHOTO,| img.type | CDATA | REQUIRED |
235 | TYPE for SOUND | aud.type | CDATA | REQUIRED |
236 | VALUE | value | NOTATION | See elements |
237 +----------------+------------+-----------+-----------------+
239 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2];
241 [dict setObject:@"lang" forKey:@"LANGUAGE"];
242 [dict setObject:@"value" forKey:@"VALUE"];
243 [self setAttributeMapping:dict];
246 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
247 [dict setObject:@"del.type" forKey:@"TYPE"];
248 [self setAttributeMapping:dict forElement:@"ADR"];
249 [self setAttributeMapping:dict forElement:@"LABEL"];
252 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
253 [dict setObject:@"tel.type" forKey:@"TYPE"];
254 [self setAttributeMapping:dict forElement:@"TEL"];
257 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
258 [dict setObject:@"email.type" forKey:@"TYPE"];
259 [self setAttributeMapping:dict forElement:@"EMAIL"];
262 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
263 [dict setObject:@"img.type" forKey:@"TYPE"];
264 [self setAttributeMapping:dict forElement:@"PHOTO"];
265 [self setAttributeMapping:dict forElement:@"LOGO"];
268 dict = [[NSMutableDictionary alloc] initWithCapacity:1];
269 [dict setObject:@"aud.type" forKey:@"TYPE"];
270 [self setAttributeMapping:dict forElement:@"SOUND"];
274 - (void)_setVCardSubItemMappings {
277 a = [NSArray arrayWithObjects:
284 [self setSubItemMapping:a forElement:@"n"];
286 a = [NSArray arrayWithObjects:
295 [self setSubItemMapping:a forElement:@"adr"];
297 a = [NSArray arrayWithObjects:
301 [self setSubItemMapping:a forElement:@"geo"];
303 a = [NSArray arrayWithObjects:
307 [self setSubItemMapping:a forElement:@"org"];
311 if ((self = [super init])) {
313 [self setPrefixURI:@"http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt"];
314 [self setElementMapping:[[self class] xcardMapping]];
315 [self setAttributeElements:defElementNames];
316 [self _setVCardAttributeMappings];
317 [self _setVCardSubItemMappings];
322 @end /* VCardSaxDriver */