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 {
95 NSMutableDictionary *md;
100 if (self->uidToFolder != nil)
102 if ((luids = [self uids]) == nil)
105 count = [luids count];
106 ma = [NSMutableArray arrayWithCapacity:count + 1];
107 md = [NSMutableDictionary dictionaryWithCapacity:count];
109 for (i = 0; i < count; i++) {
113 uid = [luids objectAtIndex:i];
114 folder = [self _primaryLookupFolderForUID:uid inContext: context];
116 if ([folder isNotNull]) {
117 [md setObject:folder forKey:uid];
118 [ma addObject:folder];
121 [ma addObject:[NSNull null]];
125 self->uidToFolder = [md copy];
126 self->folders = [[NSArray alloc] initWithArray:ma];
129 - (NSArray *)memberFolders {
130 [self _setupFolders];
131 return self->folders;
134 - (id)folderForUID:(NSString *)_uid {
135 [self _setupFolders];
137 if ([_uid length] == 0)
140 return [self->uidToFolder objectForKey:_uid];
143 - (void)resetFolderCaches {
144 [self->uidToFolder release]; self->uidToFolder = nil;
145 [self->folders release]; self->folders = nil;
148 [self resetFolderCaches];
154 - (BOOL)isFolderish {
158 /* looking up shared objects */
160 - (SOGoGroupsFolder *)lookupGroupsFolder {
161 return [[self container] lookupGroupsFolder];
168 - (id)groupCalendar:(NSString *)_key inContext:(id)_ctx {
169 static Class calClass = Nil;
173 calClass = NSClassFromString(@"SOGoGroupAppointmentFolder");
174 if (calClass == Nil) {
175 [self errorWithFormat:@"missing SOGoGroupAppointmentFolder class!"];
179 calendar = [[calClass alloc] initWithName:_key inContainer:self];
181 // TODO: should we pass over the uids in questions or should the
182 // appointment folder query its container for that info?
184 return [calendar autorelease];
187 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
190 /* first check attributes directly bound to the application */
191 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
194 if ([_key isEqualToString:@"Calendar"])
195 return [self groupCalendar:_key inContext:_ctx];
197 /* return 404 to stop acquisition */
198 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
201 @end /* SOGoGroupFolder */