1 /* SOGoFolder.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSString.h>
25 #import <Foundation/NSURL.h>
27 #import <NGObjWeb/SoSelectorInvocation.h>
29 #import <SaxObjC/XMLNamespaces.h>
31 #import "NSString+Utilities.h"
33 #import "SOGoPermissions.h"
34 #import "SOGoFolder.h"
36 @implementation SOGoFolder
40 if ((self = [super init]))
48 [displayName release];
52 - (void) setDisplayName: (NSString *) newDisplayName
54 ASSIGN (displayName, newDisplayName);
57 - (NSString *) displayName
59 return ((displayName) ? displayName : nameInContainer);
62 - (NSString *) folderType
64 [self subclassResponsibility: _cmd];
69 - (id) lookupName: (NSString *) lookupName
70 inContext: (id) localContext
71 acquire: (BOOL) acquire
74 NSArray *davNamespaces;
75 NSDictionary *davInvocation;
78 obj = [super lookupName: lookupName inContext: localContext
82 davNamespaces = [self davNamespaces];
83 if ([davNamespaces count] > 0)
85 davInvocation = [lookupName asDavInvocation];
88 containsObject: [davInvocation objectForKey: @"ns"]])
90 objcMethod = [[davInvocation objectForKey: @"method"]
92 obj = [[SoSelectorInvocation alloc]
93 initWithSelectorNamed:
94 [NSString stringWithFormat: @"%@:", objcMethod]
95 addContextParameter: YES];
109 - (NSString *) httpURLForAdvisoryToUser: (NSString *) uid
111 return [[self soURL] absoluteString];
114 - (NSString *) resourceURLForAdvisoryToUser: (NSString *) uid
116 return [[self davURL] absoluteString];
120 - (NSComparisonResult) _compareByOrigin: (SOGoFolder *) otherFolder
122 NSArray *thisElements, *otherElements;
123 unsigned thisCount, otherCount;
124 NSComparisonResult comparison;
126 thisElements = [nameInContainer componentsSeparatedByString: @"_"];
127 otherElements = [[otherFolder nameInContainer]
128 componentsSeparatedByString: @"_"];
129 thisCount = [thisElements count];
130 otherCount = [otherElements count];
131 if (thisCount == otherCount)
134 comparison = NSOrderedSame;
136 comparison = [[thisElements objectAtIndex: 0]
137 compare: [otherElements objectAtIndex: 0]];
141 if (thisCount > otherCount)
142 comparison = NSOrderedDescending;
144 comparison = NSOrderedAscending;
150 - (NSComparisonResult) _compareByNameInContainer: (SOGoFolder *) otherFolder
153 NSComparisonResult comparison;
155 otherName = [otherFolder nameInContainer];
156 if ([nameInContainer hasSuffix: @"personal"])
158 if ([otherName hasSuffix: @"personal"])
159 comparison = [nameInContainer compare: otherName];
161 comparison = NSOrderedAscending;
165 if ([otherName hasSuffix: @"personal"])
166 comparison = NSOrderedDescending;
168 comparison = NSOrderedSame;
174 - (NSComparisonResult) compare: (id) otherFolder
176 NSComparisonResult comparison;
178 comparison = [self _compareByOrigin: otherFolder];
179 if (comparison == NSOrderedSame)
181 comparison = [self _compareByNameInContainer: otherFolder];
182 if (comparison == NSOrderedSame)
184 = [[self displayName]
185 localizedCaseInsensitiveCompare: [otherFolder displayName]];
193 - (NSArray *) davNamespaces
198 - (BOOL) davIsCollection
200 return [self isFolderish];
203 - (NSString *) davContentType
205 return @"httpd/unix-directory";
208 - (NSArray *) davResourceType
210 NSArray *rType, *groupDavCollection;
212 if ([self respondsToSelector: @selector (groupDavResourceType)])
215 = [NSArray arrayWithObjects: [self groupDavResourceType],
216 XMLNS_GROUPDAV, nil];
217 rType = [NSArray arrayWithObjects: @"collection", groupDavCollection,
221 rType = [NSArray arrayWithObject: @"collection"];
228 - (BOOL) isEqual: (id) otherFolder
230 return ([otherFolder class] == [self class]
231 && [container isEqual: [otherFolder container]]
233 isEqualToString: [otherFolder nameInContainer]]);
236 - (NSString *) outlookFolderClass
238 [self subclassResponsibility: _cmd];
245 - (NSArray *) subscriptionRoles
247 return [NSArray arrayWithObjects: SoRole_Owner, SOGoRole_ObjectViewer,
248 SOGoRole_ObjectEditor, SOGoRole_ObjectCreator,
249 SOGoRole_ObjectEraser, nil];
252 - (NSArray *) aclsForUser: (NSString *) uid