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 return [GCSFolderManager defaultFolderManager];
96 - (GCSFolder *)ocsFolderForPath:(NSString *)_path {
97 return [[self folderManager] folderAtPath:_path];
100 - (GCSFolder *) ocsFolder {
104 ocsFolder = [[self ocsFolderForPath:[self ocsPath]] retain];
106 if ([ocsFolder isNotNull])
114 - (NSString *) folderType
123 [GCSFolderType setFolderNamePrefix: @"SOGo_"];
125 result = [[self folderManager] createFolderOfType: [self folderType]
128 return (result == nil);
131 - (NSArray *)fetchContentObjectNames {
132 NSArray *fields, *records;
134 fields = [NSArray arrayWithObject:@"c_name"];
135 records = [[self ocsFolder] fetchFields:fields matchingQualifier:nil];
136 if (![records isNotNull]) {
137 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
140 if ([records isKindOfClass:[NSException class]])
142 return [records valueForKey:@"c_name"];
145 - (BOOL) nameExistsInFolder: (NSString *) objectName
147 NSArray *fields, *records;
148 EOQualifier *qualifier;
151 = [EOQualifier qualifierWithQualifierFormat:
152 [NSString stringWithFormat: @"c_name='%@'", objectName]];
154 fields = [NSArray arrayWithObject: @"c_name"];
155 records = [[self ocsFolder] fetchFields: fields
156 matchingQualifier: qualifier];
158 && ![records isKindOfClass:[NSException class]]
159 && [records count] > 0);
162 - (NSDictionary *)fetchContentStringsAndNamesOfAllObjects {
165 files = [[self ocsFolder] fetchContentsOfAllFiles];
166 if (![files isNotNull]) {
167 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
170 if ([files isKindOfClass:[NSException class]])
177 - (NSString *)defaultFilenameExtension {
179 Override to add an extension to a filename
181 Note: be careful with that, needs to be consistent with object lookup!
186 - (NSArray *) davResourceType
188 NSArray *rType, *groupDavCollection;
190 if ([self respondsToSelector: @selector (groupDavResourceType)])
192 groupDavCollection = [NSArray arrayWithObjects: [self groupDavResourceType],
193 @"http://groupdav.org/", @"G", nil];
194 rType = [NSArray arrayWithObjects: @"collection", groupDavCollection, nil];
197 rType = [NSArray arrayWithObject: @"collection"];
202 - (NSArray *) toOneRelationshipKeys {
203 /* toOneRelationshipKeys are the 'files' contained in a folder */
206 NSString *name, *ext;
210 names = [self fetchContentObjectNames];
211 count = [names count];
212 ext = [self defaultFilenameExtension];
213 if (count && [ext length] > 0)
215 ma = [NSMutableArray arrayWithCapacity: count];
216 for (i = 0; i < count; i++)
218 name = [names objectAtIndex: i];
219 r = [name rangeOfString: @"."];
221 name = [[name stringByAppendingString:@"."] stringByAppendingString: ext];
233 - (BOOL)davIsCollection {
234 return [self isFolderish];
239 - (NSString *)outlookFolderClass {
245 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
246 [super appendAttributesToDescription:_ms];
248 [_ms appendFormat:@" ocs=%@", [self ocsPath]];
251 - (NSString *)loggingPrefix {
252 return [NSString stringWithFormat:@"<0x%08X[%@]:%@>",
253 self, NSStringFromClass([self class]),
254 [self nameInContainer]];
257 @end /* SOGoFolder */