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