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 "SOGoContactObject.h"
23 #include <NGiCal/NGVCard.h>
26 @implementation SOGoContactObject
29 [self->record release];
36 if (self->record == nil) {
39 s = [self contentAsString];
41 if ([s hasPrefix:@"BEGIN:VCARD"]) {
44 v = [NGVCard parseVCardsFromSource:s];
46 [self errorWithFormat:@"Could not parse vCards from content!"];
50 self->record = [[v objectAtIndex:0] retain];
53 self->record = [[s propertyList] copy];
55 if (self->record == nil)
56 self->record = [[NSNull null] retain];
58 return [self->record isNotNull] ? self->record : nil;
61 - (BOOL)isVCardRecord {
62 return [[self record] isKindOfClass:[NGVCard class]];
66 return [[self record] isKindOfClass:[NGVCard class]]
71 /* key value coding */
73 - (id)valueForKey:(NSString *)_key {
76 if ((value = [[self record] valueForKey:_key]) != nil)
79 return [super valueForKey:_key];
84 - (NSString *)davDisplayName {
87 if ((n = [self valueForKey:@"cn"]))
90 return [self nameInContainer];
93 /* specialized actions */
95 - (NSException *)saveRecord:(id)_record {
96 if ([_record isKindOfClass:[NGVCard class]]) {
97 // TODO: implement a vCard generator
98 return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */
99 reason:@"Saving vCards is not supported yet."];
102 return [self saveContentString:[_record description]];
105 - (NSException *)patchField:(NSString *)_fname value:(NSString *)_value
108 NSMutableDictionary *md;
110 if ([self isVCardRecord]) {
111 return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */
112 reason:@"Changing vCards is not supported yet."];
115 if ([_fname length] == 0) {
116 return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
117 reason:@"missing form field name"];
120 if ((md = [[[self record] mutableCopy] autorelease]) == nil) {
121 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
122 reason:@"did not find contact record"];
125 [md setObject:[_value isNotNull] ? _value : @"" forKey:_fname];
127 return [self saveRecord:md];
130 - (id)patchOneFieldAction:(id)_ctx {
132 expects: fieldname\nfieldvalue
134 TODO: should be extended to properly parse XML.
139 fields = [[[(WOContext *)_ctx request] contentAsString]
140 componentsSeparatedByString:@"\n"];
142 if ([fields count] < 2) {
143 return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
144 reason:@"missing form fields"];
147 error = [self patchField:[fields objectAtIndex:0]
148 value:[fields objectAtIndex:1]
153 return [(WOContext *)_ctx response];
158 - (NSString *)outlookMessageClass {
159 return @"IPM.Contact";
162 @end /* SOGoContactObject */