2 Copyright (C) 2002-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "OFSFolder.h"
26 Some special WebDAV keys:
27 .autodiskmounted - queried by the MacOSX DAV filesystem
28 .directory - queried by Nautilus
30 both seem to work if the keys do not exist (no special handling required).
33 @implementation OFSFolder(SoDAV)
35 static int davDebugOn = 0;
37 - (BOOL)davIsCollection {
41 /* this can be overridden by compound documents (aka filewrappers) */
42 return [self davIsCollection];
45 - (BOOL)davHasSubFolders {
46 /* search for subfolders (tries to be smart and load as little as p. ;-) */
50 if ((ak = [self allKeys]) == nil) return NO;
51 if ((count = [ak count]) == 0) return NO;
53 /* first scan the already loaded children */
54 for (i = 0; i < count; i++) {
57 child = [self->children objectForKey:[ak objectAtIndex:i]];
58 if ([child davIsFolder]) return YES;
61 /* now scan all children */
63 if (self->flags.didLoadAll)
64 return NO; /* we've already seen all children */
65 [self allValues]; /* otherwise trigger a load */
67 for (i = 0; i < count; i++) {
70 child = [self->children objectForKey:[ak objectAtIndex:i]];
71 if ([child davIsFolder]) return YES;
77 - (NSString *)fileExtensionForChildrenInContext:(id)_ctx {
79 This can be used to enforce a common extension for all children, this is
80 useful for WebDAV directory listings (eg all children of an address folder
81 can appear as vcf files in cadaver or OSX).
86 - (NSEnumerator *)davChildKeysInContext:(id)_ctx {
91 keys = [self allKeys];
92 if ((len = [keys count]) == 0) {
94 [self debugWithFormat:@"no DAV child keys for delivery ..."];
95 return [keys objectEnumerator];
98 if ((ext = [self fileExtensionForChildrenInContext:_ctx])) {
103 ma = [NSMutableArray arrayWithCapacity:len];
105 for (i = 0; i < len; i++) {
108 k = [keys objectAtIndex:i];
110 if ((pe = [k pathExtension]) == nil)
112 else if ([pe length] == 0)
115 k = [k stringByDeletingPathExtension];
116 k = [k stringByAppendingPathExtension:ext];
121 if (didChange) keys = ma;
124 [self debugWithFormat:@"DAV child keys for delivery: %@",
125 [keys componentsJoinedByString:@","]];
127 return [keys objectEnumerator];
130 - (NSException *)davCreateCollection:(NSString *)_name inContext:(id)_ctx {
131 id<NSObject,NGFileManager> fm;
135 if ([_name hasPrefix:@"."]) {
136 return [NSException exceptionWithHTTPStatus:405 /* not allowed */
137 reason:@"creation of collections with a "
138 @"leading dot is not allowed."];
141 [self debugWithFormat:@"should create collection: %@", _name];
143 p = [[self storagePath] stringByAppendingPathComponent:_name];
144 [self debugWithFormat:@" path for new collection: %@", p];
146 fm = [self fileManager];
147 ok = [fm createDirectoryAtPath:p attributes:nil];
149 [self debugWithFormat:@" could not created collection at: %@", p];
150 return [NSException exceptionWithHTTPStatus:405 /* not allowed */
152 @"this OFSFolder could not create the collection"];
155 [self debugWithFormat:@" created collection."];
156 self->flags.didLoadAll = NO; /* not valid anymore */
160 @end /* OFSFolder(SoDAV) */