From f7672af7e739c71a3968e2831c9204993f5a2bab Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 8 Feb 2007 15:57:18 +0000 Subject: [PATCH] enhanced WebDAV value handling git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1407 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 3 + sope-appserver/NGObjWeb/Version | 2 +- .../NGObjWeb/WebDAV/SoWebDAVRenderer.m | 102 +++++++++++++----- 3 files changed, 80 insertions(+), 27 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index c834d5d3..56719c1a 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,5 +1,8 @@ 2007-02-08 Helge Hess + * WebDAV/SoWebDAVRenderer.m: added support for XML properties which + contain values (v4.5.265) + * DAVPropMap.plist: added mappings for calendar-home-set, dropbox-home-URL and notifications-URL CalDAV properties (v4.5.264) diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index f867e8bd..b613fe43 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,7 +1,7 @@ # version file ifneq ($(GNUSTEP_HOST_VENDOR),apple) # linker overflow -SUBMINOR_VERSION:=264 +SUBMINOR_VERSION:=265 else SUBMINOR_VERSION:=255 endif diff --git a/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m b/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m index b50ff5cc..a2f6459f 100644 --- a/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m +++ b/sope-appserver/NGObjWeb/WebDAV/SoWebDAVRenderer.m @@ -1,6 +1,6 @@ /* - Copyright (C) 2000-2006 SKYRIX Software AG - Copyright (C) 2006 Helge Hess + Copyright (C) 2000-2007 SKYRIX Software AG + Copyright (C) 2007 Helge Hess This file is part of SOPE. @@ -321,12 +321,13 @@ static BOOL formatOutput = NO; return YES; } -- (NSString *)stringForResourceType:(id)_value ofProperty:(NSString *)_prop +- (NSString *)stringForValue:(id)_value ofProperty:(NSString *)_prop prefixes:(NSDictionary *)_prefixes + requireTagValue:(BOOL)_requireTagValue { NSString *davNS; - davNS = [_prefixes objectForKey:@"DAV:"]; + davNS = [_prefixes objectForKey:XMLNS_WEBDAV]; if ([_value isKindOfClass:[NSArray class]]) { /* @@ -334,25 +335,27 @@ static BOOL formatOutput = NO; Item Format: - ( TAG ) => tag in DAV: namespace - ( TAG, NS ) => tag in NS namespace - ( TAG, NS, PREFIX ) => tag in NS namespace with PREFIX + ( TAG ) => tag in DAV: namespace + ( TAG, NS ) => tag in NS namespace + ( TAG, NS, PREFIX ) => tag in NS namespace with PREFIX + ( TAG, NS, PREFIX, val ) => tag in NS namespace with PREFIX and value */ NSMutableString *ms; NSEnumerator *e; id item; - if ([_value count] == 0) + if (![_value isNotEmpty]) return nil; - + ms = [NSMutableString stringWithCapacity:16]; e = [_value objectEnumerator]; while ((item = [e nextObject]) != nil) { + NSString *tag, *ns, *pre; unsigned count; if (![item isKindOfClass:[NSArray class]]) { item = [item stringValue]; - if ([item length] == 0) continue; + if (![item isNotEmpty]) continue; [ms appendFormat:@"<%@:%@ />", davNS, item]; continue; } @@ -361,28 +364,69 @@ static BOOL formatOutput = NO; if ((count = [item count]) == 0) continue; - - if (count == 1) - [ms appendFormat:@"<%@:%@ />", davNS, [item objectAtIndex:0]]; - else if (count == 2) { - /* 0=tag, 1=nsuri */ - [ms appendFormat:@"<%@ xmlns=\"%@\" />", - [item objectAtIndex:0], [item objectAtIndex:1]]; + + tag = [[item objectAtIndex:0] stringValue]; + ns = (count > 1) ? [[item objectAtIndex:1] stringValue] : nil; + pre = (count > 2) ? [[item objectAtIndex:2] stringValue] : davNS; + + [ms appendString:@"<"]; + if (count != 2) { + [ms appendString:pre]; + [ms appendString:@":"]; + } + [ms appendString:tag]; + + if (count == 2) { + [ms appendString:@" xmlns=\""]; + [ms appendString:ns]; + [ms appendString:@"\""]; + } + else if (count > 2) { + [ms appendString:@" xmlns:"]; + [ms appendString:pre]; + [ms appendString:@"=\""]; + [ms appendString:ns]; + [ms appendString:@"\""]; + } + + if (count > 3) { + id value = [item objectAtIndex:3]; + [ms appendString:@">"]; + + if ([value isNotEmpty]) { + /* nested tag */ + [ms appendString:[self stringForValue:value ofProperty:_prop + prefixes:_prefixes requireTagValue:NO]]; + } + + [ms appendString:@""]; } else { - /* 0=tag, 1=nsuri, 2=nsprefix */ - [ms appendFormat:@"<%@:%@ xmlns:%@=\"%@\" />", - [item objectAtIndex:2], [item objectAtIndex:0], - [item objectAtIndex:2], [item objectAtIndex:1]]; + /* no value, close tag */ + [ms appendString:@" />"]; } } return ms; } _value = [_value stringValue]; - if ([_value length] == 0) return nil; + if (![_value isNotEmpty]) return nil; + + if (_requireTagValue) { + /* + This is for properties like 'resourcetype'. davResourceType just + returns 'collection' but gets rendered as '' + */ + return [NSString stringWithFormat:@"<%@:%@/>", davNS, _value]; + } - return [NSString stringWithFormat:@"<%@:%@/>", davNS, _value]; + return _value; } - (NSString *)stringForValue:(id)_value ofProperty:(NSString *)_prop prefixes:(NSDictionary *)_prefixes @@ -398,10 +442,11 @@ static BOOL formatOutput = NO; /* special processing for some properties */ if ([_prop isEqualToString:@"{DAV:}resourcetype"]) { - return [self stringForResourceType:_value ofProperty:_prop - prefixes:_prefixes]; + return [self stringForValue:_value ofProperty:_prop + prefixes:_prefixes requireTagValue:YES]; } - else if ([_prop isEqualToString:@"{DAV:}creationdate"]) + + if ([_prop isEqualToString:@"{DAV:}creationdate"]) datefmt = @"%Y-%m-%dT%H:%M:%S%zZ"; /* special processing for some properties */ @@ -427,6 +472,11 @@ static BOOL formatOutput = NO; locale:nil]; } + if ([_value isKindOfClass:[NSArray class]]) { + return [self stringForValue:_value ofProperty:_prop + prefixes:_prefixes requireTagValue:NO]; + } + return [[_value stringValue] stringByEscapingXMLString]; } -- 2.39.5