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];
52 [displayName release];
56 - (id <SOGoContactFolder>) initWithName: (NSString *) newName
57 andDisplayName: (NSString *) newDisplayName
58 inContainer: (SOGoObject *) newContainer
60 if ((self = [self initWithName: newName
61 inContainer: newContainer]))
62 ASSIGN (displayName, newDisplayName);
67 - (NSString *) displayName
74 - (id <SOGoContactObject>) lookupContactWithId: (NSString *) recordId
76 SOGoContactGCSEntry *contact;
78 if ([recordId length] > 0)
79 contact = [SOGoContactGCSEntry objectWithName: recordId
87 - (id) lookupName: (NSString *) _key
88 inContext: (WOContext *) _ctx
93 /* first check attributes directly bound to the application */
94 obj = [super lookupName:_key inContext:_ctx acquire:NO];
97 if ([[[_ctx request] method] isEqualToString: @"PUT"])
99 obj = [[SOGoContactGCSEntry alloc] initWithName: _key
104 obj = [self lookupContactWithId: _key];
107 obj = [NSException exceptionWithHTTPStatus:404 /* Not Found */];
110 // if ([[self ocsFolder] versionOfContentWithName:_key])
112 // return [self contactWithName:_key inContext:_ctx];
115 /* return 404 to stop acquisition */
120 - (EOQualifier *) _qualifierForFilter: (NSString *) filter
123 EOQualifier *qualifier;
125 if (filter && [filter length] > 0)
127 qs = [NSString stringWithFormat:
128 @"(sn isCaseInsensitiveLike: '%@%%') OR "
129 @"(givenname isCaseInsensitiveLike: '%@%%') OR "
130 @"(mail isCaseInsensitiveLike: '%@%%') OR "
131 @"(telephonenumber isCaseInsensitiveLike: '%%%@%%')",
132 filter, filter, filter, filter];
133 qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
141 - (NSArray *) lookupContactsWithFilter: (NSString *) filter
142 sortBy: (NSString *) sortKey
143 ordering: (NSComparisonResult) sortOrdering
145 NSArray *fields, *records;
146 EOQualifier *qualifier;
147 EOSortOrdering *ordering;
149 // NSLog (@"fetching records matching '%@', sorted by '%@' in order %d",
150 // filter, sortKey, sortOrdering);
152 fields = folderListingFields;
153 qualifier = [self _qualifierForFilter: filter];
154 records = [[self ocsFolder] fetchFields: fields
155 matchingQualifier: qualifier];
156 if ([records count] > 1)
159 = [EOSortOrdering sortOrderingWithKey: sortKey
160 selector: ((sortOrdering == NSOrderedDescending)
161 ? EOCompareCaseInsensitiveDescending
162 : EOCompareCaseInsensitiveAscending)];
164 = [records sortedArrayUsingKeyOrderArray:
165 [NSArray arrayWithObject: ordering]];
168 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
170 //[self debugWithFormat:@"fetched %i records.", [records count]];
174 - (NSString *) groupDavResourceType
176 return @"vcard-collection";
179 - (NSException *) delete
181 return (([nameInContainer isEqualToString: @"personal"])
182 ? [NSException exceptionWithHTTPStatus: 403
183 reason: @"the 'personal' folder cannot be deleted"]
189 // - (id) GETAction: (id)_ctx
191 // // TODO: I guess this should really be done by SOPE (redirect to
192 // // default method)
196 // uri = [[_ctx request] uri];
197 // if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"];
198 // uri = [uri stringByAppendingString:@"view"];
200 // r = [_ctx response];
201 // [r setStatus:302 /* moved */];
202 // [r setHeader:uri forKey:@"location"];
208 - (NSString *) folderType
213 - (NSString *) outlookFolderClass
215 return @"IPF.Contact";
218 @end /* SOGoContactGCSFolder */