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
21 // $Id: SOGoGroupFolder.m 115 2004-06-30 11:57:37Z helge $
23 #include "SOGoGroupFolder.h"
26 @implementation SOGoGroupFolder
28 static NGLogger *logger = nil;
32 static BOOL didInit = NO;
37 lm = [NGLoggerManager defaultLoggerManager];
38 logger = [lm loggerForDefaultKey:@"SOGoGroupFolderDebugEnabled"];
42 [self->uidToFolder release];
43 [self->folders release];
56 [self errorWithFormat:@"instantiated abstract Group folder class!"];
60 /* folder management */
62 - (id)_primaryLookupFolderForUID:(NSString *)_uid inContext:(id)_ctx {
63 NSException *error = nil;
67 /* create subcontext, so that we don't destroy our environment */
69 if ((ctx = [_ctx createSubContext]) == nil) {
70 [self errorWithFormat:@"could not create SOPE subcontext!"];
76 path = _uid != nil ? [NSArray arrayWithObjects:&_uid count:1] : nil;
80 result = [[ctx application] traversePathArray:path inContext:ctx
81 error:&error acquire:NO];
83 [self errorWithFormat:@"folder lookup failed (uid=%@): %@",
89 [self debugWithFormat:@"Note: got folder for uid %@ path %@: %@",
90 _uid, [path componentsJoinedByString:@"=>"], result];
94 - (void)_setupFolders {
96 NSMutableDictionary *md;
101 if (self->uidToFolder != nil)
103 if ((luids = [self uids]) == nil)
106 ctx = [[WOApplication application] context];
108 count = [luids count];
109 ma = [NSMutableArray arrayWithCapacity:count + 1];
110 md = [NSMutableDictionary dictionaryWithCapacity:count];
112 for (i = 0; i < count; i++) {
116 uid = [luids objectAtIndex:i];
117 folder = [self _primaryLookupFolderForUID:uid inContext:ctx];
119 if ([folder isNotNull]) {
120 [md setObject:folder forKey:uid];
121 [ma addObject:folder];
124 [ma addObject:[NSNull null]];
128 self->uidToFolder = [md copy];
129 self->folders = [[NSArray alloc] initWithArray:ma];
132 - (NSArray *)memberFolders {
133 [self _setupFolders];
134 return self->folders;
137 - (id)folderForUID:(NSString *)_uid {
138 [self _setupFolders];
140 if ([_uid length] == 0)
143 return [self->uidToFolder objectForKey:_uid];
146 - (void)resetFolderCaches {
147 [self->uidToFolder release]; self->uidToFolder = nil;
148 [self->folders release]; self->folders = nil;
151 [self resetFolderCaches];
157 - (BOOL)isFolderish {
161 /* looking up shared objects */
163 - (SOGoGroupsFolder *)lookupGroupsFolder {
164 return [[self container] lookupGroupsFolder];
171 - (id)groupCalendar:(NSString *)_key inContext:(id)_ctx {
172 static Class calClass = Nil;
176 calClass = NSClassFromString(@"SOGoGroupAppointmentFolder");
177 if (calClass == Nil) {
178 [self errorWithFormat:@"missing SOGoGroupAppointmentFolder class!"];
182 calendar = [[calClass alloc] initWithName:_key inContainer:self];
184 // TODO: should we pass over the uids in questions or should the
185 // appointment folder query its container for that info?
187 return [calendar autorelease];
190 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
193 /* first check attributes directly bound to the application */
194 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
197 if ([_key isEqualToString:@"Calendar"])
198 return [self groupCalendar:_key inContext:_ctx];
200 /* return 404 to stop acquisition */
201 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
204 @end /* SOGoGroupFolder */