]> err.no Git - sope/blob - sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m
fixed OGo bug #888
[sope] / sope-appserver / NGObjWeb / Associations / WOResourceURLAssociation.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$
22
23 #include "WOResourceURLAssociation.h"
24 #include <NGObjWeb/WOApplication.h>
25 #include <NGObjWeb/WOComponent.h>
26 #include <NGObjWeb/WOContext.h>
27 #include <NGObjWeb/WORequest.h>
28 #include <NGObjWeb/WOResourceManager.h>
29 #include <NGObjWeb/WOSession.h>
30 #include "common.h"
31
32 @implementation WOResourceURLAssociation
33
34 static BOOL doDebug = NO;
35
36 + (int)version {
37   return [super version] + 0 /* v2 */;
38 }
39 + (void)initialize {
40   NSAssert2([super version] == 2,
41             @"invalid superclass (%@) version %i !",
42             NSStringFromClass([self superclass]), [super version]);
43 }
44
45 - (id)initWithString:(NSString *)_name {
46   if ([_name length] == 0) {
47     if (doDebug) {
48       NSLog(@"WARNING(%s): got passed no resource name!", 
49             __PRETTY_FUNCTION__);
50     }
51     [self release];
52     return nil;
53   }
54   if ((self = [super init])) {
55     self->resourceName = [_name copy];
56   }
57   return self;
58 }
59 - (id)init {
60   return [self initWithString:nil];
61 }
62
63 - (void)dealloc {
64   [self->resourceName release];
65   [super dealloc];
66 }
67
68 /* accessors */
69
70 - (NSString *)resourceName {
71   return self->resourceName;
72 }
73 - (NSString *)frameworkName {
74   return nil;
75 }
76
77 /* value */
78
79 - (void)setValue:(id)_value inComponent:(WOComponent *)_component {
80   /* resource-url association values cannot be set */
81   [NSException raise:@"AssociationException"
82                format:@"association value is not settable !"];
83 }
84 - (id)valueInComponent:(WOComponent *)_component {
85   WOResourceManager *rm;
86   WOContext *ctx;
87   NSArray   *langs;
88   WORequest *rq;
89
90   if ((ctx = [_component context]) == nil)
91     ctx = [[WOApplication application] context];
92   rq    = [ctx request];
93   langs = [ctx hasSession]
94     ? [[ctx session] languages]
95     : [[ctx request] browserLanguages];
96   
97   if ((rm = [_component resourceManager]) == nil) {
98     WOApplication *app;
99     
100     if ((app = [ctx application]) == nil)
101       app = [WOApplication application];
102     
103     rm = [app resourceManager];
104   }
105   if (rm == nil) {
106     [self logWithFormat:@"WARNING: found no resource manager!"];
107     return nil;
108   }
109   
110   return [rm urlForResourceNamed:[self resourceName]
111              inFramework:[self frameworkName]
112              languages:langs
113              request:rq];
114 }
115
116 - (BOOL)isValueConstant {
117   return NO;
118 }
119 - (BOOL)isValueSettable {
120   return NO;
121 }
122
123 /* NSCopying */
124
125 - (id)copyWithZone:(NSZone *)_zone {
126   /* rsrc-url associations are immutable and don't need to be copied */
127   return [self retain];
128 }
129
130 - (NSString *)description {
131   NSMutableString *str;
132
133   str = [NSMutableString stringWithCapacity:64];
134   [str appendFormat:@"<%@[0x%08X]:", NSStringFromClass([self class]), self];
135   [str appendFormat:@" rsrc='%@'", [self resourceName]];
136   [str appendString:@">"];
137   return str;
138 }
139
140 @end /* WOResourceURLAssociation */