]> err.no Git - scalable-opengroupware.org/blob - SOGo/SoObjects/SOGo/SOGoContentObject.m
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@135 d1b88da0-ebda-0310-925b-ed51d...
[scalable-opengroupware.org] / SOGo / SoObjects / SOGo / SOGoContentObject.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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 "SOGoContentObject.h"
24 #include "common.h"
25 #include <OGoContentStore/OCSFolder.h>
26
27 @implementation SOGoContentObject
28
29 - (void)dealloc {
30   [self->content release];
31   [self->ocsPath release];
32   [super dealloc];
33 }
34
35 /* accessors */
36
37 - (BOOL)isFolderish {
38   return NO;
39 }
40
41 - (void)setOCSPath:(NSString *)_path {
42   if ([self->ocsPath isEqualToString:_path])
43     return;
44   
45   if (self->ocsPath)
46     [self logWithFormat:@"WARNING: OCS path is already set! '%@'", _path];
47   
48   ASSIGNCOPY(self->ocsPath, _path);
49 }
50
51 - (NSString *)ocsPath {
52   if (self->ocsPath == nil) {
53     NSString *p;
54     
55     if ((p = [self ocsPathOfContainer]) != nil) {
56       if (![p hasSuffix:@"/"]) p = [p stringByAppendingString:@"/"];
57       p = [p stringByAppendingString:[self nameInContainer]];
58       self->ocsPath = [p copy];
59     }
60   }
61   return self->ocsPath;
62 }
63
64 - (NSString *)ocsPathOfContainer {
65   if (![[self container] respondsToSelector:@selector(ocsPath)])
66     return nil;
67
68   return [[self container] ocsPath];
69 }
70
71 - (OCSFolder *)ocsFolder {
72   if (![[self container] respondsToSelector:@selector(ocsFolder)])
73     return nil;
74   
75   return [[self container] ocsFolder];
76 }
77
78 /* content */
79
80 - (NSString *)contentAsString {
81   OCSFolder *folder;
82
83   if (self->content != nil)
84     return self->content;
85
86   if ((folder = [self ocsFolder]) == nil) {
87     [self logWithFormat:@"did not find folder of appointment."];
88     return nil;
89   }
90   
91   self->content = [[folder fetchContentWithName:[self nameInContainer]] copy];
92   return self->content;
93 }
94
95 - (NSException *)saveContentString:(NSString *)_str {
96   OCSFolder   *folder;
97   NSException *ex;
98   
99   if ((folder = [self ocsFolder]) == nil) {
100     [self logWithFormat:@"did not find folder of appointment."];
101     return nil;
102   }
103   
104   if ((ex = [folder writeContent:_str toName:[self nameInContainer]])) {
105     [self logWithFormat:@"write failed: %@", ex];
106     return ex;
107   }
108   
109   return nil;
110 }
111
112 /* description */
113
114 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
115   [super appendAttributesToDescription:_ms];
116   
117   [_ms appendFormat:@" ocs=%@", [self ocsPath]];
118 }
119
120 @end /* SOGoContentObject */