2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
22 #include "SOGoObject.h"
23 #include "SOGoUserFolder.h"
26 @interface SOGoObject(Content)
27 - (NSString *)contentAsString;
30 @implementation SOGoObject
32 - (BOOL)doesRetainContainer {
36 - (id)initWithName:(NSString *)_name inContainer:(id)_container {
37 if ((self = [super init])) {
38 self->nameInContainer = [_name copy];
40 [self doesRetainContainer] ? [_container retain] : _container;
45 return [self initWithName:nil inContainer:nil];
49 if ([self doesRetainContainer])
50 [self->container release];
51 [self->nameInContainer release];
57 - (NSString *)nameInContainer {
58 return self->nameInContainer;
61 return self->container;
66 - (NSString *)ownerInContext:(id)_ctx {
67 return [[self container] ownerInContext:_ctx];
72 - (NSArray *)fetchSubfolders {
77 if ((names = [self toManyRelationshipKeys]) == nil)
80 count = [names count];
81 ma = [NSMutableArray arrayWithCapacity:count + 1];
82 for (i = 0; i < count; i++) {
85 folder = [self lookupName:[names objectAtIndex:i] inContext:nil
89 if ([folder isKindOfClass:[NSException class]])
92 [ma addObject:folder];
97 /* looking up shared objects */
99 - (SOGoUserFolder *)lookupUserFolder {
100 if (![self->container respondsToSelector:_cmd])
103 return [self->container lookupUserFolder];
105 - (SOGoGroupsFolder *)lookupGroupsFolder {
106 return [[self lookupUserFolder] lookupGroupsFolder];
110 if ([self doesRetainContainer])
111 [self->container release];
112 self->container = nil;
117 - (NSException *)delete {
118 return [NSException exceptionWithHTTPStatus:501 /* not implemented */
119 reason:@"delete not yet implemented, sorry ..."];
124 - (id)valueForUndefinedKey:(NSString *)_key {
130 - (NSString *)davDisplayName {
131 return [self nameInContainer];
136 - (id)DELETEAction:(id)_ctx {
137 return [self delete];
140 - (id)GETAction:(id)_ctx {
141 // TODO: I guess this should really be done by SOPE (redirect to
148 if ([rq isSoWebDAVRequest]) {
149 if ([self respondsToSelector:@selector(contentAsString)])
150 return [self contentAsString];
152 return [NSException exceptionWithHTTPStatus:501 /* not implemented */
153 reason:@"no WebDAV GET support?!"];
157 if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"];
158 uri = [uri stringByAppendingString:@"view"];
161 [r setStatus:302 /* moved */];
162 [r setHeader:uri forKey:@"location"];
168 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
169 if (self->nameInContainer != nil)
170 [_ms appendFormat:@" name=%@", self->nameInContainer];
171 if (self->container != nil) {
172 [_ms appendFormat:@" container=0x%08X/%@",
173 self->container, [self->container valueForKey:@"nameInContainer"]];
177 - (NSString *)description {
180 ms = [NSMutableString stringWithCapacity:64];
181 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
182 [self appendAttributesToDescription:ms];
183 [ms appendString:@">"];
187 @end /* SOGoObject */