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 #import <NGObjWeb/SoObject.h>
23 #import <GDLContentStore/GCSFolderManager.h>
24 #import <GDLContentStore/GCSFolder.h>
25 #import <GDLContentStore/GCSFolderType.h>
27 #import "SOGoFolder.h"
32 #import "SOGoAclsFolder.h"
34 @implementation SOGoFolder
37 return [super version] + 0 /* v0 */;
40 NSAssert2([super version] == 0,
41 @"invalid superclass (%@) version %i !",
42 NSStringFromClass([self superclass]), [super version]);
45 + (NSString *)globallyUniqueObjectId {
47 4C08AE1A-A808-11D8-AC5A-000393BBAFF6
48 SOGo-Web-28273-18283-288182
49 printf( "%x", *(int *) &f);
52 static int sequence = 0;
53 static float rndm = 0;
56 if (pid == 0) { /* break if we fork ;-) */
61 f = [[NSDate date] timeIntervalSince1970];
62 return [NSString stringWithFormat:@"%0X-%0X-%0X-%0X",
63 pid, *(int *)&f, sequence++, random];
67 [self->ocsFolder release];
68 [self->ocsPath release];
78 - (void)setOCSPath:(NSString *)_path {
79 if ([self->ocsPath isEqualToString:_path])
83 [self warnWithFormat:@"GCS path is already set! '%@'", _path];
85 ASSIGNCOPY(self->ocsPath, _path);
88 - (NSString *)ocsPath {
92 - (GCSFolderManager *)folderManager {
93 static GCSFolderManager *folderManager = nil;
97 folderManager = [GCSFolderManager defaultFolderManager];
98 [folderManager setFolderNamePrefix: @"SOGo_"];
101 return folderManager;
104 - (GCSFolder *)ocsFolderForPath:(NSString *)_path {
105 return [[self folderManager] folderAtPath:_path];
108 - (GCSFolder *) ocsFolder {
112 ocsFolder = [[self ocsFolderForPath:[self ocsPath]] retain];
114 if ([ocsFolder isNotNull])
122 - (NSString *) folderType
131 result = [[self folderManager] createFolderOfType: [self folderType]
134 return (result == nil);
137 - (NSException *) delete
139 return [[self folderManager] deleteFolderAtPath: ocsPath];
142 - (NSArray *)fetchContentObjectNames {
143 NSArray *fields, *records;
145 fields = [NSArray arrayWithObject:@"c_name"];
146 records = [[self ocsFolder] fetchFields:fields matchingQualifier:nil];
147 if (![records isNotNull]) {
148 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
151 if ([records isKindOfClass:[NSException class]])
153 return [records valueForKey:@"c_name"];
156 - (BOOL) nameExistsInFolder: (NSString *) objectName
158 NSArray *fields, *records;
159 EOQualifier *qualifier;
162 = [EOQualifier qualifierWithQualifierFormat:
163 [NSString stringWithFormat: @"c_name='%@'", objectName]];
165 fields = [NSArray arrayWithObject: @"c_name"];
166 records = [[self ocsFolder] fetchFields: fields
167 matchingQualifier: qualifier];
169 && ![records isKindOfClass:[NSException class]]
170 && [records count] > 0);
173 - (NSDictionary *)fetchContentStringsAndNamesOfAllObjects {
176 files = [[self ocsFolder] fetchContentsOfAllFiles];
177 if (![files isNotNull]) {
178 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
181 if ([files isKindOfClass:[NSException class]])
188 - (NSString *)defaultFilenameExtension {
190 Override to add an extension to a filename
192 Note: be careful with that, needs to be consistent with object lookup!
197 - (NSArray *) davResourceType
199 NSArray *rType, *groupDavCollection;
201 if ([self respondsToSelector: @selector (groupDavResourceType)])
203 groupDavCollection = [NSArray arrayWithObjects: [self groupDavResourceType],
204 @"http://groupdav.org/", @"G", nil];
205 rType = [NSArray arrayWithObjects: @"collection", groupDavCollection, nil];
208 rType = [NSArray arrayWithObject: @"collection"];
213 - (NSArray *) toOneRelationshipKeys {
214 /* toOneRelationshipKeys are the 'files' contained in a folder */
217 NSString *name, *ext;
221 names = [self fetchContentObjectNames];
222 count = [names count];
223 ext = [self defaultFilenameExtension];
224 if (count && [ext length] > 0)
226 ma = [NSMutableArray arrayWithCapacity: count];
227 for (i = 0; i < count; i++)
229 name = [names objectAtIndex: i];
230 r = [name rangeOfString: @"."];
232 name = [[name stringByAppendingString:@"."] stringByAppendingString: ext];
244 - (BOOL)davIsCollection {
245 return [self isFolderish];
250 - (NSString *)outlookFolderClass {
256 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
257 [super appendAttributesToDescription:_ms];
259 [_ms appendFormat:@" ocs=%@", [self ocsPath]];
262 - (NSString *)loggingPrefix {
263 return [NSString stringWithFormat:@"<0x%08X[%@]:%@>",
264 self, NSStringFromClass([self class]),
265 [self nameInContainer]];
268 @end /* SOGoFolder */