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 #import <GDLContentStore/GCSFolder.h>
26 #import "SOGoContactGCSEntry.h"
27 #import "SOGoContactGCSFolder.h"
29 #define folderListingFields [NSArray arrayWithObjects: @"c_name", @"cn", \
30 @"givenname", @"screenname", \
31 @"o", @"mail", @"telephonenumber", \
34 @implementation SOGoContactGCSFolder
36 + (id <SOGoContactFolder>) contactFolderWithName: (NSString *) aName
37 andDisplayName: (NSString *) aDisplayName
38 inContainer: (SOGoObject *) aContainer
40 SOGoContactGCSFolder *folder;
42 folder = [[self alloc] initWithName: aName
43 andDisplayName: aDisplayName
44 inContainer: aContainer];
50 - (id <SOGoContactFolder>) initWithName: (NSString *) aName
51 andDisplayName: (NSString *) aDisplayName
52 inContainer: (SOGoObject *) aContainer
54 if ((self = [self initWithName: aName
55 inContainer: aContainer]))
56 [self setDisplayName: aDisplayName];
61 - (void) setDisplayName: (NSString *) aDisplayName
64 [displayName release];
65 displayName = aDisplayName;
70 - (NSString *) displayName
77 - (id <SOGoContactObject>) lookupContactWithId: (NSString *) recordId
79 SOGoContactGCSEntry *contact;
81 if ([recordId length] > 0)
82 contact = [SOGoContactGCSEntry objectWithName: recordId
90 - (id) lookupName: (NSString *) _key
91 inContext: (WOContext *) _ctx
96 /* first check attributes directly bound to the application */
97 obj = [super lookupName:_key inContext:_ctx acquire:NO];
100 if ([[[_ctx request] method] isEqualToString: @"PUT"])
102 obj = [[SOGoContactGCSEntry alloc] initWithName: _key
107 obj = [self lookupContactWithId: _key];
110 obj = [NSException exceptionWithHTTPStatus:404 /* Not Found */];
113 // if ([[self ocsFolder] versionOfContentWithName:_key])
115 // return [self contactWithName:_key inContext:_ctx];
118 /* return 404 to stop acquisition */
123 - (EOQualifier *) _qualifierForFilter: (NSString *) filter
126 EOQualifier *qualifier;
128 if (filter && [filter length] > 0)
130 qs = [NSString stringWithFormat:
131 @"(sn isCaseInsensitiveLike: '%@%%') OR "
132 @"(givenname isCaseInsensitiveLike: '%@%%') OR "
133 @"(mail isCaseInsensitiveLike: '%@%%') OR "
134 @"(telephonenumber isCaseInsensitiveLike: '%%%@%%')",
135 filter, filter, filter, filter];
136 qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
144 - (NSArray *) lookupContactsWithFilter: (NSString *) filter
145 sortBy: (NSString *) sortKey
146 ordering: (NSComparisonResult) sortOrdering
148 NSArray *fields, *records;
149 EOQualifier *qualifier;
150 EOSortOrdering *ordering;
152 NSLog (@"fetching records matching '*%@*', sorted by '%@' in order %d",
153 filter, sortKey, sortOrdering);
155 fields = folderListingFields;
156 qualifier = [self _qualifierForFilter: filter];
157 records = [[self ocsFolder] fetchFields: fields
158 matchingQualifier: qualifier];
162 = [EOSortOrdering sortOrderingWithKey: sortKey
163 selector: ((sortOrdering == NSOrderedDescending)
164 ? EOCompareCaseInsensitiveDescending
165 : EOCompareCaseInsensitiveAscending)];
167 = [records sortedArrayUsingKeyOrderArray:
168 [NSArray arrayWithObject: ordering]];
171 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
173 //[self debugWithFormat:@"fetched %i records.", [records count]];
177 - (NSString *) groupDavResourceType
179 return @"vcard-collection";
182 - (NSException *) delete
184 return (([nameInContainer isEqualToString: @"personal"])
185 ? [NSException exceptionWithHTTPStatus: 403
186 reason: @"the 'personal' folder cannot be deleted"]
192 // - (id) GETAction: (id)_ctx
194 // // TODO: I guess this should really be done by SOPE (redirect to
195 // // default method)
199 // uri = [[_ctx request] uri];
200 // if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"];
201 // uri = [uri stringByAppendingString:@"view"];
203 // r = [_ctx response];
204 // [r setStatus:302 /* moved */];
205 // [r setHeader:uri forKey:@"location"];
211 - (NSString *) folderType
216 - (NSString *)outlookFolderClass {
217 return @"IPF.Contact";
220 @end /* SOGoContactGCSFolder */