]> err.no Git - sope/blobdiff - sope-appserver/NGObjWeb/WebDAV/SoObject+SoDAV.m
improved WebDAV property handling
[sope] / sope-appserver / NGObjWeb / WebDAV / SoObject+SoDAV.m
index b4eeb90c9dc9e7c956a2844c361a0b9a0fa8a164..0334a9f6f92d91da31410b9d46600612172fac47 100644 (file)
@@ -1,20 +1,20 @@
 /*
-  Copyright (C) 2002-2004 SKYRIX Software AG
+  Copyright (C) 2002-2005 SKYRIX Software AG
 
-  This file is part of OpenGroupware.org.
+  This file is part of SOPE.
 
-  OGo is free software; you can redistribute it and/or modify it under
+  SOPE is free software; you can redistribute it and/or modify it under
   the terms of the GNU Lesser General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
 
-  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+  SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
   License for more details.
 
   You should have received a copy of the GNU Lesser General Public
-  License along with OGo; see the file COPYING.  If not, write to the
+  License along with SOPE; see the file COPYING.  If not, write to the
   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.
 */
@@ -45,6 +45,7 @@
 @implementation NSObject(SoObjectSoDAVImp)
 
 - (NSArray *)defaultWebDAVPropertyNamesInContext:(id)_ctx {
+  // TODO: check for set in SoClass slots
   static NSArray *defNames = nil;
   if (defNames == nil) {
     defNames = [[[NSUserDefaults standardUserDefaults] 
   return defNames;
 }
 
+- (NSArray *)davComplianceClassesInContext:(id)_ctx {
+  /*
+    Class 1 is everything in WebDAV which is a MUST.
+    
+    Class 2 adds the LOCK method, the supportedlock property, the lockdiscovery
+    property, the time-out response header and the lock-token request header.
+    
+    In this method we check that by querying the lock manager. If the object
+    has one, it will return class 2, otherwise just class 1.
+  */
+  static NSArray *class1 = nil, *class2 = nil;
+  
+  if (class1 == nil)
+    class1 = [[NSArray alloc] initWithObjects:@"1", nil];
+  if (class2 == nil)
+    class2 = [[NSArray alloc] initWithObjects:@"1", @"2", nil];
+  
+  return ([self davLockManagerInContext:_ctx] != nil)
+    ? class2 : class1;
+}
+
+- (NSArray *)davAllowedMethodsInContext:(id)_ctx {
+  static NSArray *defMethods = nil;
+  NSMutableArray *allow;
+  
+  if (defMethods == nil) {
+    defMethods = [[[NSUserDefaults standardUserDefaults] 
+                                   arrayForKey:@"SoWebDAVDefaultAllowMethods"] 
+                                   copy];
+  }
+  
+  allow = [NSMutableArray arrayWithCapacity:16];
+  if (defMethods) [allow addObjectsFromArray:defMethods];
+  
+  if ([self respondsToSelector:@selector(performWebDAVQuery:inContext:)]) {
+    [allow addObject:@"PROPFIND"];
+    [allow addObject:@"SEARCH"];
+  }
+  if ([self respondsToSelector:
+             @selector(davSetProperties:removePropertiesNamed:)])
+    [allow addObject:@"PROPPATCH"];
+  
+  return allow;
+}
+
 /* attributes */
 
 - (BOOL)davIsCollection {
   ctx = [[WOApplication application] context];
   i = 0;
   e = [self davChildKeysInContext:ctx];
-  while ((childName = [e nextObject])) {
-    if (![[self lookupName:childName inContext:ctx acquire:NO] davIsCollection])
+  while ((childName = [e nextObject]) != nil) {
+    if (![[self lookupName:childName inContext:ctx acquire:NO]davIsCollection])
       i++;
   }
   return i;
   return [self davURL];
 }
 - (id)davEntityTag {
-  return [self davUid];
+  return nil;
 }
 
 - (BOOL)davIsStructuredDocument {