/*
- Copyright (C) 2000-2003 SKYRIX Software AG
+ Copyright (C) 2002-2005 SKYRIX Software AG
- This file is part of OGo
+ 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.
*/
-// $Id$
#include "SoObject+SoDAV.h"
#include "SoObject.h"
@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 {
id v;
+
if ([self respondsToSelector:@selector(isCollection)])
return [self isCollection];
- if ((v = [self valueForKey:@"NSFileType"])) {
+ if ([(v = [self valueForKey:@"NSFileType"]) isNotNull]) {
if ([v isEqualToString:NSFileTypeDirectory])
return YES;
else
return NO;
}
- return [[self toOneRelationshipKeys] count] > 0 ? YES : NO;
+ if ([[self toManyRelationshipKeys] count] > 0)
+ return YES;
+ if ([[self toOneRelationshipKeys] count] > 0)
+ return YES;
+ return NO;
}
- (BOOL)davIsFolder {
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 {
url = [self baseURL];
}
else {
- [self logWithFormat:
- @"WARNING: unable to calculate davURL for this object !"];
+ [self warnWithFormat:@"unable to calculate davURL for this object !"];
url = nil;
}
if (url == nil)
- [self logWithFormat:@"WARNING: got no davURL for this object !"];
+ [self warnWithFormat:@"got no davURL for this object !"];
return url;
}
@end /* NSObject(SoObjectSoDAV) */
-@implementation NSObject(SoObjectDAVMaps)
+@interface WOCoreApplication(Resources)
++ (NSString *)findNGObjWebResource:(NSString *)_name ofType:(NSString *)_ext;
+@end
-+ (NSString *)lookupDefMapPlist {
- NSString *apath;
-#if !COMPILE_AS_FRAMEWORK
- NSFileManager *fm = [NSFileManager defaultManager];
- NSDictionary *env;
- NSString *relPath;
-#endif
-#if COMPILE_AS_FRAMEWORK
- {
- NSBundle *bundle;
-
- bundle = [NSBundle bundleForClass:self];
- apath = [bundle pathForResource:@"DAVPropMap" ofType:@"plist"];
- }
-#else
- env = [[NSProcessInfo processInfo] environment];
- relPath = @"Libraries";
- relPath = [relPath stringByAppendingPathComponent:@"Resources"];
- relPath = [relPath stringByAppendingPathComponent:@"NGObjWeb"];
- relPath = [relPath stringByAppendingPathComponent:@"DAVPropMap.plist"];
-
- apath = [env objectForKey:@"GNUSTEP_USER_ROOT"];
- apath = [apath stringByAppendingPathComponent:relPath];
- if (![fm fileExistsAtPath:apath]) {
- apath = [env objectForKey:@"GNUSTEP_LOCAL_ROOT"];
- apath = [apath stringByAppendingPathComponent:relPath];
- }
- if (![fm fileExistsAtPath:apath]) {
- apath = [env objectForKey:@"GNUSTEP_SYSTEM_ROOT"];
- apath = [apath stringByAppendingPathComponent:relPath];
- }
- if (![fm fileExistsAtPath:apath]) {
- apath = relPath;
- }
- if (![fm fileExistsAtPath:apath]) {
- NSLog(@"ERROR: cannot find DAVPropMap.plist resource "
- @"of NGObjWeb library !");
- }
-#endif
- return apath;
-}
+@implementation NSObject(SoObjectDAVMaps)
+ (id)defaultWebDAVAttributeMap {
static NSDictionary *defMap = nil;
if (defMap == nil) {
NSString *path;
- if ((path = [self lookupDefMapPlist]))
+ path = [WOApplication findNGObjWebResource:@"DAVPropMap" ofType:@"plist"];
+ if (path != nil)
defMap = [[NSDictionary alloc] initWithContentsOfFile:path];
}
return defMap;