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 #include "SOGoContactFolder.h"
23 #include <SOGo/SOGoCustomGroupFolder.h>
24 #include <SOGo/AgenorUserManager.h>
25 #include <GDLContentStore/GCSFolder.h>
26 #include <NGiCal/NGiCal.h>
31 @implementation SOGoContactFolder
35 - (BOOL)isValidContactName:(NSString *)_key {
36 if ([_key length] == 0)
42 - (id)contactWithName:(NSString *)_key inContext:(id)_ctx {
43 static Class ctClass = Nil;
47 ctClass = NSClassFromString(@"SOGoContactObject");
49 [self errorWithFormat:@"missing SOGoContactObject class!"];
53 ct = [[ctClass alloc] initWithName:_key inContainer:self];
54 return [ct autorelease];
57 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
60 /* first check attributes directly bound to the application */
61 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
64 if ([self isValidContactName:_key]) {
66 if ([[self ocsFolder] versionOfContentWithName:_key])
68 return [self contactWithName:_key inContext:_ctx];
71 /* return 404 to stop acquisition */
72 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
77 - (NSArray *)fixupRecords:(NSArray *)_records {
81 - (NSArray *)fetchCoreInfos {
82 NSArray *fields, *records;
84 fields = [NSArray arrayWithObjects:
86 @"sn", @"givenname", @"l",
87 @"mail", @"telephonenumber",
89 records = [[self ocsFolder] fetchFields:fields matchingQualifier:nil];
91 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
94 records = [self fixupRecords:records];
95 //[self debugWithFormat:@"fetched %i records.", [records count]];
101 - (id)GETAction:(id)_ctx {
102 // TODO: I guess this should really be done by SOPE (redirect to
107 uri = [[_ctx request] uri];
108 if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"];
109 uri = [uri stringByAppendingString:@"view"];
112 [r setStatus:302 /* moved */];
113 [r setHeader:uri forKey:@"location"];
119 - (NSString *)outlookFolderClass {
120 return @"IPF.Contact";
123 @end /* SOGoContactFolder */