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 - (NSDictionary *)fetchContentStringsAndNamesOfAllObjects {
148 files = [[self ocsFolder] fetchContentsOfAllFiles];
149 if (![files isNotNull]) {
150 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
153 if ([files isKindOfClass:[NSException class]])
160 - (NSString *)defaultFilenameExtension {
162 Override to add an extension to a filename
164 Note: be careful with that, needs to be consistent with object lookup!
169 - (NSArray *) davResourceType
171 NSArray *rType, *groupDavCollection;
173 if ([self respondsToSelector: @selector (groupDavResourceType)])
175 groupDavCollection = [NSArray arrayWithObjects: [self groupDavResourceType],
176 @"http://groupdav.org/", @"G", nil];
177 rType = [NSArray arrayWithObjects: @"collection", groupDavCollection, nil];
180 rType = [NSArray arrayWithObject: @"collection"];
185 - (NSArray *) toOneRelationshipKeys {
186 /* toOneRelationshipKeys are the 'files' contained in a folder */
189 NSString *name, *ext;
193 names = [self fetchContentObjectNames];
194 count = [names count];
195 ext = [self defaultFilenameExtension];
196 if (count && [ext length] > 0)
198 ma = [NSMutableArray arrayWithCapacity: count];
199 for (i = 0; i < count; i++)
201 name = [names objectAtIndex: i];
202 r = [name rangeOfString: @"."];
204 name = [[name stringByAppendingString:@"."] stringByAppendingString: ext];
216 - (BOOL)davIsCollection {
217 return [self isFolderish];
222 - (NSString *)outlookFolderClass {
228 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
229 [super appendAttributesToDescription:_ms];
231 [_ms appendFormat:@" ocs=%@", [self ocsPath]];
234 - (NSString *)loggingPrefix {
235 return [NSString stringWithFormat:@"<0x%08X[%@]:%@>",
236 self, NSStringFromClass([self class]),
237 [self nameInContainer]];
240 @end /* SOGoFolder */