]> err.no Git - scalable-opengroupware.org/blob - SOGo/SoObjects/SOGo/SOGoFolder.m
d8e10aee3c22e6cc8624753ff2749d63dcf91506
[scalable-opengroupware.org] / SOGo / SoObjects / SOGo / SOGoFolder.m
1 /*
2   Copyright (C) 2004-2005 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
22 #include "SOGoFolder.h"
23 #include "common.h"
24 #include <GDLContentStore/GCSFolderManager.h>
25 #include <GDLContentStore/GCSFolder.h>
26
27 @implementation SOGoFolder
28
29 - (void)dealloc {
30   [self->ocsFolder release];
31   [self->ocsPath   release];
32   [super dealloc];
33 }
34
35 /* accessors */
36
37 - (BOOL)isFolderish {
38   return YES;
39 }
40
41 - (void)setOCSPath:(NSString *)_path {
42   if ([self->ocsPath isEqualToString:_path])
43     return;
44   
45   if (self->ocsPath)
46     [self warnWithFormat:@"GCS path is already set! '%@'", _path];
47   
48   ASSIGNCOPY(self->ocsPath, _path);
49 }
50 - (NSString *)ocsPath {
51   return self->ocsPath;
52 }
53
54 - (GCSFolderManager *)folderManager {
55   return [GCSFolderManager defaultFolderManager];
56 }
57 - (GCSFolder *)ocsFolderForPath:(NSString *)_path {
58   return [[self folderManager] folderAtPath:_path];
59 }
60 - (GCSFolder *)ocsFolder {
61   if (self->ocsFolder != nil)
62     return [self->ocsFolder isNotNull] ? self->ocsFolder : nil;
63   
64   self->ocsFolder = [[self ocsFolderForPath:[self ocsPath]] retain];
65   return self->ocsFolder;
66 }
67
68 - (NSArray *)fetchContentObjectNames {
69   NSArray *fields, *records;
70   
71   fields = [NSArray arrayWithObject:@"c_name"];
72   records = [[self ocsFolder] fetchFields:fields matchingQualifier:nil];
73   if (![records isNotNull]) {
74     [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
75     return nil;
76   }
77   if ([records isKindOfClass:[NSException class]])
78     return records;
79   return [records valueForKey:@"c_name"];
80 }
81 - (NSDictionary *)fetchContentStringsAndNamesOfAllObjects {
82   NSDictionary *files;
83   
84   files = [[self ocsFolder] fetchContentsOfAllFiles];
85   if (![files isNotNull]) {
86     [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
87     return nil;
88   }
89   if ([files isKindOfClass:[NSException class]])
90     return files;
91   return files;
92 }
93
94 /* reflection */
95
96 - (NSString *)defaultFilenameExtension {
97   /* 
98      Override to add an extension to a filename
99      
100      Note: be careful with that, needs to be consistent with object lookup!
101   */
102   return nil;
103 }
104
105 - (NSArray *)toOneRelationshipKeys {
106   /* toOneRelationshipKeys are the 'files' contained in a folder */
107   NSMutableArray *ma;
108   NSArray  *names;
109   NSString *ext;
110   unsigned i, count;
111
112   if ((names = [self fetchContentObjectNames]) == nil)
113     return names;
114   
115   if ((count = [names count]) == 0)
116     return names;
117   
118   if ((ext = [self defaultFilenameExtension]) == nil)
119     return names;
120   
121   ma = [NSMutableArray arrayWithCapacity:count];
122   for (i = 0; i < count; i++) {
123     NSRange  r;
124     NSString *name;
125     
126     name = [names objectAtIndex:i];
127     r = [name rangeOfString:@"."];
128     if (r.length == 0)
129       name = [[name stringByAppendingString:@"."] stringByAppendingString:ext];
130     
131     [ma addObject:name];
132   }
133   return ma;
134 }
135
136 /* WebDAV */
137
138 - (BOOL)davIsCollection {
139   return [self isFolderish];
140 }
141
142 /* folder type */
143
144 - (NSString *)outlookFolderClass {
145   return nil;
146 }
147
148 /* description */
149
150 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
151   [super appendAttributesToDescription:_ms];
152   
153   [_ms appendFormat:@" ocs=%@", [self ocsPath]];
154 }
155
156 - (NSString *)loggingPrefix {
157   return [NSString stringWithFormat:@"<0x%08X[%@]:%@>",
158                    self, NSStringFromClass([self class]),
159                    [self nameInContainer]];
160 }
161
162 @end /* SOGoFolder */