/* Copyright (C) 2000-2003 SKYRIX Software AG This file is part of OGo OGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. OGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id: SxEnterpriseFolder.m 1 2004-08-20 11:17:52Z znek $ #include "SxEnterpriseFolder.h" #include "SxEnterprise.h" #include "common.h" #include #include #include @implementation SxEnterpriseFolder /* factory */ - (NSString *)entity { return @"Enterprise"; } - (Class)recordClassForKey:(NSString *)_key { return [SxEnterprise class]; } /* rendering */ - (id)evoRendererInContext:(id)_ctx { static Class EvoRenderer = Nil; if (EvoRenderer == Nil) { if ((EvoRenderer = NSClassFromString(@"SxEvoEnterpriseRenderer")) == nil) { static BOOL didLog = NO; if (!didLog) { [self logWithFormat:@"Note: no Evolution support installed!"]; didLog = YES; } } } return [EvoRenderer rendererWithFolder:self inContext:_ctx]; } - (id)zideLookRendererInContext:(id)_ctx { /* TODO: move to ZideLook bundle */ static Class RendererClass = NULL; if (RendererClass == NULL) { NSString *className = @"SxZLEnterpriseRenderer"; RendererClass = NSClassFromString(className); if (RendererClass == NULL) { [self logWithFormat:@"try to instantiate '%@'", className]; return nil; } } return [RendererClass rendererWithFolder:self inContext:_ctx]; } - (id)renderListEntry:(id)_entry { // contentlength,lastmodified,displayname,executable,resourcetype // checked-in,checked-out /* $baseURL$/$pkey$.vcf?sn=$sn$ text/vcard $sn$, $givenname$ */ NSMutableDictionary *record; NSString *url, *cn, *pkey; if ((record = [_entry mutableCopy]) == nil) return nil; // getting: pkey, sn, givenname if ((pkey = [[record valueForKey:@"pkey"] stringValue]) == nil) return nil; cn = [record valueForKey:@"cn"]; url = [NSString stringWithFormat:@"%@%@.vcf", [self baseURL], pkey]; if ([cn length] > 0) url = [url stringByAppendingFormat:@"?cn=%@", [cn stringByEscapingURL]]; [record setObject:url forKey:@"{DAV:}href"]; [record setObject:cn?cn:pkey forKey:@"davDisplayName"]; return [record autorelease]; } /* queries */ - (SxContactSetIdentifier *)contactSetID { return [[self type] isEqualToString:@"public"] ? [SxContactSetIdentifier publicEnterprises] : [SxContactSetIdentifier privateEnterprises]; } - (id)performWebDAVBulkQuery:(EOFetchSpecification *)_fs inContext:(id)_ctx { // TODO: this method should check which attributes are actually queried! // TODO: would be better to implement performBulkQuery:onGlobalIDs of // SxFolder! id renderer; NSArray *pkeys; NSArray *records; unsigned count; /* get primary keys */ static Class RendererClass = NULL; if (RendererClass == NULL) { NSString *className = @"SxZLFullEnterpriseRenderer"; RendererClass = NSClassFromString(className); if (RendererClass == NULL) { [self logWithFormat:@"try to instantiate '%@'", className]; return nil; } } if ((pkeys = [self extractBulkPrimaryKeys:_fs]) == nil) return nil; if ((count = [pkeys count]) == 0) return [NSArray array]; if ([self doExplainQueries]) [self logWithFormat:@"performing enterprise bulk query on %i keys ...", count]; /* fetch */ #if 1 records = [[self contactManagerInContext:_ctx] fullObjectInfosForPrimaryKeys:pkeys withSetIdentifier:[self contactSetID]]; #else records = [[self contactManagerInContext:_ctx] fullEnterpriseInfosForPrimaryKeys:pkeys]; #endif if ((count = [records count]) == 0) return [NSArray array]; /* render to WebDAV */ #if 1 /* enable if the full renderer is fixed regarding the URL */ renderer = [RendererClass rendererWithContext:_ctx baseURL:[self baseURL]]; return [SxMapEnumerator enumeratorWithSource:[records objectEnumerator] object:renderer selector:@selector(renderEntry:)]; #else { NSMutableArray *davEntries; unsigned i; #warning fix enterprise full renderer to remove this junk davEntries = [NSMutableArray arrayWithCapacity:count]; for (i = 0; i < count; i++) { NSString *url; id pkey; id record; record = [records objectAtIndex:i]; if ((pkey = [record valueForKey:@"pkey"]) == nil) { [self logWithFormat:@"missing primary key in record: %@", record]; continue; } pkey = [pkey stringValue]; url = [[self baseURL] stringByAppendingString:pkey]; renderer = [[SxZLFullEnterpriseRenderer alloc] initWithContext:_ctx baseURL:url]; record = [renderer renderEntry:record]; [renderer release]; renderer = nil; if (record == nil) continue; [davEntries addObject:record]; } return davEntries; } #endif } @end /* SxEnterpriseFolder */