- (BOOL)renderObjectBodyResult:(id)_object inContext:(WOContext *)_ctx
onlyHead:(BOOL)_onlyHead
{
- WOResponse *r = [_ctx response];
+ WOResponse *r;
NSString *tmp;
+ unsigned char buf[128];
+
+ r = [_ctx response];
/*
TODO: implement proper etag support. This probably implies that we need
We cannot use davEntityTag on the input parameter, since this is
usually the plain object.
*/
- tmp = @"0"; // fallback, cannot use the thing above
- [r setHeader:tmp forKey:@"ETag"]; // required for WebFolder PUTs
+ if ((tmp = [r headerForKey:@"etag"]) == nil) {
+ tmp = @"0"; // fallback, cannot use the thing above
+ [r setHeader:tmp forKey:@"etag"]; // required for WebFolder PUTs
+ }
if ([_object isKindOfClass:[NSData class]]) {
[r setHeader:[self mimeTypeForData:_object inContext:_ctx]
forKey:@"content-type"];
- [r setHeader:[NSString stringWithFormat:@"%d", [_object length]]
- forKey:@"content-length"];
+ sprintf(buf, "%d", [_object length]);
+ [r setHeader:[NSString stringWithCString:buf] forKey:@"content-length"];
if (!_onlyHead) [r setContent:_object];
return YES;
}
-
+
if ([_object isKindOfClass:[NSString class]]) {
NSData *data;
forKey:@"content-type"];
data = [_object dataUsingEncoding:NSUTF8StringEncoding];
- [r setHeader:[NSString stringWithFormat:@"%d", [data length]]
- forKey:@"content-length"];
+ sprintf(buf, "%d", [data length]);
+ [r setHeader:[NSString stringWithCString:buf] forKey:@"content-length"];
[r setContent:data];
return YES;
}
return YES;
}
+- (NSString *)stringForResourceType:(id)_value ofProperty:(NSString *)_prop
+ prefixes:(NSDictionary *)_prefixes
+{
+ NSString *davNS;
+
+ davNS = [_prefixes objectForKey:@"DAV:"];
+
+ if ([_value isKindOfClass:[NSArray class]]) {
+ /*
+ Use arrays to allow for something like this:
+ <collection/>
+ <C:todos xmlns:C="urn:ietf:params:xml:ns:caldav"/>
+ Item Format:
+ ( TAG ) => tag in DAV: namespace
+ ( TAG, NS ) => tag in NS namespace
+ ( TAG, NS, PREFIX ) => tag in NS namespace with PREFIX
+ */
+ NSMutableString *ms;
+ NSEnumerator *e;
+ id item;
+
+ if ([_value count] == 0)
+ return nil;
+
+ ms = [NSMutableString stringWithCapacity:16];
+ e = [_value objectEnumerator];
+ while ((item = [e nextObject]) != nil) {
+ unsigned count;
+
+ if (![item isKindOfClass:[NSArray class]]) {
+ item = [item stringValue];
+ if ([item length] == 0) continue;
+ [ms appendFormat:@"<%@:%@ />", davNS, item];
+ continue;
+ }
+
+ /* process array tags */
+
+ 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]];
+ }
+ else {
+ /* 0=tag, 1=nsuri, 2=nsprefix */
+ [ms appendFormat:@"<%@:%@ xmlns:%@=\"%@\" />",
+ [item objectAtIndex:2], [item objectAtIndex:0],
+ [item objectAtIndex:2], [item objectAtIndex:1]];
+ }
+ }
+ return ms;
+ }
+
+ _value = [_value stringValue];
+ if ([_value length] == 0) return nil;
+
+ return [NSString stringWithFormat:@"<%@:%@/>", davNS, _value];
+}
- (NSString *)stringForValue:(id)_value ofProperty:(NSString *)_prop
prefixes:(NSDictionary *)_prefixes
{
/* special processing for some properties */
if ([_prop isEqualToString:@"{DAV:}resourcetype"]) {
- _value = [_value stringValue];
- if ([_value length] == 0) return nil;
-
- return [NSString stringWithFormat:@"<%@:%@/>",
- [_prefixes objectForKey:@"DAV:"], _value];
+ return [self stringForResourceType:_value ofProperty:_prop
+ prefixes:_prefixes];
}
else if ([_prop isEqualToString:@"{DAV:}creationdate"])
datefmt = @"%Y-%m-%dT%H:%M:%S%zZ";