]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WebDAV/SoObjectResultEntry.m
improved WebDAV property handling
[sope] / sope-appserver / NGObjWeb / WebDAV / SoObjectResultEntry.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 "SoObjectResultEntry.h"
23 #include "common.h"
24
25 @implementation SoObjectResultEntry
26
27 static BOOL debugOn = NO;
28
29 - (id)initWithURI:(NSString *)_href object:(id)_o values:(NSDictionary *)_d {
30   if ((self = [super init])) {
31     if (debugOn) {
32       // TODO: this happens if we access using Goliath
33       if ([_href hasPrefix:@"http:/"] && ![_href hasPrefix:@"http://"]) {
34         [self logWithFormat:@"BROKEN URL: %@", _href];
35         [self release];
36         //abort();
37         return nil;
38       }
39     }
40     
41     self->href   = [_href copy];
42     self->values = [_d retain];
43     self->object = [_o retain];
44   }
45   return self;
46 }
47 - (id)init {
48   return [self initWithURI:nil object:nil values:nil];
49 }
50
51 - (void)dealloc {
52   [self->href   release];
53   [self->values release];
54   [self->object release];
55   [super dealloc];
56 }
57
58 /* keys */
59
60 - (NSArray *)attributeKeys {
61   return [self->values allKeys];
62 }
63
64 /* dict */
65
66 - (NSArray *)allKeys {
67   return [self->values allKeys];
68 }
69 - (NSEnumerator *)keyEnumerator {
70   return [self->values keyEnumerator];
71 }
72 - (id)objectForKey:(id)_key {
73   return [self->values objectForKey:_key];
74 }
75
76 /* KVC */
77
78 - (BOOL)kvcIsPreferredInKeyPath {
79   /*
80     This is difficult to grasp. It says, that the WOKeyPathAssociation
81     should *always* use -valueForKey:, even if the object has an accessors
82     method matching the key.
83     It's required for all "storage" type objects.
84   */
85   return YES;
86 }
87
88 - (id)valueForKey:(NSString *)_key {
89   if ([_key isEqualToString:@"{DAV:}href"])
90     return self->href;
91   
92   if ([_key isEqualToString:@"{DAV:}status"])
93     return nil;
94   
95   if (!debugOn)
96     return [self->values objectForKey:_key];
97   
98   {
99     id v = [self->values objectForKey:_key];
100     [self logWithFormat:@"key %@: %@", _key, v];
101     return v;
102   }
103 }
104
105 /* description */
106
107 - (NSString *)description {
108   NSMutableString *ms;
109   
110   ms = [NSMutableString stringWithCapacity:64];
111   [ms appendFormat:@"<0x%p[%@]:", self,
112         NSStringFromClass((Class)*(void**)self)];
113   
114   if (self->href)
115     [ms appendFormat:@" uri=%@", self->href];
116
117   if (self->object) {
118     [ms appendFormat:@" obj=0x%p[%@]", 
119           self->object, NSStringFromClass([self->object class])];
120   }
121   
122   if ([self->values count] > 0) {
123     NSEnumerator *e;
124     NSString *k;
125     
126     [ms appendString:@" values"];
127     e = [self->values keyEnumerator];
128     while ((k = [e nextObject]))
129       [ms appendFormat:@":%@=%@", k, [self->values objectForKey:k]];
130   }
131   
132   [ms appendString:@">"];
133   return ms;
134 }
135
136 @end /* SoObjectResultEntry */
137
138 @implementation SoObjectErrorEntry
139
140 - (id)initWithURI:(NSString *)_href object:(id)_o error:(NSException *)_e {
141   self->href   = [_href copy];
142   self->error  = [_e retain];
143   self->object = [_o retain];
144   return self;
145 }
146
147 - (void)dealloc {
148   [self->object release];
149   [self->href   release];
150   [self->error  release];
151   [super dealloc];
152 }
153
154 /* dict */
155
156 - (NSArray *)allKeys {
157   return nil;
158 }
159 - (NSEnumerator *)keyEnumerator {
160   return nil;
161 }
162 - (id)objectForKey:(id)_key {
163   return nil;
164 }
165
166 /* KVC */
167
168 - (BOOL)kvcIsPreferredInKeyPath {
169   return YES;
170 }
171
172 - (id)valueForKey:(NSString *)_key {
173   if ([_key isEqualToString:@"{DAV:}href"])
174     return self->href;
175   else if ([_key isEqualToString:@"{DAV:}status"])
176     return self->error;
177   else
178     return nil;
179 }
180
181 /* description */
182
183 - (NSString *)description {
184   NSMutableString *ms;
185   
186   ms = [NSMutableString stringWithCapacity:64];
187   [ms appendFormat:@"<0x%p[%@]:", self,
188         NSStringFromClass((Class)*(void**)self)];
189   
190   if (self->href)
191     [ms appendFormat:@" uri=%@", self->href];
192
193   if (self->object) {
194     [ms appendFormat:@" obj=0x%p[%@]", 
195           self->object, NSStringFromClass([self->object class])];
196   }
197
198   if (self->error)
199     [ms appendFormat:@" error=%@", self->error];
200   
201   [ms appendString:@">"];
202   return ms;
203 }
204
205 @end /* SoObjectErrorEntry */