~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-ical/versitSaxDriver/VSvCardSaxDriver.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#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",
 
43
    @"prodid",
 
44
    @"rev",
 
45
    @"uid",
 
46
    @"version",
 
47
    nil];
 
48
}
 
49
 
 
50
+ (NSDictionary *)xcardMapping  {
 
51
  static NSDictionary *dict = nil;
 
52
  if (dict == NULL) {
 
53
    NSMutableDictionary *xcard;
 
54
 
 
55
    xcard = [[NSMutableDictionary alloc] initWithCapacity:30];
 
56
    
 
57
    [xcard setObject:@"vCard" forKey:@"VCARD"];
 
58
    
 
59
    /*
 
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
     +----------------+------------+------------+----------------+
 
70
     */
 
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"];
 
76
    
 
77
    
 
78
    /*
 
79
     Identification Types
 
80
     +----------------+------------+-----------------------------+
 
81
     |      vCard     |  Element   |  Element Content Model      |
 
82
     |    Type Name   |   Name     |                             |
 
83
     +----------------+------------+-----------------------------+
 
84
     | FN             | fn         | PCDATA                      |
 
85
     | N              | n          | family*,given*,other*,      |
 
86
     |                |            |  prefix*, suffix*           |
 
87
     |                | family     | PCDATA                      |
 
88
     |                | given      | PCDATA                      |
 
89
     |                | other      | PCDATA                      |
 
90
     |                | prefix     | PCDATA                      |
 
91
     |                | suffix     | PCDATA                      |
 
92
     | NICKNAME       | nickname   | PCDATA                      |
 
93
     | PHOTO          | photo      | extref or b64bin            |
 
94
     |                | extref     | EMPTY                       |
 
95
     |                | b64bin     | PCDATA                      |
 
96
     | BDAY           | bday       | PCDATA                      |
 
97
     +----------------+------------+-----------------------------+
 
98
     */
 
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"];
 
104
    
 
105
    
 
106
    /*
 
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*,  |
 
114
     |                |            |  country*                   |
 
115
     |                | pobox      | PCDATA                      |
 
116
     |                | extadd     | PCDATA                      |
 
117
     |                | street     | PCDATA                      |
 
118
     |                | locality   | PCDATA                      |
 
119
     |                | region     | PCDATA                      |
 
120
     |                | pcode      | PCDATA                      |
 
121
     |                | country    | PCDATA                      |
 
122
     | LABEL          | LABEL      | PCDATA                      |
 
123
     +----------------+------------+-----------------------------+
 
124
     */
 
125
    [xcard setObject:@"adr" forKey:@"ADR"];
 
126
    [xcard setObject:@"LABEL" forKey:@"LABEL"];
 
127
    
 
128
    /* 
 
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
     +----------------+------------+-----------------------------+
 
138
     */
 
139
    [xcard setObject:@"tel" forKey:@"TEL"];
 
140
    [xcard setObject:@"email" forKey:@"EMAIL"];
 
141
    [xcard setObject:@"mailer" forKey:@"MAILER"];    
 
142
    
 
143
    /*
 
144
     Geographical Types
 
145
     +----------------+------------+-----------------------------+
 
146
     |      vCard     |  Element   |  Element Content Model      |
 
147
     |    Type Name   |   Name     |                             |
 
148
     +----------------+------------+-----------------------------+
 
149
     | TZ             | tz         | PCDATA                      |
 
150
     | GEO            | geo        | lat,lon                     |
 
151
     |                | lat        | PCDATA                      |
 
152
     |                | lon        | PCDATA                      |
 
153
     +----------------+------------+-----------------------------+
 
154
     */
 
155
    [xcard setObject:@"tz" forKey:@"TZ"];
 
156
    [xcard setObject:@"geo" forKey:@"GEO"];
 
157
 
 
158
    /*
 
159
     Organizational Types
 
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            |
 
167
     |                | extref     | EMPTY                       |
 
168
     |                | b64bin     | PCDATA                      |
 
169
     | AGENT          | agent      | vCard | extref              |
 
170
     | ORG            | org        | orgnam,orgunit*             |
 
171
     |                | orgnam     | PCDATA                      |
 
172
     |                | orgunit    | PCDATA
 
173
     +----------------+------------+-----------------------------+
 
174
     */
 
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"];
 
180
    
 
181
    /*
 
182
     Explanatory Types
 
183
     +----------------+------------+-----------------------------+
 
184
     |      vCard     |  Element   |  Element Content Model      |
 
185
     |    Type Name   |   Name     |                             |
 
186
     +----------------+------------+-----------------------------+
 
187
     | CATEGORIES     | categories | item*                       |
 
188
     |                | item       | PCDATA                      |
 
189
     | NOTE           | note       | PCDATA                      |
 
190
     | SORT-STRING    | sort       | PCDATA                      |
 
191
     | SOUND          | sound      | extref | b64bin             |
 
192
     |                | extref     | EMPTY                       |
 
193
     |                | b64bin     | PCDATA                      |
 
194
     | URL            | url        | PCDATA                      |
 
195
     | URI            | uri        | PCDATA                      |
 
196
     +----------------+------------+-----------------------------+
 
197
     */
 
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"];    
 
204
    
 
205
    /*
 
206
     Security Types
 
207
     +----------------+------------+-----------------------------+
 
208
     |      vCard     |  Element   |  Element Content Model      |
 
209
     |    Type Name   |   Name     |                             |
 
210
     +----------------+------------+-----------------------------+
 
211
     | KEY            | key        | extref | b64bin             |
 
212
     |                | extref     | EMPTY                       |
 
213
     |                | b64bin     | PCDATA                      |
 
214
     +----------------+------------+-----------------------------+     
 
215
     */
 
216
    [xcard setObject:@"key" forKey:@"KEY"];
 
217
    
 
218
    dict = [xcard copy];
 
219
    [xcard release];
 
220
  }
 
221
  return dict;
 
222
}
 
223
 
 
224
- (void)_setVCardAttributeMappings {
 
225
  /*
 
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        |
 
237
   |  and LOGO      |            |           |                 |
 
238
   | TYPE for SOUND | aud.type   | CDATA     | REQUIRED        |
 
239
   | VALUE          | value      | NOTATION  | See elements    |
 
240
   +----------------+------------+-----------+-----------------+   
 
241
   */
 
242
  NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2];
 
243
  
 
244
  [dict setObject:@"lang" forKey:@"LANGUAGE"];
 
245
  [dict setObject:@"value" forKey:@"VALUE"];
 
246
  [self setAttributeMapping:dict];
 
247
  [dict release];
 
248
  
 
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"];
 
253
  [dict release];
 
254
  
 
255
  dict = [[NSMutableDictionary alloc] initWithCapacity:1];
 
256
  [dict setObject:@"tel.type" forKey:@"TYPE"];
 
257
  [self setAttributeMapping:dict forElement:@"TEL"];
 
258
  [dict release];
 
259
  
 
260
  dict = [[NSMutableDictionary alloc] initWithCapacity:1];
 
261
  [dict setObject:@"email.type" forKey:@"TYPE"];
 
262
  [self setAttributeMapping:dict forElement:@"EMAIL"];
 
263
  [dict release];
 
264
  
 
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"];
 
269
  [dict release];
 
270
  
 
271
  dict = [[NSMutableDictionary alloc] initWithCapacity:1];
 
272
  [dict setObject:@"aud.type" forKey:@"TYPE"];
 
273
  [self setAttributeMapping:dict forElement:@"SOUND"];
 
274
  [dict release];
 
275
}
 
276
 
 
277
- (void)_setVCardSubItemMappings {
 
278
  NSArray *a;
 
279
  
 
280
  a = [NSArray arrayWithObjects:
 
281
    @"family",
 
282
    @"given",
 
283
    @"other",
 
284
    @"prefix",
 
285
    @"suffix",
 
286
    nil];
 
287
  [self setSubItemMapping:a forElement:@"n"];
 
288
 
 
289
  a = [NSArray arrayWithObjects:
 
290
    @"pobox",
 
291
    @"extadd",
 
292
    @"street",
 
293
    @"locality",
 
294
    @"region",
 
295
    @"pcode",
 
296
    @"country",
 
297
    nil];
 
298
  [self setSubItemMapping:a forElement:@"adr"];
 
299
  
 
300
  a = [NSArray arrayWithObjects:
 
301
    @"lat",
 
302
    @"lon",
 
303
    nil];
 
304
  [self setSubItemMapping:a forElement:@"geo"];
 
305
  
 
306
  a = [NSArray arrayWithObjects:
 
307
    @"orgnam",
 
308
    @"orgunit",
 
309
    nil];
 
310
  [self setSubItemMapping:a forElement:@"org"];
 
311
}
 
312
 
 
313
- (id)init {
 
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];
 
320
  }
 
321
  return self;
 
322
}
 
323
 
 
324
/* top level parsing method */
 
325
 
 
326
- (void)reportDocStart {
 
327
  [super reportDocStart];
 
328
  
 
329
  [self->contentHandler startElement:@"vCardSet" namespace:self->prefixURI
 
330
                        rawName:@"vCardSet" attributes:nil];
 
331
}
 
332
- (void)reportDocEnd {
 
333
  [self->contentHandler endElement:@"vCardSet" namespace:self->prefixURI
 
334
                        rawName:@"vCardSet"];
 
335
  
 
336
  [super reportDocEnd];
 
337
}
 
338
 
 
339
@end /* VCardSaxDriver */