]> err.no Git - sope/blob - sope-ical/versitSaxDriver/VSvCardSaxDriver.m
bumped Xcode dyld versions
[sope] / sope-ical / versitSaxDriver / VSvCardSaxDriver.m
1 /*
2   Copyright (C) 2003-2004 Max Berger
3   Copyright (C) 2004-2005 OpenGroupware.org
4   
5   This file is part of versitSaxDriver, written for the OpenGroupware.org
6   project (OGo).
7   
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
11   later version.
12   
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.
17   
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
21   02111-1307, USA.
22 */
23
24 #include "VSvCardSaxDriver.h"
25 #include "common.h"
26
27 #define XMLNS_VSvCard \
28   @"http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt"
29
30 @implementation VSvCardSaxDriver
31
32 static NSSet *defElementNames = nil;
33
34 + (void)initialize {
35   static BOOL didInit = NO;
36   
37   if(didInit)
38     return;
39   didInit = YES;
40   
41   defElementNames = [[NSSet alloc] initWithObjects:
42     @"class", @"prodid", @"rev", @"uid", @"version", nil];
43 }
44
45 + (NSDictionary *)xcardMapping  {
46   static NSDictionary *dict = nil;
47   if (dict == NULL) {
48     NSMutableDictionary *xcard;
49
50     xcard = [[NSMutableDictionary alloc] initWithCapacity:30];
51     
52     [xcard setObject:@"vCard" forKey:@"VCARD"];
53     
54     /*
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      +----------------+------------+------------+----------------+
65      */
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"];
71     
72     
73     /*
74      Identification Types
75      +----------------+------------+-----------------------------+
76      |      vCard     |  Element   |  Element Content Model      |
77      |    Type Name   |   Name     |                             |
78      +----------------+------------+-----------------------------+
79      | FN             | fn         | PCDATA                      |
80      | N              | n          | family*,given*,other*,      |
81      |                |            |  prefix*, suffix*           |
82      |                | family     | PCDATA                      |
83      |                | given      | PCDATA                      |
84      |                | other      | PCDATA                      |
85      |                | prefix     | PCDATA                      |
86      |                | suffix     | PCDATA                      |
87      | NICKNAME       | nickname   | PCDATA                      |
88      | PHOTO          | photo      | extref or b64bin            |
89      |                | extref     | EMPTY                       |
90      |                | b64bin     | PCDATA                      |
91      | BDAY           | bday       | PCDATA                      |
92      +----------------+------------+-----------------------------+
93      */
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"];
99     
100     
101     /*
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*,  |
109      |                |            |  country*                   |
110      |                | pobox      | PCDATA                      |
111      |                | extadd     | PCDATA                      |
112      |                | street     | PCDATA                      |
113      |                | locality   | PCDATA                      |
114      |                | region     | PCDATA                      |
115      |                | pcode      | PCDATA                      |
116      |                | country    | PCDATA                      |
117      | LABEL          | LABEL      | PCDATA                      |
118      +----------------+------------+-----------------------------+
119      */
120     [xcard setObject:@"adr" forKey:@"ADR"];
121     [xcard setObject:@"LABEL" forKey:@"LABEL"];
122     
123     /* 
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      +----------------+------------+-----------------------------+
133      */
134     [xcard setObject:@"tel" forKey:@"TEL"];
135     [xcard setObject:@"email" forKey:@"EMAIL"];
136     [xcard setObject:@"mailer" forKey:@"MAILER"];    
137     
138     /*
139      Geographical Types
140      +----------------+------------+-----------------------------+
141      |      vCard     |  Element   |  Element Content Model      |
142      |    Type Name   |   Name     |                             |
143      +----------------+------------+-----------------------------+
144      | TZ             | tz         | PCDATA                      |
145      | GEO            | geo        | lat,lon                     |
146      |                | lat        | PCDATA                      |
147      |                | lon        | PCDATA                      |
148      +----------------+------------+-----------------------------+
149      */
150     [xcard setObject:@"tz" forKey:@"TZ"];
151     [xcard setObject:@"geo" forKey:@"GEO"];
152
153     /*
154      Organizational Types
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            |
162      |                | extref     | EMPTY                       |
163      |                | b64bin     | PCDATA                      |
164      | AGENT          | agent      | vCard | extref              |
165      | ORG            | org        | orgnam,orgunit*             |
166      |                | orgnam     | PCDATA                      |
167      |                | orgunit    | PCDATA
168      +----------------+------------+-----------------------------+
169      */
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"];
175     
176     /*
177      Explanatory Types
178      +----------------+------------+-----------------------------+
179      |      vCard     |  Element   |  Element Content Model      |
180      |    Type Name   |   Name     |                             |
181      +----------------+------------+-----------------------------+
182      | CATEGORIES     | categories | item*                       |
183      |                | item       | PCDATA                      |
184      | NOTE           | note       | PCDATA                      |
185      | SORT-STRING    | sort       | PCDATA                      |
186      | SOUND          | sound      | extref | b64bin             |
187      |                | extref     | EMPTY                       |
188      |                | b64bin     | PCDATA                      |
189      | URL            | url        | PCDATA                      |
190      | URI            | uri        | PCDATA                      |
191      +----------------+------------+-----------------------------+
192      */
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"];    
199     
200     /*
201      Security Types
202      +----------------+------------+-----------------------------+
203      |      vCard     |  Element   |  Element Content Model      |
204      |    Type Name   |   Name     |                             |
205      +----------------+------------+-----------------------------+
206      | KEY            | key        | extref | b64bin             |
207      |                | extref     | EMPTY                       |
208      |                | b64bin     | PCDATA                      |
209      +----------------+------------+-----------------------------+     
210      */
211     [xcard setObject:@"key" forKey:@"KEY"];
212     
213     dict = [xcard copy];
214     [xcard release];
215   }
216   return dict;
217 }
218
219 - (void)_setVCardAttributeMappings {
220   /*
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        |
232    |  and LOGO      |            |           |                 |
233    | TYPE for SOUND | aud.type   | CDATA     | REQUIRED        |
234    | VALUE          | value      | NOTATION  | See elements    |
235    +----------------+------------+-----------+-----------------+   
236    */
237   NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2];
238   
239   [dict setObject:@"lang" forKey:@"LANGUAGE"];
240   [dict setObject:@"value" forKey:@"VALUE"];
241   [self setAttributeMapping:dict];
242   [dict release];
243   
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"];
248   [dict release];
249   
250   dict = [[NSMutableDictionary alloc] initWithCapacity:1];
251   [dict setObject:@"tel.type" forKey:@"TYPE"];
252   [self setAttributeMapping:dict forElement:@"TEL"];
253   [dict release];
254   
255   dict = [[NSMutableDictionary alloc] initWithCapacity:1];
256   [dict setObject:@"email.type" forKey:@"TYPE"];
257   [self setAttributeMapping:dict forElement:@"EMAIL"];
258   [dict release];
259   
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"];
264   [dict release];
265   
266   dict = [[NSMutableDictionary alloc] initWithCapacity:1];
267   [dict setObject:@"aud.type" forKey:@"TYPE"];
268   [self setAttributeMapping:dict forElement:@"SOUND"];
269   [dict release];
270 }
271
272 - (void)_setVCardSubItemMappings {
273   NSArray *a;
274   
275   a = [NSArray arrayWithObjects:
276     @"family",
277     @"given",
278     @"other",
279     @"prefix",
280     @"suffix",
281     nil];
282   [self setSubItemMapping:a forElement:@"n"];
283
284   a = [NSArray arrayWithObjects:
285     @"pobox",
286     @"extadd",
287     @"street",
288     @"locality",
289     @"region",
290     @"pcode",
291     @"country",
292     nil];
293   [self setSubItemMapping:a forElement:@"adr"];
294   
295   a = [NSArray arrayWithObjects:
296     @"lat",
297     @"lon",
298     nil];
299   [self setSubItemMapping:a forElement:@"geo"];
300   
301   a = [NSArray arrayWithObjects:
302     @"orgnam",
303     @"orgunit",
304     nil];
305   [self setSubItemMapping:a forElement:@"org"];
306 }
307
308 - (id)init {
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];
315   }
316   return self;
317 }
318
319 /* top level parsing method */
320
321 - (void)reportDocStart {
322   [super reportDocStart];
323   
324   [self->contentHandler startElement:@"vCardSet" namespace:self->prefixURI
325                         rawName:@"vCardSet" attributes:nil];
326 }
327 - (void)reportDocEnd {
328   [self->contentHandler endElement:@"vCardSet" namespace:self->prefixURI
329                         rawName:@"vCardSet"];
330   
331   [super reportDocEnd];
332 }
333
334 @end /* VCardSaxDriver */