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
#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:
50
+ (NSDictionary *)xcardMapping {
51
static NSDictionary *dict = nil;
53
NSMutableDictionary *xcard;
55
xcard = [[NSMutableDictionary alloc] initWithCapacity:30];
57
[xcard setObject:@"vCard" forKey:@"VCARD"];
60
+----------------+------------+------------+----------------+
61
| Type | Attribute | Attribute | Default |
62
| Name | Name | Type | Value |
63
+----------------+------------+------------+----------------+
64
| CLASS | class | enumerated | 'PUBLIC' |
65
| PRODID | prodid | CDATA | IMPLIED |
66
| REV | rev | CDATA | IMPLIED |
67
| UID | uid | CDATA | IMPLIED |
68
| VERSION | version | CDATA | IMPLIED |
69
+----------------+------------+------------+----------------+
71
[xcard setObject:@"class" forKey:@"CLASS"];
72
[xcard setObject:@"prodid" forKey:@"PRODID"];
73
[xcard setObject:@"rev" forKey:@"REV"];
74
[xcard setObject:@"uid" forKey:@"UID"];
75
[xcard setObject:@"version" forKey:@"VERSION"];
80
+----------------+------------+-----------------------------+
81
| vCard | Element | Element Content Model |
82
| Type Name | Name | |
83
+----------------+------------+-----------------------------+
85
| N | n | family*,given*,other*, |
86
| | | prefix*, suffix* |
92
| NICKNAME | nickname | PCDATA |
93
| PHOTO | photo | extref or b64bin |
96
| BDAY | bday | PCDATA |
97
+----------------+------------+-----------------------------+
99
[xcard setObject:@"fn" forKey:@"FN"];
100
[xcard setObject:@"n" forKey:@"N"];
101
[xcard setObject:@"nickname" forKey:@"NICKNAME"];
102
[xcard setObject:@"photo" forKey:@"PHOTO"];
103
[xcard setObject:@"bday" forKey:@"BDAY"];
107
Delivery Addressing Types
108
+----------------+------------+-----------------------------+
109
| vCard | Element | Element Content Model |
110
| Type Name | Name | |
111
+----------------+------------+-----------------------------+
112
| ADR | adr | pobox*,extadd*,street*, |
113
| | | locality*,region*,pcode*, |
116
| | extadd | PCDATA |
117
| | street | PCDATA |
118
| | locality | PCDATA |
119
| | region | PCDATA |
121
| | country | PCDATA |
122
| LABEL | LABEL | PCDATA |
123
+----------------+------------+-----------------------------+
125
[xcard setObject:@"adr" forKey:@"ADR"];
126
[xcard setObject:@"LABEL" forKey:@"LABEL"];
129
Telecommunications Addressing Types
130
+----------------+------------+-----------------------------+
131
| vCard | Element | Element Content Model |
132
| Type Name | Name | |
133
+----------------+------------+-----------------------------+
134
| TEL | tel | PCDATA |
135
| EMAIL | email | PCDATA |
136
| MAILER | mailer | PCDATA |
137
+----------------+------------+-----------------------------+
139
[xcard setObject:@"tel" forKey:@"TEL"];
140
[xcard setObject:@"email" forKey:@"EMAIL"];
141
[xcard setObject:@"mailer" forKey:@"MAILER"];
145
+----------------+------------+-----------------------------+
146
| vCard | Element | Element Content Model |
147
| Type Name | Name | |
148
+----------------+------------+-----------------------------+
150
| GEO | geo | lat,lon |
153
+----------------+------------+-----------------------------+
155
[xcard setObject:@"tz" forKey:@"TZ"];
156
[xcard setObject:@"geo" forKey:@"GEO"];
160
+----------------+------------+-----------------------------+
161
| vCard | Element | Element Content Model |
162
| Type Name | Name | |
163
+----------------+------------+-----------------------------+
164
| TITLE | title | PCDATA |
165
| ROLE | role | PCDATA |
166
| LOGO | logo | extref or b64bin |
168
| | b64bin | PCDATA |
169
| AGENT | agent | vCard | extref |
170
| ORG | org | orgnam,orgunit* |
171
| | orgnam | PCDATA |
173
+----------------+------------+-----------------------------+
175
[xcard setObject:@"title" forKey:@"TITLE"];
176
[xcard setObject:@"role" forKey:@"ROLE"];
177
[xcard setObject:@"logo" forKey:@"LOGO"];
178
[xcard setObject:@"agent" forKey:@"AGENT"];
179
[xcard setObject:@"org" forKey:@"ORG"];
183
+----------------+------------+-----------------------------+
184
| vCard | Element | Element Content Model |
185
| Type Name | Name | |
186
+----------------+------------+-----------------------------+
187
| CATEGORIES | categories | item* |
189
| NOTE | note | PCDATA |
190
| SORT-STRING | sort | PCDATA |
191
| SOUND | sound | extref | b64bin |
193
| | b64bin | PCDATA |
194
| URL | url | PCDATA |
195
| URI | uri | PCDATA |
196
+----------------+------------+-----------------------------+
198
[xcard setObject:@"categories" forKey:@"CATEGORIES"];
199
[xcard setObject:@"note" forKey:@"NOTE"];
200
[xcard setObject:@"sort" forKey:@"SORT-STRING"];
201
[xcard setObject:@"sound" forKey:@"SOUND"];
202
[xcard setObject:@"url" forKey:@"URL"];
203
[xcard setObject:@"uri" forKey:@"URI"];
207
+----------------+------------+-----------------------------+
208
| vCard | Element | Element Content Model |
209
| Type Name | Name | |
210
+----------------+------------+-----------------------------+
211
| KEY | key | extref | b64bin |
213
| | b64bin | PCDATA |
214
+----------------+------------+-----------------------------+
216
[xcard setObject:@"key" forKey:@"KEY"];
224
- (void)_setVCardAttributeMappings {
226
+----------------+------------+-----------+-----------------+
227
| Type | Attribute | Attribute | Default |
228
| Parameter Name | Name | Type | Value |
229
+----------------+------------+-----------+-----------------+
230
| ENCODING | Not Used | n/a | n/a |
231
| LANGUAGE | lang | CDATA | IMPLIED |
232
| TYPE for ADR | del.type | NMTOKENS | 'INTL POSTAL |
233
| and LABEL | | | PARCEL WORK' |
234
| TYPE for TEL | tel.type | NMTOKENS | 'VOICE' |
235
| TYPE for EMAIL | email.type | NMTOKENS | 'INTERNET' |
236
| TYPE for PHOTO,| img.type | CDATA | REQUIRED |
238
| TYPE for SOUND | aud.type | CDATA | REQUIRED |
239
| VALUE | value | NOTATION | See elements |
240
+----------------+------------+-----------+-----------------+
242
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2];
244
[dict setObject:@"lang" forKey:@"LANGUAGE"];
245
[dict setObject:@"value" forKey:@"VALUE"];
246
[self setAttributeMapping:dict];
249
dict = [[NSMutableDictionary alloc] initWithCapacity:1];
250
[dict setObject:@"del.type" forKey:@"TYPE"];
251
[self setAttributeMapping:dict forElement:@"ADR"];
252
[self setAttributeMapping:dict forElement:@"LABEL"];
255
dict = [[NSMutableDictionary alloc] initWithCapacity:1];
256
[dict setObject:@"tel.type" forKey:@"TYPE"];
257
[self setAttributeMapping:dict forElement:@"TEL"];
260
dict = [[NSMutableDictionary alloc] initWithCapacity:1];
261
[dict setObject:@"email.type" forKey:@"TYPE"];
262
[self setAttributeMapping:dict forElement:@"EMAIL"];
265
dict = [[NSMutableDictionary alloc] initWithCapacity:1];
266
[dict setObject:@"img.type" forKey:@"TYPE"];
267
[self setAttributeMapping:dict forElement:@"PHOTO"];
268
[self setAttributeMapping:dict forElement:@"LOGO"];
271
dict = [[NSMutableDictionary alloc] initWithCapacity:1];
272
[dict setObject:@"aud.type" forKey:@"TYPE"];
273
[self setAttributeMapping:dict forElement:@"SOUND"];
277
- (void)_setVCardSubItemMappings {
280
a = [NSArray arrayWithObjects:
287
[self setSubItemMapping:a forElement:@"n"];
289
a = [NSArray arrayWithObjects:
298
[self setSubItemMapping:a forElement:@"adr"];
300
a = [NSArray arrayWithObjects:
304
[self setSubItemMapping:a forElement:@"geo"];
306
a = [NSArray arrayWithObjects:
310
[self setSubItemMapping:a forElement:@"org"];
314
if ((self = [super init]) != nil) {
315
[self setPrefixURI:XMLNS_VSvCard];
316
[self setElementMapping:[[self class] xcardMapping]];
317
[self setAttributeElements:defElementNames];
318
[self _setVCardAttributeMappings];
319
[self _setVCardSubItemMappings];
324
/* top level parsing method */
326
- (void)reportDocStart {
327
[super reportDocStart];
329
[self->contentHandler startElement:@"vCardSet" namespace:self->prefixURI
330
rawName:@"vCardSet" attributes:nil];
332
- (void)reportDocEnd {
333
[self->contentHandler endElement:@"vCardSet" namespace:self->prefixURI
334
rawName:@"vCardSet"];
336
[super reportDocEnd];
339
@end /* VCardSaxDriver */