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>
24 #include "SOGoFolder.h"
26 #include <GDLContentStore/GCSFolderManager.h>
27 #include <GDLContentStore/GCSFolder.h>
31 #import "SOGoAclsFolder.h"
33 @implementation SOGoFolder
36 return [super version] + 0 /* v0 */;
39 NSAssert2([super version] == 0,
40 @"invalid superclass (%@) version %i !",
41 NSStringFromClass([self superclass]), [super version]);
44 + (NSString *)globallyUniqueObjectId {
46 4C08AE1A-A808-11D8-AC5A-000393BBAFF6
47 SOGo-Web-28273-18283-288182
48 printf( "%x", *(int *) &f);
51 static int sequence = 0;
52 static float rndm = 0;
55 if (pid == 0) { /* break if we fork ;-) */
60 f = [[NSDate date] timeIntervalSince1970];
61 return [NSString stringWithFormat:@"%0X-%0X-%0X-%0X",
62 pid, *(int *)&f, sequence++, random];
66 [self->ocsFolder release];
67 [self->ocsPath release];
77 - (void)setOCSPath:(NSString *)_path {
78 if ([self->ocsPath isEqualToString:_path])
82 [self warnWithFormat:@"GCS path is already set! '%@'", _path];
84 ASSIGNCOPY(self->ocsPath, _path);
86 - (NSString *)ocsPath {
90 - (GCSFolderManager *)folderManager {
91 return [GCSFolderManager defaultFolderManager];
94 - (GCSFolder *)ocsFolderForPath:(NSString *)_path {
95 return [[self folderManager] folderAtPath:_path];
98 - (GCSFolder *) ocsFolder {
102 ocsFolder = [[self ocsFolderForPath:[self ocsPath]] retain];
104 if ([ocsFolder isNotNull])
112 - (NSArray *)fetchContentObjectNames {
113 NSArray *fields, *records;
115 fields = [NSArray arrayWithObject:@"c_name"];
116 records = [[self ocsFolder] fetchFields:fields matchingQualifier:nil];
117 if (![records isNotNull]) {
118 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
121 if ([records isKindOfClass:[NSException class]])
123 return [records valueForKey:@"c_name"];
126 - (NSDictionary *)fetchContentStringsAndNamesOfAllObjects {
129 files = [[self ocsFolder] fetchContentsOfAllFiles];
130 if (![files isNotNull]) {
131 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
134 if ([files isKindOfClass:[NSException class]])
141 - (NSString *)defaultFilenameExtension {
143 Override to add an extension to a filename
145 Note: be careful with that, needs to be consistent with object lookup!
150 - (NSArray *) davResourceType
152 NSArray *rType, *groupDavCollection;
154 if ([self respondsToSelector: @selector (groupDavResourceType)])
156 groupDavCollection = [NSArray arrayWithObjects: [self groupDavResourceType],
157 @"http://groupdav.org/", @"G", nil];
158 rType = [NSArray arrayWithObjects: @"collection", groupDavCollection, nil];
161 rType = [NSArray arrayWithObject: @"collection"];
166 - (NSArray *) toOneRelationshipKeys {
167 /* toOneRelationshipKeys are the 'files' contained in a folder */
170 NSString *name, *ext;
174 names = [self fetchContentObjectNames];
175 count = [names count];
176 ext = [self defaultFilenameExtension];
177 if (count && [ext length] > 0)
179 ma = [NSMutableArray arrayWithCapacity: count];
180 for (i = 0; i < count; i++)
182 name = [names objectAtIndex: i];
183 r = [name rangeOfString: @"."];
185 name = [[name stringByAppendingString:@"."] stringByAppendingString: ext];
197 - (BOOL)davIsCollection {
198 return [self isFolderish];
203 - (NSString *)outlookFolderClass {
209 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
210 [super appendAttributesToDescription:_ms];
212 [_ms appendFormat:@" ocs=%@", [self ocsPath]];
215 - (NSString *)loggingPrefix {
216 return [NSString stringWithFormat:@"<0x%08X[%@]:%@>",
217 self, NSStringFromClass([self class]),
218 [self nameInContainer]];
221 @end /* SOGoFolder */