]> err.no Git - scalable-opengroupware.org/commitdiff
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1044 d1b88da0-ebda-0310...
authorwolfgang <wolfgang@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 10 Apr 2007 20:44:24 +0000 (20:44 +0000)
committerwolfgang <wolfgang@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 10 Apr 2007 20:44:24 +0000 (20:44 +0000)
ChangeLog
OGoContentStore/OCSContactFieldExtractor.m
SoObjects/Contacts/SOGoContactGCSEntry.m

index 3169fec90f83055aab65c38f4dbd8f5fe4445c30..60b5ef6e7049a5428cc023e255417d65e2b42775 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-04-10  Wolfgang Sourdeau  <wsourdeau@inverse.ca>
+
+       * SoObjects/Contacts/SOGoContactGCSEntry.m ([SOGoContactGCSEntry
+       -vCard]): test the prefix of the card in a case-independent way.
+
+       * OGoContentStore/OCSContactFieldExtractor.m
+       ([OCSContactFieldExtractor
+       -extractQuickFieldsFromContent:content]): we no longer accept
+       records in a format other than versit vCard so we can get rid of a
+       lot of code.
+
 2007-04-04  Wolfgang Sourdeau  <wsourdeau@inverse.ca>
 
        * UI/Contacts/UIxContactsListView.m ([UIxContactsListView
index 5ca2024fd6532f9a9af76baa6d390a02b048cda3..675ea7e8d181700a85b878b6fd001dd066939e13 100644 (file)
   02111-1307, USA.
 */
 
-#include <GDLContentStore/GCSFieldExtractor.h>
+#import <GDLContentStore/GCSFieldExtractor.h>
+#import <NGCards/NGVCard.h>
+#import "common.h"
 
 @interface OCSContactFieldExtractor : GCSFieldExtractor
 @end
 
-#include <NGCards/NGVCard.h>
-#include "common.h"
-
 @implementation OCSContactFieldExtractor
 
-static NSString *fieldNames[] = {
-  /* quickfield,      vCard KVC path */
-  @"givenName",       @"n.given",
-  @"cn",              @"fn.stringValue",
-  @"sn",              @"n.family",
-  @"l",               @"preferredAdr.locality",
-  @"mail",            @"preferredEMail.stringValue",
-  @"o",               @"org.orgnam",
-  @"ou",              @"org.orgunit",
-  @"telephoneNumber", @"preferredTel.stringValue",
-  nil, nil
-};
-
 - (NSMutableDictionary *) extractQuickFieldsFromVCard: (NGVCard *) vCard
 {
   NSMutableDictionary *fields;
@@ -50,10 +36,7 @@ static NSString *fieldNames[] = {
   NSString *value;
   unsigned int max;
 
-  if (vCard == nil)
-    return nil;
-
-  fields = [NSMutableDictionary dictionaryWithCapacity:16];
+  fields = [NSMutableDictionary dictionaryWithCapacity: 16];
 
   value = [vCard fn];
   if (value)
@@ -93,57 +76,24 @@ static NSString *fieldNames[] = {
   return fields;
 }
 
-- (NSMutableDictionary *)extractQuickFieldsFromVCardString:(NSString *)_str {
+- (NSMutableDictionary *) extractQuickFieldsFromContent: (NSString *) content
+{
+  NSMutableDictionary *fields;
   NGVCard *vCard;
-  
-  if ((vCard = [NGVCard parseSingleFromSource: _str]) == nil) {
-    [self errorWithFormat:@"Could not parse content as a vCard."];
-    return nil;
-  }
-  
-  return [self extractQuickFieldsFromVCard: vCard];
-}
 
-- (NSMutableDictionary *)extractQuickFieldsFromContent:(NSString *)_content {
-  NSMutableDictionary *fields;
-  NSDictionary *plist;
-  unsigned i;
-  
-  if ([_content length] == 0)
-    return nil;
-  
-  if ([_content hasPrefix:@"BEGIN:VCARD"])
-    return [self extractQuickFieldsFromVCardString:_content];
-  
-  // TODO: we want to support vcard storage in the future?!
-  
-  if ((plist = [_content propertyList]) == nil) {
-    [self logWithFormat:@"ERROR: could not parse property list content!"];
-    return nil;
-  }
-  
-  if (![plist isKindOfClass:[NSDictionary class]]) {
-    [self logWithFormat:@"ERROR: parsed property list is not a dictionary!"];
-    return nil;
-  }
-  
-  fields = [NSMutableDictionary dictionaryWithCapacity:16];
-  
-  /* copy field values to quick record */
-  for (i = 0; fieldNames[i] != nil; i += 2) {
-    NSString *fieldName, *sqlName;
-    id value;
-    
-    fieldName = fieldNames[i];
-    sqlName   = [fieldName lowercaseString]; /* actually pgsql doesn't care */
-    
-    value = [plist objectForKey:fieldName];
-    if ([value isNotNull])
-      [fields setObject:value forKey:sqlName];
-    else
-      [fields setObject:[NSNull null] forKey:sqlName];
-  }
-  
+  fields = nil;
+  if ([content length] > 0
+      && [[content uppercaseString] hasPrefix: @"BEGIN:VCARD"])
+    {
+      vCard = [NGVCard parseSingleFromSource: content];
+      if (vCard)
+       fields = [self extractQuickFieldsFromVCard: vCard];
+      else
+       [self errorWithFormat: @"Could not parse content as a vCard."];
+    }
+  else
+    [self errorWithFormat: @"Content is not a vCard"];
+
   return fields;
 }
 
index 1dde518e92c4f07e5e70bfad685b8f923b802316..39aca0a4b2fb8396d71e63cb73dbec4dc7d99908 100644 (file)
@@ -54,7 +54,7 @@
   if (!card)
     {
       contentStr = [self contentAsString];
-      if ([contentStr hasPrefix:@"BEGIN:VCARD"])
+      if ([[contentStr uppercaseString] hasPrefix:@"BEGIN:VCARD"])
         card = [NGVCard parseSingleFromSource: contentStr];
       else
         card = [NGVCard cardWithUid: [self nameInContainer]];