2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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
11 SOPE 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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "SoWebDAVValue.h"
25 @implementation SoWebDAVValue
27 + (id)valueForObject:(id)_obj attributes:(NSDictionary *)_attrs {
28 return [[[self alloc] initWithObject:_obj attributes:_attrs] autorelease];
30 - (id)initWithObject:(id)_obj attributes:(NSDictionary *)_attrs {
31 if ((self = [super init])) {
32 self->object = [_obj retain];
33 self->attributes = [_attrs copy];
38 return [self initWithObject:nil attributes:nil];
42 [self->object release];
43 [self->attributes release];
47 - (NSString *)stringForTag:(NSString *)_key rawName:(NSString *)_extName
49 prefixes:(NSDictionary *)_prefixes
52 NSMutableDictionary *encNS = nil;
54 ms = [NSMutableString stringWithCapacity:16];
56 [ms appendString:@"<"];
57 [ms appendString:_extName];
59 /* process attributes */
60 if (self->attributes) {
64 keys = [self->attributes keyEnumerator];
65 while ((key = [keys nextObject])) {
68 vs = [[self->attributes objectForKey:key] stringValue];
74 encNS = [NSMutableDictionary dictionaryWithCapacity:16];
76 a = [key xmlLocalName];
77 ns = [key xmlNamespaceURI];
79 if ((p = [encNS objectForKey:ns]) == nil) {
80 if ((p = [_prefixes objectForKey:ns]) == nil) {
81 p = [NSString stringWithFormat:@"a%i", [encNS count]];
82 [encNS setObject:p forKey:ns];
83 [ms appendString:@" xmlns:"];
85 [ms appendString:@"=\""];
87 [ms appendString:@"\""];
90 [encNS setObject:p forKey:ns];
93 [ms appendString:@" "];
95 [ms appendString:@":"];
99 [ms appendString:@" "];
100 [ms appendString:key];
103 [ms appendString:@"=\""];
104 [ms appendString:vs];
105 [ms appendString:@"\""];
108 if (self->object == nil) {
109 [ms appendString:@"/>"];
113 [ms appendString:@">"];
115 //s = [self stringForValue:value ofProperty:key prefixes:nsToPrefix];
116 [ms appendString:[self->object stringValue]];
118 [ms appendString:@"</"];
119 [ms appendString:_extName];
120 [ms appendString:@">"];
126 - (NSString *)propertyListStringWithLocale:(id)_locale indent:(unsigned)_i {
127 return [self->object propertyListStringWithLocale:_locale indent:_i];
130 - (NSString *)stringValue {
131 return [self->object stringValue];
134 @end /* SoWebDAVValue */