]> err.no Git - sope/blob - sope-ical/versitSaxDriver/VSvCardSaxDriver.m
yet another bugfix for recurrence calculation
[sope] / sope-ical / versitSaxDriver / VSvCardSaxDriver.m
1 /*
2  Copyright (C) 2003-2004 Max Berger
3  Copyright (C) 2004 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 @implementation VSvCardSaxDriver
28
29 static NSSet *defElementNames = nil;
30
31 + (void)initialize {
32   static BOOL didInit = NO;
33   
34   if(didInit)
35     return;
36   didInit = YES;
37   
38   defElementNames = [[NSSet alloc] initWithObjects:
39     @"class",
40     @"prodid",
41     @"rev",
42     @"uid",
43     @"version",
44     nil];
45 }
46
47 + (NSDictionary *)xcardMapping  {
48   static NSDictionary *dict = nil;
49   if (dict == NULL) {
50     NSMutableDictionary *xcard;
51
52     xcard = [[NSMutableDictionary alloc] initWithCapacity:30];
53     
54     [xcard setObject:@"vCard" forKey:@"VCARD"];
55     
56     /*
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      +----------------+------------+------------+----------------+
67      */
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"];
73     
74     
75     /*
76      Identification Types
77      +----------------+------------+-----------------------------+
78      |      vCard     |  Element   |  Element Content Model      |
79      |    Type Name   |   Name     |                             |
80      +----------------+------------+-----------------------------+
81      | FN             | fn         | PCDATA                      |
82      | N              | n          | family*,given*,other*,      |
83      |                |            |  prefix*, suffix*           |
84      |                | family     | PCDATA                      |
85      |                | given      | PCDATA                      |
86      |                | other      | PCDATA                      |
87      |                | prefix     | PCDATA                      |
88      |                | suffix     | PCDATA                      |
89      | NICKNAME       | nickname   | PCDATA                      |
90      | PHOTO          | photo      | extref or b64bin            |
91      |                | extref     | EMPTY                       |
92      |                | b64bin     | PCDATA                      |
93      | BDAY           | bday       | PCDATA                      |
94      +----------------+------------+-----------------------------+
95      */
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"];
101     
102     
103     /*
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*,  |
111      |                |            |  country*                   |
112      |                | pobox      | PCDATA                      |
113      |                | extadd     | PCDATA                      |
114      |                | street     | PCDATA                      |
115      |                | locality   | PCDATA                      |
116      |                | region     | PCDATA                      |
117      |                | pcode      | PCDATA                      |
118      |                | country    | PCDATA                      |
119      | LABEL          | LABEL      | PCDATA                      |
120      +----------------+------------+-----------------------------+
121      */
122     [xcard setObject:@"adr" forKey:@"ADR"];
123     [xcard setObject:@"LABEL" forKey:@"LABEL"];
124     
125     /* 
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      +----------------+------------+-----------------------------+
135      */
136     [xcard setObject:@"tel" forKey:@"TEL"];
137     [xcard setObject:@"email" forKey:@"EMAIL"];
138     [xcard setObject:@"mailer" forKey:@"MAILER"];    
139     
140     /*
141      Geographical Types
142      +----------------+------------+-----------------------------+
143      |      vCard     |  Element   |  Element Content Model      |
144      |    Type Name   |   Name     |                             |
145      +----------------+------------+-----------------------------+
146      | TZ             | tz         | PCDATA                      |
147      | GEO            | geo        | lat,lon                     |
148      |                | lat        | PCDATA                      |
149      |                | lon        | PCDATA                      |
150      +----------------+------------+-----------------------------+
151      */
152     [xcard setObject:@"tz" forKey:@"TZ"];
153     [xcard setObject:@"geo" forKey:@"GEO"];
154
155     /*
156      Organizational Types
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            |
164      |                | extref     | EMPTY                       |
165      |                | b64bin     | PCDATA                      |
166      | AGENT          | agent      | vCard | extref              |
167      | ORG            | org        | orgnam,orgunit*             |
168      |                | orgnam     | PCDATA                      |
169      |                | orgunit    | PCDATA
170      +----------------+------------+-----------------------------+
171      */
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"];
177     
178     /*
179      Explanatory Types
180      +----------------+------------+-----------------------------+
181      |      vCard     |  Element   |  Element Content Model      |
182      |    Type Name   |   Name     |                             |
183      +----------------+------------+-----------------------------+
184      | CATEGORIES     | categories | item*                       |
185      |                | item       | PCDATA                      |
186      | NOTE           | note       | PCDATA                      |
187      | SORT-STRING    | sort       | PCDATA                      |
188      | SOUND          | sound      | extref | b64bin             |
189      |                | extref     | EMPTY                       |
190      |                | b64bin     | PCDATA                      |
191      | URL            | url        | PCDATA                      |
192      | URI            | uri        | PCDATA                      |
193      +----------------+------------+-----------------------------+
194      */
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"];    
201     
202     /*
203      Security Types
204      +----------------+------------+-----------------------------+
205      |      vCard     |  Element   |  Element Content Model      |
206      |    Type Name   |   Name     |                             |
207      +----------------+------------+-----------------------------+
208      | KEY            | key        | extref | b64bin             |
209      |                | extref     | EMPTY                       |
210      |                | b64bin     | PCDATA                      |
211      +----------------+------------+-----------------------------+     
212      */
213     [xcard setObject:@"key" forKey:@"KEY"];
214     
215     dict = [xcard copy];
216     [xcard release];
217   }
218   return dict;
219 }
220
221 - (void)_setVCardAttributeMappings {
222   /*
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        |
234    |  and LOGO      |            |           |                 |
235    | TYPE for SOUND | aud.type   | CDATA     | REQUIRED        |
236    | VALUE          | value      | NOTATION  | See elements    |
237    +----------------+------------+-----------+-----------------+   
238    */
239   NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2];
240   
241   [dict setObject:@"lang" forKey:@"LANGUAGE"];
242   [dict setObject:@"value" forKey:@"VALUE"];
243   [self setAttributeMapping:dict];
244   [dict release];
245   
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"];
250   [dict release];
251   
252   dict = [[NSMutableDictionary alloc] initWithCapacity:1];
253   [dict setObject:@"tel.type" forKey:@"TYPE"];
254   [self setAttributeMapping:dict forElement:@"TEL"];
255   [dict release];
256   
257   dict = [[NSMutableDictionary alloc] initWithCapacity:1];
258   [dict setObject:@"email.type" forKey:@"TYPE"];
259   [self setAttributeMapping:dict forElement:@"EMAIL"];
260   [dict release];
261   
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"];
266   [dict release];
267   
268   dict = [[NSMutableDictionary alloc] initWithCapacity:1];
269   [dict setObject:@"aud.type" forKey:@"TYPE"];
270   [self setAttributeMapping:dict forElement:@"SOUND"];
271   [dict release];
272 }
273
274 - (void)_setVCardSubItemMappings {
275   NSArray *a;
276   
277   a = [NSArray arrayWithObjects:
278     @"family",
279     @"given",
280     @"other",
281     @"prefix",
282     @"suffix",
283     nil];
284   [self setSubItemMapping:a forElement:@"n"];
285
286   a = [NSArray arrayWithObjects:
287     @"pobox",
288     @"extadd",
289     @"street",
290     @"locality",
291     @"region",
292     @"pcode",
293     @"country",
294     nil];
295   [self setSubItemMapping:a forElement:@"adr"];
296   
297   a = [NSArray arrayWithObjects:
298     @"lat",
299     @"lon",
300     nil];
301   [self setSubItemMapping:a forElement:@"geo"];
302   
303   a = [NSArray arrayWithObjects:
304     @"orgnam",
305     @"orgunit",
306     nil];
307   [self setSubItemMapping:a forElement:@"org"];
308 }
309
310 - (id)init {
311   if ((self = [super init])) {
312     
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];
318   }
319   return self;
320 }
321
322 @end /* VCardSaxDriver */