]> err.no Git - sope/blob - sope-ical/versitSaxDriver/VSiCalSaxDriver.m
added support vcard type groupings
[sope] / sope-ical / versitSaxDriver / VSiCalSaxDriver.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 "VSiCalSaxDriver.h"
25 #include <SaxObjC/XMLNamespaces.h>
26 #include "common.h"
27
28 @implementation VSiCalSaxDriver
29
30 static NSSet   *defElementNames = nil;
31 static NSArray *defGeoMappings  = nil;
32
33 + (void)initialize {
34   static BOOL didInit = NO;
35
36   if(didInit)
37     return;
38   didInit = YES;
39
40   defElementNames = [[NSSet alloc] initWithObjects:
41     @"calscale",
42     @"version",
43     @"prodid",
44     @"method",
45     nil];
46   defGeoMappings = [[NSArray alloc] initWithObjects:
47     @"lat",
48     @"lon",
49     nil];
50 }
51
52 + (NSDictionary *)xcalMapping  {
53   static NSDictionary *dict = nil;
54   if (dict == nil) {
55     NSMutableDictionary *xcal;
56
57     xcal = [[NSMutableDictionary alloc] initWithCapacity:60];
58     /* 
59       +---------------+-----------+-----------+-----------------+
60      | Calendar      | Attribute | Attribute | Default         |
61      | Property Name | Name      | Type      | Value           |
62      +---------------+-----------+-----------+-----------------+
63      | CALSCALE      | calscale  | CDATA     | IMPLIED         |
64      | METHOD        | method    | NMTOKEN   | PUBLISH         |
65      | VERSION       | version   | CDATA     | REQUIRED        |
66      | PRODID        | prodid    | CDATA     | IMPLIED         |
67      +---------------+-----------+-----------+-----------------+
68       */
69     [xcal setObject:@"calscale" forKey:@"CALSCALE"];
70     [xcal setObject:@"method" forKey:@"METHOD"];
71     [xcal setObject:@"version" forKey:@"VERSION"];
72     [xcal setObject:@"prodid" forKey:@"PRODID"];
73     
74     /*
75      Descriptive Component Properties
76      +----------------+-------------+-----------------------------+
77      | Component      | Element     | Element Content Model       |
78      | Property Name  | Name        |                             |
79      +----------------+-------------+-----------------------------+
80      | ATTACH         | attach      | extref or b64bin            |
81      |                | extref      | EMPTY                       |
82      |                | b64bin      | PCDATA                      |
83      | CATEGORIES     | categories  | Any number of item elements |
84      |                | item        | PCDATA                      |
85      | CLASS          | class       | PCDATA                      |
86      | COMMENT        | comment     | PCDATA                      |
87      | DESCRIPTION    | description | PCDATA                      |
88      | GEO            | geo         | lat followed by lon element |
89      |                | lat         | PCDATA                      |
90      |                | lon         | PCDATA                      |
91      | LOCATION       | location    | PCDATA                      |
92      | PERCENT        | percent     | PCDATA                      |
93      | PRIORITY       | priority    | PCDATA                      |
94      | RESOURCES      | resources   | Any number of item elements |
95      | STATUS         | status      | PCDATA                      |
96      | SUMMARY        | summary     | PCDATA                      |
97      +----------------+-------------+-----------------------------+
98      */
99     
100     [xcal setObject:@"attach" forKey:@"ATTACH"];
101     [xcal setObject:@"categories" forKey:@"CATEGORIES"];
102     [xcal setObject:@"class" forKey:@"CLASS"];
103     [xcal setObject:@"comment" forKey:@"COMMENT"];
104     [xcal setObject:@"description" forKey:@"DESCRIPTION"];
105     [xcal setObject:@"geo" forKey:@"GEO"];
106     [xcal setObject:@"location" forKey:@"LOCATION"];
107     [xcal setObject:@"percent" forKey:@"PERCENT"];
108     [xcal setObject:@"priority" forKey:@"PRIORITY"];
109     [xcal setObject:@"resources" forKey:@"RESOURCES"];
110     [xcal setObject:@"status" forKey:@"STATUS"];
111     [xcal setObject:@"summary" forKey:@"SUMMARY"];
112       
113     /*
114      Date and Time Component Properties
115      +----------------+------------+-----------------------------+
116      | Component      | Element    | Element Content Model       |
117      | Property Name  | Name       |                             |
118      +----------------+------------+-----------------------------+
119      | COMPLETED      | completed  | PCDATA                      |
120      | DTEND          | dtend      | PCDATA                      |
121      | DUE            | due        | PCDATA                      |
122      | DTSTART        | dtstart    | PCDATA                      |
123      | DURATION       | duration   | PCDATA                      |
124      | FREEBUSY       | freebusy   | PCDATA                      |
125      | TRANSP         | transp     | PCDATA                      |
126      +----------------+------------+-----------------------------+
127      */
128     
129     [xcal setObject:@"completed" forKey:@"COMPLETED"];
130     [xcal setObject:@"dtend" forKey:@"DTEND"];
131     [xcal setObject:@"due" forKey:@"DUE"];
132     [xcal setObject:@"dtstart" forKey:@"DTSTART"];
133     [xcal setObject:@"duration" forKey:@"DURATION"];
134     [xcal setObject:@"freebusy" forKey:@"FREEBUSY"];
135     [xcal setObject:@"transp" forKey:@"TRANSP"];    
136     
137     /*
138      Time Zone Component Properties
139      +----------------+-------------+-----------------------------+
140      | Component      | Element     | Element Content Model       |
141      | Property Name  | Name        |                             |
142      +----------------+-------------+-----------------------------+
143      | TZID           | tzid        | PCDATA                      |
144      | TZNAME         | tzname      | PCDATA                      |
145      | TZOFFSETFROM   | tzoffsetfrom| PCDATA                      |
146      | TZOFFSETTO     | tzoffsetto  | PCDATA                      |
147      | TZURL          | tzurl       | EMPTY                       |
148      +----------------+-------------+-----------------------------+     
149      */
150     
151     [xcal setObject:@"tzid" forKey:@"TZID"];
152     [xcal setObject:@"tzname" forKey:@"TZNAME"];
153     [xcal setObject:@"tzoffsetfrom" forKey:@"TZOFFSETFROM"];
154     [xcal setObject:@"tzoffsetto" forKey:@"TZOFFSETTO"];
155     [xcal setObject:@"tzurl" forKey:@"TZURL"];
156     
157     /*    
158      Relationship Component Properties
159      +----------------+---------------+--------------------------+
160      | Component      | Element       | Element Content Model    |
161      | Property Name  | Name          |                          |
162      +----------------+---------------+--------------------------+
163      | ATTENDEE       | attendee      | PCDATA                   |
164      | CONTACT        | contact       | PCDATA                   |
165      | ORGANIZER      | organizer     | PCDATA                   |
166      | RECURRENCE-ID  | recurrence-id | PCDATA                   |
167      | RELATED-TO     | related-to    | PCDATA                   |
168      | URL            | url           | EMPTY                    |
169      | UID            | uid           | PCDATA                   |
170      +----------------+---------------+--------------------------+
171     */ 
172     [xcal setObject:@"attendee" forKey:@"ATTENDEE"];
173     [xcal setObject:@"contact" forKey:@"CONTACT"];
174     [xcal setObject:@"organizer" forKey:@"ORGANIZER"];
175     [xcal setObject:@"recurrence-id" forKey:@"RECURRENCE-ID"];
176     [xcal setObject:@"related-to" forKey:@"RELATED-TO"];
177     [xcal setObject:@"url" forKey:@"URL"];
178     [xcal setObject:@"uid" forKey:@"UID"];
179     
180     /*
181      Recurrence Component Properties
182      +----------------+------------+-----------------------------+
183      | Component      | Element    | Element Content Model       |
184      | Property Name  | Name       |                             |
185      +----------------+------------+-----------------------------+
186      | EXDATE         | exdate     | PCDATA                      |
187      | EXRULE         | exrule     | PCDATA                      |
188      | RDATE          | rdate      | PCDATA                      |
189      | RRULE          | rrule      | PCDATA                      |
190      +----------------+------------+-----------------------------+
191      
192      */
193     [xcal setObject:@"exdate" forKey:@"EXDATE"];
194     [xcal setObject:@"exrule" forKey:@"EXRULE"];
195     [xcal setObject:@"rdate" forKey:@"RDATE"];
196     [xcal setObject:@"rrule" forKey:@"RRULE"];
197     
198     /*     
199      Alarm Component Properties
200      +----------------+------------+-----------------------------+
201      | Component      | Element    | Element Content Model       |
202      | Property Name  | Name       |                             |
203      +----------------+------------+-----------------------------+
204      | ACTION         | action     | PCDATA                      |
205      | REPEAT         | repeat     | PCDATA                      |
206      | TRIGGER        | trigger    | PCDATA                      |
207      +----------------+------------+-----------------------------+
208      */
209     [xcal setObject:@"action" forKey:@"ACTION"];
210     [xcal setObject:@"repeat" forKey:@"REPEAT"];
211     [xcal setObject:@"trigger" forKey:@"TRIGGER"];
212     
213     /* 
214      Change Management Component Properties
215      +----------------+---------------+--------------------------+
216      | Component      | Element       | Element Content Model    |
217      | Property Name  | Name          |                          |
218      +----------------+---------------+--------------------------+
219      | CREATED        | created       | PCDATA                   |
220      | DTSTAMP        | dtstamp       | PCDATA                   |
221      | LAST-MODIFIED  | last-modified | PCDATA                   |
222      | SEQUENCE       | sequence      | PCDATA                   |
223      +----------------+---------------+--------------------------+
224      */
225     [xcal setObject:@"created" forKey:@"CREATED"];
226     [xcal setObject:@"dtstamp" forKey:@"DTSTAMP"];
227     [xcal setObject:@"last-modified" forKey:@"LAST-MODIFIED"];
228     [xcal setObject:@"sequence" forKey:@"SEQUENCE"];
229     
230      /*
231      Miscellaneous Component Properties
232      +----------------+----------------+-------------------------+
233      | Component      | Element        | Element Content Model   |
234      | Property Name  | Name           |                         |
235      +----------------+----------------+-------------------------+
236      | REQUEST-STATUS | request-status | PCDATA                  |
237      +----------------+----------------+-------------------------+
238      */
239     [xcal setObject:@"request-status" forKey:@"REQUEST-STATUS"];
240
241     
242     /*
243      Component Structuring Properties
244      +----------------+------------+-------------------------------+
245      | Component      | Element    | Element Content Model         |
246      | Property Name  | Name       |                               |
247      +----------------+------------+-------------------------------+
248      | Multiple iCal- | iCalendar  | One or more iCal elements     |
249      | endar objects  |            |                               |
250      | VCALENDAR      | vcalendar  | calcomp parameter entity      |
251      | VEVENT         | vevent     | vevent.opt1 and vevent.optm   |
252      |                |            | parameter entity and valarm   |
253      |                |            | element                       |
254      | VTODO          | vtodo      | vtodo.opt1 and vtodo.optm     |
255      |                |            | parameter entity and valarm   |
256      |                |            | element                       |
257      | VJOURNAL       | vjournal   | vjournal.opt1 and             |
258      |                |            | vjournal.optm parameter       |
259      |                |            | entity                        |
260      | VFREEBUSY      | vfreebusy  | vfreebusy.opt1 and            |
261      |                |            | vfreebusy.optm parameter      |
262      |                |            | entity                        |
263      | VTIMEZONE      | vtimezone  | vtimezone.man,                |
264      |                |            | vtimezone.opt1,               |
265      |                |            | vtimezone.mann parameter      |
266      |                |            | entity                        |
267      | STANDARD       | standard   | standard.man or standard.optm |
268      |                |            | entity                        |
269      | DAYLIGHT       | daylight   | daylight.man or daylight.optm |
270      |                |            | entity                        |
271      | VALARM         | valarm     | valarm.audio, valarm.display, |
272      |                |            | valarm.email and              |
273      |                |            | valarm.procedure entity       |
274      +----------------+------------+-------------------------------+
275      */
276
277     [xcal setObject:@"vcalendar" forKey:@"VCALENDAR"];
278     [xcal setObject:@"vevent" forKey:@"VEVENT"];
279     [xcal setObject:@"vtodo" forKey:@"VTODO"];
280     [xcal setObject:@"vjournal" forKey:@"VJOURNAL"];
281     [xcal setObject:@"vfreebusy" forKey:@"VFREEBUSY"];
282     [xcal setObject:@"vtimezone" forKey:@"VTIMEZONE"];
283     [xcal setObject:@"standard" forKey:@"STANDARD"];
284     [xcal setObject:@"daylight" forKey:@"DAYLIGHT"];
285     [xcal setObject:@"valarm" forKey:@"VALARM"];
286     
287     dict = [xcal copy];
288     [xcal release];
289   }
290   return dict;
291 }
292
293 + (NSDictionary *)xcalAttrMapping {
294   static NSDictionary *dict = nil;
295   if (dict == nil) {
296     NSMutableDictionary *xcal;
297
298     xcal = [[NSMutableDictionary alloc] initWithCapacity:20];
299     /*
300      ----------------+----------------+-----------+-----------------+
301      | Property       | Attribute      | Attribute | Default         |
302      | Parameter Name | Name           | Type      | Value           |
303      +----------------+----------------+-----------+-----------------+
304      | ALTREP         | altrep         | ENTITY    | IMPLIED         |
305      | CN             | cn             | CDATA     | Null String     |
306      | CUTYPE         | cutype         | NMTOKEN   | INDIVIDUAL      |
307      | DELEGATED-FROM | delegated-from | CDATA     | IMPLIED         |
308      | DELEGATED-TO   | delegated-to   | CDATA     | IMPLIED         |
309      | DIR            | dir            | ENTITY    | IMPLIED         |
310      | ENCODING       | Not Used       | n/a       | n/a             |
311      | FMTTYPE        | fmttype        | CDATA     | REQUIRED        |
312      | FBTYPE         | fbtype         | NMTOKEN   | BUSY            |
313      | LANGUAGE       | language       | CDATA     | IMPLIED         |
314      | MEMBER         | member         | CDATA     | IMPLIED         |
315      | PARTSTAT       | partstat       | NMTOKEN   | NEEDS-ACTION    |
316      | RANGE          | range          | NMTOKEN   | THISONLY        |
317      | RELATED        | related        | NMTOKEN   | START           |
318      | RELTYPE        | reltype        | NMTOKEN   | PARENT          |
319      | ROLE           | role           | NMTOKEN   | REQ-PARTICIPANT |
320      | RSVP           | rsvp           | NMTOKEN   | FALSE           |
321      | SENT-BY        | sent-by        | CDATA     | IMPLIED         |
322      | TZID           | tzid           | CDATA     | IMPLIED         |
323      | VALUE          | value          | NOTATION  | See elements    |
324      +----------------+----------------+-----------+-----------------+
325      */
326     [xcal setObject:@"altrep" forKey:@"ALTREP"];
327     [xcal setObject:@"cn" forKey:@"CN"];
328     [xcal setObject:@"cutype" forKey:@"CUTYPE"];
329     [xcal setObject:@"delegated-from" forKey:@"DELEGATED-FROM"];
330     [xcal setObject:@"delegated-to" forKey:@"DELEGATED-TO"];
331     [xcal setObject:@"dir" forKey:@"DIR"];
332     [xcal setObject:@"Not" forKey:@"ENCODING"];
333     [xcal setObject:@"fmttype" forKey:@"FMTTYPE"];
334     [xcal setObject:@"fbtype" forKey:@"FBTYPE"];
335     [xcal setObject:@"language" forKey:@"LANGUAGE"];
336     [xcal setObject:@"member" forKey:@"MEMBER"];
337     [xcal setObject:@"partstat" forKey:@"PARTSTAT"];
338     [xcal setObject:@"range" forKey:@"RANGE"];
339     [xcal setObject:@"related" forKey:@"RELATED"];
340     [xcal setObject:@"reltype" forKey:@"RELTYPE"];
341     [xcal setObject:@"role" forKey:@"ROLE"];
342     [xcal setObject:@"rsvp" forKey:@"RSVP"];
343     [xcal setObject:@"sent-by" forKey:@"SENT-BY"];
344     [xcal setObject:@"tzid" forKey:@"TZID"];
345     [xcal setObject:@"value" forKey:@"VALUE"];
346     
347     dict = [xcal copy];
348     [xcal release];
349   }
350   return dict;
351 }
352
353 - (id)init {
354   if ((self = [super init])) {
355     [self setPrefixURI:XMLNS_XCAL_01];
356     [self setElementMapping:[[self class] xcalMapping]];
357     [self setAttributeElements:defElementNames];
358
359     [self setAttributeMapping:[[self class] xcalAttrMapping]];
360     [self setSubItemMapping:defGeoMappings forElement:@"geo"];
361   }
362   return self;
363 }
364
365 @end /* ICalendarSaxDriver */