]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoFolder.m
Install libs to /usr/lib
[scalable-opengroupware.org] / SoObjects / SOGo / SOGoFolder.m
1 /* SOGoFolder.m - this file is part of SOGo
2  *
3  * Copyright (C) 2007 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSString.h>
25 #import <Foundation/NSURL.h>
26
27 #import <NGObjWeb/SoSelectorInvocation.h>
28
29 #import <SaxObjC/XMLNamespaces.h>
30
31 #import "NSString+Utilities.h"
32
33 #import "SOGoPermissions.h"
34 #import "SOGoFolder.h"
35
36 @implementation SOGoFolder
37
38 - (id) init
39 {
40   if ((self = [super init]))
41     displayName = nil;
42
43   return self;
44 }
45
46 - (void) dealloc
47 {
48   [displayName release];
49   [super dealloc];
50 }
51
52 - (void) setDisplayName: (NSString *) newDisplayName
53 {
54   ASSIGN (displayName, newDisplayName);
55 }
56
57 - (NSString *) displayName
58 {
59   return ((displayName) ? displayName : nameInContainer);
60 }
61
62 - (NSString *) folderType
63 {
64   [self subclassResponsibility: _cmd];
65
66   return nil;
67 }
68
69 - (id) lookupName: (NSString *) lookupName
70         inContext: (id) localContext
71           acquire: (BOOL) acquire
72 {
73   id obj;
74   NSArray *davNamespaces;
75   NSDictionary *davInvocation;
76   NSString *objcMethod;
77
78   obj = [super lookupName: lookupName inContext: localContext
79                acquire: acquire];
80   if (!obj)
81     {
82       davNamespaces = [self davNamespaces];
83       if ([davNamespaces count] > 0)
84         {
85           davInvocation = [lookupName asDavInvocation];
86           if (davInvocation
87               && [davNamespaces
88                    containsObject: [davInvocation objectForKey: @"ns"]])
89             {
90               objcMethod = [[davInvocation objectForKey: @"method"]
91                              davMethodToObjC];
92               obj = [[SoSelectorInvocation alloc]
93                       initWithSelectorNamed:
94                         [NSString stringWithFormat: @"%@:", objcMethod]
95                       addContextParameter: YES];
96               [obj autorelease];
97             }
98         }
99     }
100
101   return obj;
102 }
103
104 - (BOOL) isFolderish
105 {
106   return YES;
107 }
108
109 - (NSString *) httpURLForAdvisoryToUser: (NSString *) uid
110 {
111   return [[self soURL] absoluteString];
112 }
113
114 - (NSString *) resourceURLForAdvisoryToUser: (NSString *) uid
115 {
116   return [[self davURL] absoluteString];
117 }
118
119 /* sorting */
120 - (NSComparisonResult) _compareByOrigin: (SOGoFolder *) otherFolder
121 {
122   NSArray *thisElements, *otherElements;
123   unsigned thisCount, otherCount;
124   NSComparisonResult comparison;
125
126   thisElements = [nameInContainer componentsSeparatedByString: @"_"];
127   otherElements = [[otherFolder nameInContainer]
128                     componentsSeparatedByString: @"_"];
129   thisCount = [thisElements count];
130   otherCount = [otherElements count];
131   if (thisCount == otherCount)
132     {
133       if (thisCount == 1)
134         comparison = NSOrderedSame;
135       else
136         comparison = [[thisElements objectAtIndex: 0]
137                        compare: [otherElements objectAtIndex: 0]];
138     }
139   else
140     {
141       if (thisCount > otherCount)
142         comparison = NSOrderedDescending;
143       else
144         comparison = NSOrderedAscending;
145     }
146
147   return comparison;
148 }
149
150 - (NSComparisonResult) _compareByNameInContainer: (SOGoFolder *) otherFolder
151 {
152   NSString *otherName;
153   NSComparisonResult comparison;
154
155   otherName = [otherFolder nameInContainer];
156   if ([nameInContainer hasSuffix: @"personal"])
157     {
158       if ([otherName hasSuffix: @"personal"])
159         comparison = [nameInContainer compare: otherName];
160       else
161         comparison = NSOrderedAscending;
162     }
163   else
164     {
165       if ([otherName hasSuffix: @"personal"])
166         comparison = NSOrderedDescending;
167       else
168         comparison = NSOrderedSame;
169     }
170
171   return comparison;
172 }
173
174 - (NSComparisonResult) compare: (id) otherFolder
175 {
176   NSComparisonResult comparison;
177
178   comparison = [self _compareByOrigin: otherFolder];
179   if (comparison == NSOrderedSame)
180     {
181       comparison = [self _compareByNameInContainer: otherFolder];
182       if (comparison == NSOrderedSame)
183         comparison
184           = [[self displayName]
185               localizedCaseInsensitiveCompare: [otherFolder displayName]];
186     }
187
188   return comparison;
189 }
190
191 /* WebDAV */
192
193 - (NSArray *) davNamespaces
194 {
195   return nil;
196 }
197
198 - (BOOL) davIsCollection
199 {
200   return [self isFolderish];
201 }
202
203 - (NSString *) davContentType
204 {
205   return @"httpd/unix-directory";
206 }
207
208 - (NSArray *) davResourceType
209 {
210   NSArray *rType, *groupDavCollection;
211
212   if ([self respondsToSelector: @selector (groupDavResourceType)])
213     {
214       groupDavCollection
215         = [NSArray arrayWithObjects: [self groupDavResourceType],
216                    XMLNS_GROUPDAV, nil];
217       rType = [NSArray arrayWithObjects: @"collection", groupDavCollection,
218                        nil];
219     }
220   else
221     rType = [NSArray arrayWithObject: @"collection"];
222
223   return rType;
224 }
225
226 /* folder type */
227
228 - (BOOL) isEqual: (id) otherFolder
229 {
230   return ([otherFolder class] == [self class]
231           && [container isEqual: [otherFolder container]]
232           && [nameInContainer
233                isEqualToString: [otherFolder nameInContainer]]);
234 }
235
236 - (NSString *) outlookFolderClass
237 {
238   [self subclassResponsibility: _cmd];
239
240   return nil;
241 }
242
243 /* acls */
244
245 - (NSArray *) subscriptionRoles
246 {
247   return [NSArray arrayWithObjects: SoRole_Owner, SOGoRole_ObjectViewer,
248                   SOGoRole_ObjectEditor, SOGoRole_ObjectCreator,
249  SOGoRole_ObjectEraser, nil];
250 }
251
252 - (NSArray *) aclsForUser: (NSString *) uid
253 {
254   return nil;
255 }
256
257 @end