]> err.no Git - sope/blob - sope-appserver/SoOFS/OFSFactoryContext.m
ivar extensions to NGObjWeb core classes, moved SoOFS to separate project
[sope] / sope-appserver / SoOFS / OFSFactoryContext.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo 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
9   later version.
10
11   OGo 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.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id: OFSFactoryContext.m 4 2004-08-20 17:04:31Z helge $
22
23 #include "OFSFactoryContext.h"
24 #include "OFSFolder.h"
25 #include "common.h"
26
27 @implementation OFSFactoryContext
28
29 + (OFSFactoryContext *)contextForChild:(NSString *)_name
30   storagePath:(NSString *)_sp
31   ofFolder:(OFSFolder *)_folder
32 {
33   OFSFactoryContext *ctx;
34   
35   ctx = [[self alloc] init];
36   ctx->fileManager = [[_folder fileManager] retain];
37   ctx->storagePath = [_sp copy];
38   ctx->container   = [_folder retain];
39   ctx->name        = [_name copy];
40   return [ctx autorelease];
41 }
42 + (OFSFactoryContext *)contextForNewChild:(NSString *)_name
43   storagePath:(NSString *)_sp
44   ofFolder:(OFSFolder *)_folder
45 {
46   OFSFactoryContext *ctx;
47   
48   if ((ctx = [self contextForChild:_name storagePath:_sp ofFolder:_folder])) {
49     ctx->isNewObject = YES;
50   }
51   return ctx;
52 }
53
54 + (OFSFactoryContext *)contextWithFileManager:(id<NSObject,NGFileManager>)_fm
55   storagePath:(NSString *)_sp
56 {
57   OFSFactoryContext *ctx;
58   
59   ctx = [[self alloc] init];
60   ctx->fileManager = [_fm retain];
61   ctx->storagePath = [_sp copy];
62   return [ctx autorelease];
63 }
64
65 - (void)dealloc {
66   [self->fileType    release];
67   [self->mimeType    release];
68   [self->fileManager release];
69   [self->container   release];
70   [self->name        release];
71   [self->storagePath release];
72   [super dealloc];
73 }
74
75 /* accessors */
76
77 - (id<NSObject,NGFileManager>)fileManager {
78   return self->fileManager;
79 }
80 - (NSString *)storagePath {
81   return self->storagePath;
82 }
83 - (id)container {
84   return self->container;
85 }
86 - (NSString *)nameInContainer {
87   return self->name;
88 }
89
90 - (NSString *)fileType {
91   return self->fileType;
92 }
93 - (NSString *)mimeType {
94   return self->mimeType;
95 }
96
97 - (BOOL)isNewObject {
98   return self->isNewObject;
99 }
100
101 /* description */
102
103 - (NSString *)description {
104   NSMutableString *ms;
105   
106   ms = [NSMutableString stringWithCapacity:64];
107   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
108   
109   if (self->isNewObject)
110     [ms appendString:@" NEW"];
111   if (self->name)        [ms appendFormat:@" create=%@", self->name];
112   if (self->container)   [ms appendFormat:@" in=%@",   self->container];
113   if (self->fileType)    [ms appendFormat:@" type=%@", self->fileType];
114   if (self->mimeType)    [ms appendFormat:@" mime=%@", self->mimeType];
115   if (self->storagePath) [ms appendFormat:@" path=%@", self->storagePath];
116   
117   [ms appendString:@">"];
118   return ms;
119 }
120
121 @end /* OFSFactoryContext */