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 "OFSBaseObject.h"
23 #include "OFSFactoryContext.h"
24 #include "OFSFolder.h"
27 @implementation OFSBaseObject
34 [self detachFromContainer];
36 [self->fileManager release];
37 [self->storagePath release];
38 [self->soClass release];
44 - (NSException *)takeStorageInfoFromContext:(OFSFactoryContext *)_ctx {
45 self->fileManager = [[_ctx fileManager] retain];
46 self->storagePath = [[_ctx storagePath] copy];
47 [self setContainer:[_ctx container] andName:[_ctx nameInContainer]];
51 - (id)awakeFromFetchInContext:(OFSFactoryContext *)_ctx {
52 if (self->fileManager == nil || self->storagePath == nil)
53 [self logWithFormat:@"WARNING: object has no storage info !"];
57 - (id)awakeFromInsertionInContext:(OFSFactoryContext *)_ctx {
58 self->fileManager = [[_ctx fileManager] retain];
59 self->storagePath = [[_ctx storagePath] copy];
60 [self setContainer:[_ctx container] andName:[_ctx nameInContainer]];
66 - (SoClass *)soClass {
67 if (self->soClass == nil)
68 return [super soClass];
72 - (id<NSObject,NGFileManager>)fileManager {
73 return self->fileManager;
75 - (NSString *)storagePath {
76 return self->storagePath;
78 - (EOGlobalID *)globalID {
79 return [[self fileManager] globalIDForPath:[self storagePath]];
82 - (BOOL)isCollection {
86 return [self isCollection];
89 return [[self fileManager] fileExistsAtPath:[self storagePath]];
95 return self->container;
97 - (NSString *)nameInContainer {
100 - (void)setContainer:(id)_container andName:(NSString *)_name {
101 self->container = _container;
102 ASSIGNCOPY(self->name, _name);
107 - (void)detachFromContainer {
108 self->container = nil;
109 [self->name release]; self->name = nil;
111 - (BOOL)isAttachedToContainer {
112 return self->container ? YES : NO;
115 - (id)DELETEAction:(id)_ctx {
119 if ((e = [self validateForDelete]))
122 if ((fm = [self fileManager]) == nil) {
123 [self logWithFormat:@"missing filemanager for delete."];
124 return [NSException exceptionWithHTTPStatus:500 /* server error */
125 reason:@"missing filemanager for object ?!"];
128 if (![self doesExist])
129 return [NSException exceptionWithHTTPStatus:404 /* not found */];
131 if ([fm removeFileAtPath:[self storagePath] handler:nil])
132 /* nil means "everything OK" ;-) [for the WebDAV renderer] */
133 return [NSNumber numberWithBool:YES];
135 if ([fm respondsToSelector:@selector(lastException)])
136 return [fm lastException];
138 return [NSException exceptionWithHTTPStatus:500 /* server error */
139 reason:@"filemanager couldn't remove file at path."];
144 - (id)handleQueryWithUnboundKey:(NSString *)key {
145 // TODO: any drawbacks when doing this ?
149 - (id)valueForKey:(NSString *)_name {
150 /* map out some very private keys */
154 if ((nl = [_name length]) == 0)
157 c = [_name characterAtIndex:0];
158 if ((c == 's') && (nl == 11)) {
159 if ([_name isEqualToString:@"storagePath"])
160 /* do not allow KVC access to storage path */
163 else if ((c == 'f') && (nl == 11)) {
164 if ([_name isEqualToString:@"fileManager"])
165 /* do not allow KVC access to filemanager */
169 return [super valueForKey:_name];
172 /* key validations */
174 - (NSException *)validateForDelete {
177 - (NSException *)validateForInsert {
180 - (NSException *)validateForUpdate {
183 - (NSException *)validateForSave {
189 - (NSString *)davDisplayName {
191 if ((s = [self valueForKey:@"NSFileSubject"])) return s;
192 return [self nameInContainer];
194 - (id)davLastModified {
195 return [self valueForKey:NSFileModificationDate];
200 - (NSClassDescription *)soClassDescription {
206 - (NSString *)ownerInContext:(id)_ctx {
207 /* ask container ... */
210 if ((c = [self container]) == nil)
213 if ([c respondsToSelector:@selector(ownerOfChild:inContext:)])
214 return [c ownerOfChild:self inContext:_ctx];
217 /* avoid endless recursion ... */
220 return [c ownerInContext:_ctx];
223 - (id)authenticatorInContext:(id)_ctx {
224 /* ask container ... */
227 if ((lContainer = [self container]) == nil)
230 if (lContainer == self)
231 /* avoid endless recursion ... */
234 return [lContainer authenticatorInContext:_ctx];
237 /* version control */
239 - (BOOL)isCvsControlled {
242 - (BOOL)isSvnControlled {
248 - (BOOL)isDebuggingEnabled {
255 - (NSString *)loggingPrefix {
256 /* improve perf ... */
257 NSString *n = [self nameInContainer];
258 return [NSString stringWithFormat:@"0x%08X[%@]:%@",
259 self, NSStringFromClass([self class]),
265 - (NSString *)description {
268 ms = [NSMutableString stringWithCapacity:64];
269 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
271 if (self->storagePath)
272 [ms appendFormat:@" path=%@", self->storagePath];
274 [ms appendString:@">"];
278 @end /* OFSBaseObject */