]> err.no Git - scalable-opengroupware.org/blob - SOGo/OGoContentStore/OCSContactFieldExtractor.m
863b15f032af41c4ef5c63f6517f1462c143de22
[scalable-opengroupware.org] / SOGo / OGoContentStore / OCSContactFieldExtractor.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include <GDLContentStore/GCSFieldExtractor.h>
23
24 @interface OCSContactFieldExtractor : GCSFieldExtractor
25 @end
26
27 #include "common.h"
28
29 @implementation OCSContactFieldExtractor
30
31 - (NSMutableDictionary *)extractQuickFieldsFromContent:(NSString *)_content {
32   static NSString *fieldNames[] = {
33     @"givenName",
34     @"cn",
35     @"sn",
36     @"l",
37     @"mail",
38     @"o",
39     @"ou",
40     @"telephoneNumber",
41     nil
42   };
43   NSMutableDictionary *fields;
44   NSDictionary *plist;
45   unsigned i;
46   
47   if ([_content length] == 0)
48     return nil;
49   
50   // TODO: we want to support vcard storage in the future?!
51   
52   if ((plist = [_content propertyList]) == nil) {
53     [self logWithFormat:@"ERROR: could not parse property list content!"];
54     return nil;
55   }
56   
57   fields = [NSMutableDictionary dictionaryWithCapacity:16];
58   
59   /* copy field values to quick record */
60   for (i = 0; fieldNames[i] != nil; i++) {
61     NSString *fieldName, *sqlName;
62     id value;
63
64     fieldName = fieldNames[i];
65     sqlName   = [fieldName lowercaseString]; /* actually pgsql doesn't care */
66     
67     value = [plist objectForKey:fieldName];
68     if ([value isNotNull])
69       [fields setObject:value forKey:sqlName];
70     else
71       [fields setObject:[NSNull null] forKey:sqlName];
72   }
73   
74   return fields;
75 }
76
77 @end /* OCSContactFieldExtractor */