/* 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 "SOGoContentObject.h" #include "common.h" #include @implementation SOGoContentObject - (void)dealloc { [self->content release]; [self->ocsPath release]; [super dealloc]; } /* notifications */ - (void)sleep { [self->content release]; self->content = nil; [super sleep]; } /* accessors */ - (BOOL)isFolderish { return NO; } - (void)setOCSPath:(NSString *)_path { if ([self->ocsPath isEqualToString:_path]) return; if (self->ocsPath) [self warnWithFormat:@"OCS path is already set! '%@'", _path]; ASSIGNCOPY(self->ocsPath, _path); } - (NSString *)ocsPath { if (self->ocsPath == nil) { NSString *p; if ((p = [self ocsPathOfContainer]) != nil) { if (![p hasSuffix:@"/"]) p = [p stringByAppendingString:@"/"]; p = [p stringByAppendingString:[self nameInContainer]]; self->ocsPath = [p copy]; } } return self->ocsPath; } - (NSString *)ocsPathOfContainer { if (![[self container] respondsToSelector:@selector(ocsPath)]) return nil; return [[self container] ocsPath]; } - (OCSFolder *)ocsFolder { if (![[self container] respondsToSelector:@selector(ocsFolder)]) return nil; return [[self container] ocsFolder]; } /* content */ - (NSString *)contentAsString { OCSFolder *folder; if (self->content != nil) return self->content; if ((folder = [self ocsFolder]) == nil) { [self logWithFormat:@"did not find folder of appointment."]; return nil; } self->content = [[folder fetchContentWithName:[self nameInContainer]] copy]; return self->content; } - (NSException *)saveContentString:(NSString *)_str { /* Note: "iCal multifolder saves" are implemented in the apt subclass! */ OCSFolder *folder; NSException *ex; if ((folder = [self ocsFolder]) == nil) { [self logWithFormat:@"did not find folder of appointment."]; return nil; } if ((ex = [folder writeContent:_str toName:[self nameInContainer]])) { [self logWithFormat:@"write failed: %@", ex]; return ex; } return nil; } - (NSException *)delete { /* Note: "iCal multifolder saves" are implemented in the apt subclass! */ OCSFolder *folder; NSException *ex; if ((folder = [self ocsFolder]) == nil) { [self logWithFormat:@"did not find folder of appointment."]; return nil; } if ((ex = [folder deleteContentWithName:[self nameInContainer]])) { [self logWithFormat:@"delete failed: %@", ex]; return ex; } return nil; } /* actions */ - (id)PUTAction:(WOContext *)_ctx { WORequest *rq; NSException *error; rq = [_ctx request]; if ((error = [self saveContentString:[rq contentAsString]]) != nil) return error; // TODO: this should be automatic if we return nil? [[_ctx response] setStatus:201 /* Created */]; return [_ctx response]; } /* WebDAV */ - (BOOL)davIsCollection { return [self isFolderish]; } /* message type */ - (NSString *)outlookMessageClass { return nil; } /* description */ - (void)appendAttributesToDescription:(NSMutableString *)_ms { [super appendAttributesToDescription:_ms]; [_ms appendFormat:@" ocs=%@", [self ocsPath]]; } @end /* SOGoContentObject */