]> err.no Git - sope/blobdiff - sope-ical/versitSaxDriver/VSSaxDriver.m
converted all Xcode projects from Xcode < 2.1 to 2.1
[sope] / sope-ical / versitSaxDriver / VSSaxDriver.m
index 4f0881be084aa0abb018fa10bce188d7189bd836..722e3a712df2fb30d6ba27f99183202142678c83 100644 (file)
@@ -24,6 +24,7 @@
 #include "VSSaxDriver.h"
 #include "VSStringFormatter.h"
 #include <SaxObjC/SaxException.h>
+#include <NGExtensions/NGQuotedPrintableCoding.h>
 #include "common.h"
 
 @interface VSSaxTag : NSObject
@@ -45,6 +46,7 @@
 - (id)initWithContentString:(NSString *)_data;
 
 - (NSString *)tagName;
+- (NSString *)group;
 - (BOOL)isStartTag;
 - (BOOL)isEndTag;
 - (BOOL)isTag;
@@ -381,8 +383,8 @@ static VSStringFormatter *stringFormatter = nil;
 
   if (_attrs == nil || [_attrs count] == 0)
     return nil;
-
-  attributes = [[NSMutableDictionary alloc] init];
+  
+  attributes = [[NSMutableDictionary alloc] initWithCapacity:4];
   retAttrs   = [[[SaxAttributes alloc] init] autorelease];
   
   attrEnum = [_attrs objectEnumerator];
@@ -391,11 +393,14 @@ static VSStringFormatter *stringFormatter = nil;
           forTag:_tagName
           intoAttr:&mappedAttr
           intoValue:&mappedValue];
-    if ((oldValue = [attributes objectForKey:mappedAttr])) {
+    if ((oldValue = [attributes objectForKey:mappedAttr]) != nil) {
       NSString *val;
+      
       /* ZNeK: duh! */
-      val = [NSString stringWithFormat:@"%@ %@",oldValue, mappedValue];
+      // TODO: hh asks: what does 'duh' is supposed to mean?
+      val = [[NSString alloc] initWithFormat:@"%@ %@",oldValue, mappedValue];
       [attributes setObject:val forKey:mappedAttr];
+      [val release];
     }
     else  
       [attributes setObject:mappedValue forKey:mappedAttr];
@@ -403,6 +408,16 @@ static VSStringFormatter *stringFormatter = nil;
 
   attrEnum = [attributes keyEnumerator];
   while ((curAttr = [attrEnum nextObject]) != nil) {
+    /*
+      TODO: values are not always mapped to CDATA! Eg in the dawson draft:
+        | TYPE for TEL   | tel.type   | NMTOKENS  | 'VOICE'         |
+        | TYPE for EMAIL | email.type | NMTOKENS  | 'INTERNET'      |
+        | TYPE for PHOTO,| img.type   | CDATA     | REQUIRED        |
+        |  and LOGO      |            |           |                 |
+        | TYPE for SOUND | aud.type   | CDATA     | REQUIRED        |
+        | VALUE          | value      | NOTATION  | See elements    |
+    */
+    
     [retAttrs addAttribute:curAttr uri:self->prefixURI rawName:curAttr
              type:@"CDATA" value:[attributes objectForKey:curAttr]];
   }
@@ -764,9 +779,16 @@ static VSStringFormatter *stringFormatter = nil;
     [self _endComponent:tagName value:tagValue];
   }
   else {
+    // TODO: make this more generic, this one is used with Outlook vCards
+    if ([tagAttributes containsObject:@"ENCODING=QUOTED-PRINTABLE"]) {
+      // TODO: QP is charset specific! The one below decodes in Unicode!
+      tagValue = [tagValue stringByDecodingQuotedPrintable];
+      [tagAttributes removeObject:@"ENCODING=QUOTED-PRINTABLE"];
+    }
+    
     [self _reportContentAsTag:[self _mapTagName:tagName]
          group:[self _groupFromTagName:tagName]
-         withAttrs:[self _mapAttrs:tagAttributes forTag:tagName] 
+         withAttrs:[self _mapAttrs:tagAttributes forTag:tagName]
          andContent:tagValue];
   }