2
Copyright (C) 2000-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 "OFSResourceManager.h"
23
#include "OFSBaseObject.h"
24
#include <NGObjWeb/WOComponentDefinition.h>
27
@interface WOResourceManager(UsedPrivates)
28
- (WOComponentDefinition *)definitionForComponent:(id)_name
29
inFramework:(NSString *)_framework
30
languages:(NSArray *)_languages;
33
@interface WOComponentDefinition(UsedPrivates)
34
- (void)setComponentClass:(Class)_clazz;
37
@implementation OFSResourceManager
39
static BOOL debugOn = NO;
42
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
44
debugOn = [ud boolForKey:@"SoOFSResourceManagerDebugEnabled"];
47
- (id)initWithBaseObject:(id)_object inContext:(id)_ctx {
48
if ((self = [super init])) {
49
self->baseObject = _object;
52
if (self->baseObject == nil) {
57
if (self->context == nil)
58
[self debugWithFormat:@"WARNING: got not context !"];
68
self->baseObject = nil;
75
if (self->context == nil)
76
return [[WOApplication application] context];
80
/* base object lookup */
82
- (BOOL)doesAcquireResources {
86
- (id)soObjectForResourceNamed:(NSString *)_name
87
inFramework:(NSString *)_frameworkName
88
languages:(NSArray *)_languages
93
[self debugWithFormat:@"lookup resource object named '%@' in %@",
94
_name, self->baseObject];
97
if ([self doesAcquireResources]) {
98
NSException *error = nil;
102
Note: this will first look into the object traversal stack of the
103
context which might be different to the base object!
104
e.g. its common to use the resource manager on the container
105
of the clientObject (baseObject==container) instead of the
108
subctx = [[self context] createSubContext];
109
resourceObject = [self->baseObject
116
[self debugWithFormat:@" name: %@", _name];
117
[self debugWithFormat:@" base: %@", self->baseObject];
118
[self debugWithFormat:@" ctx: %@", subctx];
120
[self logWithFormat:@"ERROR: %@", error];
124
resourceObject = [self->baseObject lookupName:_name
125
inContext:[self context]
130
[self debugWithFormat:@" found: %@", resourceObject];
131
return resourceObject;
136
- (WOComponentDefinition *)definitionForComponent:(id)_name
137
inFramework:(NSString *)_framework
138
languages:(NSArray *)_languages
140
WOComponentDefinition *cdef;
142
cdef = [super definitionForComponent:_name
143
inFramework:_framework
144
languages:_languages];
145
[cdef setComponentClass:NSClassFromString(@"WOComponent")];
149
/* resource manager methods */
151
- (NSString *)forcedComponentExtension {
152
/* the content negotiation should select an extension for us ! */
156
- (NSString *)resourceNameForComponentNamed:(NSString *)_name {
159
if ((ext = [self forcedComponentExtension])) {
160
if ([[_name pathExtension] length] == 0)
161
_name = [_name stringByAppendingPathExtension:ext];
166
- (NSString *)pathForResourceNamed:(NSString *)_name
167
inFramework:(NSString *)_fw
168
languages:(NSArray *)_langs
173
obj = [self soObjectForResourceNamed:_name inFramework:_fw languages:_langs];
175
[self debugWithFormat:@"found no resource object named '%@'", _name];
177
[self debugWithFormat:@"found resource object '%@': %@", _name, obj];
179
return [obj storagePath];
182
- (NSString *)urlForResourceNamed:(NSString *)_name
183
inFramework:(NSString *)_fw
184
languages:(NSArray *)_langs
185
request:(WORequest *)_request
190
obj = [self soObjectForResourceNamed:_name inFramework:_fw languages:_langs];
192
[self logWithFormat:@"found no object named '%@'", _name];
194
return [obj baseURLInContext:[self context]];
199
- (BOOL)isDebuggingEnabled {
205
- (NSString *)description {
208
ms = [NSMutableString stringWithCapacity:64];
209
[ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
211
if (self->baseObject)
212
[ms appendFormat:@" base=%@", self->baseObject];
214
[ms appendFormat:@" ctx=0x%08X", self->context];
216
[ms appendString:@">"];
220
@end /* OFSResourceManager */