2 Copyright (C) 2004 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 <Foundation/NSArray.h>
23 #import <Foundation/NSString.h>
25 #import <NGObjWeb/WOContext.h>
26 #import <NGObjWeb/WOContext+SoObjects.h>
28 #import <NGObjWeb/NSException+HTTP.h>
29 #import <NGExtensions/NGLogger.h>
30 #import <NGExtensions/NGLoggerManager.h>
31 #import <NGExtensions/NSObject+Logs.h>
32 #import <NGExtensions/NSNull+misc.h>
34 #import "SOGoGroupFolder.h"
36 @implementation SOGoGroupFolder
38 static NGLogger *logger = nil;
46 lm = [NGLoggerManager defaultLoggerManager];
47 logger = [lm loggerForDefaultKey:@"SOGoGroupFolderDebugEnabled"];
53 [uidToFolder release];
67 [self errorWithFormat:@"instantiated abstract Group folder class!"];
71 /* folder management */
73 - (id)_primaryLookupFolderForUID:(NSString *)_uid inContext:(id)_ctx {
74 NSException *error = nil;
78 /* create subcontext, so that we don't destroy our environment */
80 if ((ctx = [_ctx createSubContext]) == nil) {
81 [self errorWithFormat:@"could not create SOPE subcontext!"];
87 path = _uid != nil ? [NSArray arrayWithObjects:&_uid count:1] : nil;
91 result = [[ctx application] traversePathArray:path inContext:ctx
92 error:&error acquire:NO];
94 [self errorWithFormat:@"folder lookup failed (uid=%@): %@",
100 [self debugWithFormat:@"Note: got folder for uid %@ path %@: %@",
101 _uid, [path componentsJoinedByString:@"=>"], result];
105 - (void)_setupFolders {
106 NSMutableDictionary *md;
111 if (uidToFolder != nil)
113 if ((luids = [self uids]) == nil)
116 count = [luids count];
117 ma = [NSMutableArray arrayWithCapacity:count + 1];
118 md = [NSMutableDictionary dictionaryWithCapacity:count];
120 for (i = 0; i < count; i++) {
124 uid = [luids objectAtIndex:i];
125 folder = [self _primaryLookupFolderForUID:uid inContext: context];
127 if ([folder isNotNull]) {
128 [md setObject:folder forKey:uid];
129 [ma addObject:folder];
132 [ma addObject:[NSNull null]];
136 uidToFolder = [md copy];
137 folders = [[NSArray alloc] initWithArray:ma];
140 - (NSArray *)memberFolders {
141 [self _setupFolders];
145 - (id)folderForUID:(NSString *)_uid {
146 [self _setupFolders];
148 if ([_uid length] == 0)
151 return [uidToFolder objectForKey:_uid];
154 - (void) resetFolderCaches
156 [uidToFolder release];
164 [self resetFolderCaches];
175 /* looking up shared objects */
177 - (SOGoGroupsFolder *) lookupGroupsFolder
179 return [[self container] lookupGroupsFolder];
186 - (id) groupCalendar: (NSString *) _key
189 static Class calClass = Nil;
193 calClass = NSClassFromString(@"SOGoGroupAppointmentFolder");
194 if (calClass == Nil) {
195 [self errorWithFormat:@"missing SOGoGroupAppointmentFolder class!"];
199 calendar = [[calClass alloc] initWithName:_key inContainer:self];
201 // TODO: should we pass over the uids in questions or should the
202 // appointment folder query its container for that info?
204 return [calendar autorelease];
207 - (id) lookupName: (NSString *) _key
209 acquire: (BOOL) _flag
213 /* first check attributes directly bound to the application */
214 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
217 if ([_key isEqualToString:@"Calendar"])
218 return [self groupCalendar:_key inContext:_ctx];
220 /* return 404 to stop acquisition */
221 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
224 @end /* SOGoGroupFolder */