/* Copyright (C) 2004-2005 SKYRIX Software AG This file is part of OpenGroupware.org. OGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. OGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "SOGoObject.h" #include "SOGoUserFolder.h" #include "common.h" @interface SOGoObject(Content) - (NSString *)contentAsString; @end @implementation SOGoObject - (BOOL)doesRetainContainer { return YES; } - (id)initWithName:(NSString *)_name inContainer:(id)_container { if ((self = [super init])) { self->nameInContainer = [_name copy]; self->container = [self doesRetainContainer] ? [_container retain] : _container; } return self; } - (id)init { return [self initWithName:nil inContainer:nil]; } - (void)dealloc { if ([self doesRetainContainer]) [self->container release]; [self->nameInContainer release]; [super dealloc]; } /* accessors */ - (NSString *)nameInContainer { return self->nameInContainer; } - (id)container { return self->container; } /* ownership */ - (NSString *)ownerInContext:(id)_ctx { return [[self container] ownerInContext:_ctx]; } /* hierarchy */ - (NSArray *)fetchSubfolders { NSMutableArray *ma; NSArray *names; unsigned i, count; if ((names = [self toManyRelationshipKeys]) == nil) return nil; count = [names count]; ma = [NSMutableArray arrayWithCapacity:count + 1]; for (i = 0; i < count; i++) { id folder; folder = [self lookupName:[names objectAtIndex:i] inContext:nil acquire:NO]; if (folder == nil) continue; if ([folder isKindOfClass:[NSException class]]) continue; [ma addObject:folder]; } return ma; } /* looking up shared objects */ - (SOGoUserFolder *)lookupUserFolder { if (![self->container respondsToSelector:_cmd]) return nil; return [self->container lookupUserFolder]; } - (SOGoGroupsFolder *)lookupGroupsFolder { return [[self lookupUserFolder] lookupGroupsFolder]; } - (void)sleep { if ([self doesRetainContainer]) [self->container release]; self->container = nil; } /* operations */ - (NSException *)delete { return [NSException exceptionWithHTTPStatus:501 /* not implemented */ reason:@"delete not yet implemented, sorry ..."]; } /* KVC hacks */ - (id)valueForUndefinedKey:(NSString *)_key { return nil; } /* WebDAV */ - (NSString *)davDisplayName { return [self nameInContainer]; } /* actions */ - (id)DELETEAction:(id)_ctx { return [self delete]; } - (id)GETAction:(id)_ctx { // TODO: I guess this should really be done by SOPE (redirect to // default method) WORequest *rq; WOResponse *r; NSString *uri; rq = [(WOContext *)_ctx request]; if ([rq isSoWebDAVRequest]) { if ([self respondsToSelector:@selector(contentAsString)]) return [self contentAsString]; return [NSException exceptionWithHTTPStatus:501 /* not implemented */ reason:@"no WebDAV GET support?!"]; } uri = [rq uri]; if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"]; uri = [uri stringByAppendingString:@"view"]; r = [(WOContext *)_ctx response]; [r setStatus:302 /* moved */]; [r setHeader:uri forKey:@"location"]; return r; } /* description */ - (void)appendAttributesToDescription:(NSMutableString *)_ms { if (self->nameInContainer != nil) [_ms appendFormat:@" name=%@", self->nameInContainer]; if (self->container != nil) { [_ms appendFormat:@" container=0x%08X/%@", self->container, [self->container valueForKey:@"nameInContainer"]]; } } - (NSString *)description { NSMutableString *ms; ms = [NSMutableString stringWithCapacity:64]; [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; [self appendAttributesToDescription:ms]; [ms appendString:@">"]; return ms; } @end /* SOGoObject */