2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "SoWebDAVValue.h"
26 @implementation SoWebDAVValue
28 + (id)valueForObject:(id)_obj attributes:(NSDictionary *)_attrs {
29 return [[[self alloc] initWithObject:_obj attributes:_attrs] autorelease];
31 - (id)initWithObject:(id)_obj attributes:(NSDictionary *)_attrs {
32 if ((self = [super init])) {
33 self->object = [_obj retain];
34 self->attributes = [_attrs copy];
39 return [self initWithObject:nil attributes:nil];
43 [self->object release];
44 [self->attributes release];
48 - (NSString *)stringForTag:(NSString *)_key rawName:(NSString *)_extName
50 prefixes:(NSDictionary *)_prefixes
53 NSMutableDictionary *encNS = nil;
55 ms = [NSMutableString stringWithCapacity:16];
57 [ms appendString:@"<"];
58 [ms appendString:_extName];
60 /* process attributes */
61 if (self->attributes) {
65 keys = [self->attributes keyEnumerator];
66 while ((key = [keys nextObject])) {
69 vs = [[self->attributes objectForKey:key] stringValue];
75 encNS = [NSMutableDictionary dictionaryWithCapacity:16];
77 a = [key xmlLocalName];
78 ns = [key xmlNamespaceURI];
80 if ((p = [encNS objectForKey:ns]) == nil) {
81 if ((p = [_prefixes objectForKey:ns]) == nil) {
82 p = [NSString stringWithFormat:@"a%i", [encNS count]];
83 [encNS setObject:p forKey:ns];
84 [ms appendString:@" xmlns:"];
86 [ms appendString:@"=\""];
88 [ms appendString:@"\""];
91 [encNS setObject:p forKey:ns];
94 [ms appendString:@" "];
96 [ms appendString:@":"];
100 [ms appendString:@" "];
101 [ms appendString:key];
104 [ms appendString:@"=\""];
105 [ms appendString:vs];
106 [ms appendString:@"\""];
109 if (self->object == nil) {
110 [ms appendString:@"/>"];
114 [ms appendString:@">"];
116 //s = [self stringForValue:value ofProperty:key prefixes:nsToPrefix];
117 [ms appendString:[self->object stringValue]];
119 [ms appendString:@"</"];
120 [ms appendString:_extName];
121 [ms appendString:@">"];
127 - (NSString *)propertyListStringWithLocale:(id)_locale indent:(unsigned)_i {
128 return [self->object propertyListStringWithLocale:_locale indent:_i];
131 - (NSString *)stringValue {
132 return [self->object stringValue];
135 @end /* SoWebDAVValue */