]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WebDAV/SoWebDAVValue.m
reverted gstep-base workaround (fixed in gstep-base svn trunk), bumped framework...
[sope] / sope-appserver / NGObjWeb / WebDAV / SoWebDAVValue.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "SoWebDAVValue.h"
23 #include "common.h"
24
25 @implementation SoWebDAVValue
26
27 + (id)valueForObject:(id)_obj attributes:(NSDictionary *)_attrs {
28   return [[[self alloc] initWithObject:_obj attributes:_attrs] autorelease];
29 }
30 - (id)initWithObject:(id)_obj attributes:(NSDictionary *)_attrs {
31   if ((self = [super init])) {
32     self->object     = [_obj   retain];
33     self->attributes = [_attrs copy];
34   }
35   return self;
36 }
37 - (id)init {
38   return [self initWithObject:nil attributes:nil];
39 }
40
41 - (void)dealloc {
42   [self->object     release];
43   [self->attributes release];
44   [super dealloc];
45 }
46
47 - (NSString *)stringForTag:(NSString *)_key rawName:(NSString *)_extName
48   inContext:(id)_ctx
49   prefixes:(NSDictionary *)_prefixes
50 {
51   NSMutableString *ms;
52   NSMutableDictionary *encNS = nil;
53   
54   ms = [NSMutableString stringWithCapacity:16];
55   
56   [ms appendString:@"<"];
57   [ms appendString:_extName];
58   
59   /* process attributes */
60   if (self->attributes) {
61     NSEnumerator *keys;
62     NSString *key;
63     
64     keys = [self->attributes keyEnumerator];
65     while ((key = [keys nextObject])) {
66       NSString *vs;
67       
68       vs = [[self->attributes objectForKey:key] stringValue];
69       
70       if ([key xmlIsFQN]) {
71         NSString *ns, *a, *p;
72         
73         if (encNS == nil)
74           encNS = [NSMutableDictionary dictionaryWithCapacity:16];
75         
76         a  = [key xmlLocalName];
77         ns = [key xmlNamespaceURI];
78         
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:"];
84             [ms appendString:p];
85             [ms appendString:@"=\""];
86             [ms appendString:ns];
87             [ms appendString:@"\""];
88           }
89           else
90             [encNS setObject:p forKey:ns];
91         }
92         
93         [ms appendString:@" "];
94         [ms appendString:p];
95         [ms appendString:@":"];
96         [ms appendString:a];
97       }
98       else {
99         [ms appendString:@" "];
100         [ms appendString:key];
101       }
102       
103       [ms appendString:@"=\""];
104       [ms appendString:vs];
105       [ms appendString:@"\""];
106     }
107   }
108   if (self->object == nil) {
109     [ms appendString:@"/>"];
110     return ms;
111   }
112   
113   [ms appendString:@">"];
114   
115   //s = [self stringForValue:value ofProperty:key prefixes:nsToPrefix];
116   [ms appendString:[self->object stringValue]];
117   
118   [ms appendString:@"</"];
119   [ms appendString:_extName];
120   [ms appendString:@">"];
121   return ms;
122 }
123
124 /* description */
125
126 - (NSString *)propertyListStringWithLocale:(id)_locale indent:(unsigned)_i {
127   return [self->object propertyListStringWithLocale:_locale indent:_i];
128 }
129
130 - (NSString *)stringValue {
131   return [self->object stringValue];
132 }
133
134 @end /* SoWebDAVValue */