2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
22 #include "WOResourceURLAssociation.h"
23 #include <NGObjWeb/WOApplication.h>
24 #include <NGObjWeb/WOComponent.h>
25 #include <NGObjWeb/WOContext.h>
26 #include <NGObjWeb/WORequest.h>
27 #include <NGObjWeb/WOResourceManager.h>
28 #include <NGObjWeb/WOSession.h>
31 @implementation WOResourceURLAssociation
33 static BOOL doDebug = NO;
36 return [super version] + 0 /* v2 */;
39 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
40 NSAssert2([super version] == 2,
41 @"invalid superclass (%@) version %i !",
42 NSStringFromClass([self superclass]), [super version]);
44 doDebug = [ud boolForKey:@"WOResourceURLAssociationDebugEnabled"];
47 - (id)initWithString:(NSString *)_name {
48 if ([_name length] == 0) {
50 NSLog(@"WARNING(%s): got passed no resource name!",
56 if ((self = [super init])) {
57 self->resourceName = [_name copy];
62 return [self initWithString:nil];
66 [self->resourceName release];
72 - (NSString *)resourceName {
73 return self->resourceName;
75 - (NSString *)frameworkName {
81 - (void)setValue:(id)_value inComponent:(WOComponent *)_component {
82 /* resource-url association values cannot be set */
83 [NSException raise:@"AssociationException"
84 format:@"association value is not settable !"];
86 - (id)valueInComponent:(WOComponent *)_component {
87 WOResourceManager *rm;
94 [self debugWithFormat:@"lookup resource: %@", [self resourceName]];
96 if ((ctx = [_component context]) == nil)
97 ctx = [[WOApplication application] context];
99 langs = [ctx hasSession]
100 ? [[ctx session] languages]
101 : [[ctx request] browserLanguages];
104 [self debugWithFormat:@" languages: %@",
105 [langs componentsJoinedByString:@","]];
108 if ((rm = [_component resourceManager]) == nil) {
111 if ((app = [ctx application]) == nil)
112 app = [WOApplication application];
114 rm = [app resourceManager];
117 [self logWithFormat:@"WARNING: found no resource manager!"];
120 if (doDebug) [self debugWithFormat:@" resource-manager: %@", rm];
122 url = [rm urlForResourceNamed:[self resourceName]
123 inFramework:[self frameworkName]
128 [self debugWithFormat:@" => URL: %@", url];
130 [self debugWithFormat:@" => resource not found!"];
135 - (BOOL)isValueConstant {
138 - (BOOL)isValueSettable {
144 - (id)copyWithZone:(NSZone *)_zone {
145 /* rsrc-url associations are immutable and don't need to be copied */
146 return [self retain];
151 - (BOOL)isDebuggingEnabled {
154 - (NSString *)loggingPrefix {
155 return [NSString stringWithFormat:@"[rsrc:url assoc:0x%08X]", self];
160 - (NSString *)description {
161 NSMutableString *str;
163 str = [NSMutableString stringWithCapacity:64];
164 [str appendFormat:@"<%@[0x%08X]:", NSStringFromClass([self class]), self];
165 [str appendFormat:@" rsrc='%@'", [self resourceName]];
166 [str appendString:@">"];
170 @end /* WOResourceURLAssociation */