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 "SOGoUserFolder.h"
23 #include "WOContext+Agenor.h"
26 @implementation SOGoUserFolder
31 return [self nameInContainer];
36 - (NSArray *)toManyRelationshipKeys {
37 static NSArray *children = nil;
39 if (children == nil) {
40 children = [[NSArray alloc] initWithObjects:
41 @"Calendar", @"Contacts", @"Mail", nil];
48 - (NSString *)ownerInContext:(id)_ctx {
52 /* looking up shared objects */
54 - (SOGoUserFolder *)lookupUserFolder {
57 - (SOGoGroupsFolder *)lookupGroupsFolder {
58 return [self lookupName:@"Groups" inContext:nil acquire:NO];
63 - (void)setOCSPath:(NSString *)_path {
65 @"rejected attempt to reset user-folder path: '%@'", _path];
67 - (NSString *)ocsPath {
68 return [@"/Users/" stringByAppendingString:[self login]];
71 - (NSString *)ocsUserPath {
72 return [self ocsPath];
74 - (NSString *)ocsPrivateCalendarPath {
75 return [[self ocsUserPath] stringByAppendingString:@"/Calendar"];
77 - (NSString *)ocsPrivateContactsPath {
78 return [[self ocsUserPath] stringByAppendingString:@"/Contacts"];
83 - (id)privateCalendar:(NSString *)_key inContext:(id)_ctx {
84 static Class calClass = Nil;
88 calClass = NSClassFromString(@"SOGoAppointmentFolder");
89 if (calClass == Nil) {
90 [self errorWithFormat:@"missing SOGoAppointmentFolder class!"];
94 calendar = [[calClass alloc] initWithName:_key inContainer:self];
95 [calendar setOCSPath:[self ocsPrivateCalendarPath]];
96 return [calendar autorelease];
99 - (id)privateContacts:(NSString *)_key inContext:(id)_ctx {
100 static Class calClass = Nil;
104 calClass = NSClassFromString(@"SOGoContactFolder");
105 if (calClass == Nil) {
106 [self errorWithFormat:@"missing SOGoContactFolder class!"];
110 calendar = [[calClass alloc] initWithName:_key inContainer:self];
111 [calendar setOCSPath:[self ocsPrivateContactsPath]];
112 return [calendar autorelease];
115 - (id)groupsFolder:(NSString *)_key inContext:(id)_ctx {
116 static Class fldClass = Nil;
120 fldClass = NSClassFromString(@"SOGoGroupsFolder");
121 if (fldClass == Nil) {
122 [self errorWithFormat:@"missing SOGoGroupsFolder class!"];
126 folder = [[fldClass alloc] initWithName:_key inContainer:self];
127 return [folder autorelease];
130 - (id)mailAccountsFolder:(NSString *)_key inContext:(id)_ctx {
131 static Class fldClass = Nil;
135 fldClass = NSClassFromString(@"SOGoMailAccounts");
136 if (fldClass == Nil) {
137 [self errorWithFormat:@"missing SOGoMailAccounts class!"];
141 folder = [[fldClass alloc] initWithName:_key inContainer:self];
142 return [folder autorelease];
145 - (id)freeBusyObject:(NSString *)_key inContext:(id)_ctx {
146 static Class fbClass = Nil;
150 fbClass = NSClassFromString(@"SOGoFreeBusyObject");
151 if (fbClass == Nil) {
152 [self errorWithFormat:@"missing SOGoFreeBusyObject class!"];
156 fb = [[fbClass alloc] initWithName:_key inContainer:self];
157 return [fb autorelease];
160 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
163 /* first check attributes directly bound to the application */
164 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
167 if ([_key hasPrefix:@"Calendar"]) {
170 calendar = [self privateCalendar:@"Calendar" inContext:_ctx];
171 if ([_key isEqualToString:@"Calendar"])
174 return [calendar lookupName:[_key pathExtension]
175 inContext:_ctx acquire:NO];
178 if ([_key isEqualToString:@"Contacts"])
179 return [self privateContacts:_key inContext:_ctx];
181 if ([_key isEqualToString:@"Groups"]) {
182 /* Agenor requirement, return 403 to stop acquisition */
183 if (![_ctx isAccessFromIntranet]) {
184 return [NSException exceptionWithHTTPStatus:403 /* Forbidden */];
186 return [self groupsFolder:_key inContext:_ctx];
189 if ([_key isEqualToString:@"Mail"])
190 return [self mailAccountsFolder:_key inContext:_ctx];
192 if ([_key isEqualToString:@"freebusy.ifb"])
193 return [self freeBusyObject:_key inContext:_ctx];
195 /* return 404 to stop acquisition */
196 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
201 - (NSArray *)fetchContentObjectNames {
202 static NSArray *cos = nil;
205 cos = [[NSArray alloc] initWithObjects:@"freebusy.ifb", nil];
210 - (BOOL)davIsCollection {
214 @end /* SOGoUserFolder */