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
25 @interface _WOResourceImage : WOImage
27 WOAssociation *filename; // path relative to WebServerResources
28 WOAssociation *framework;
32 #include "WOElement+private.h"
33 #include <NGObjWeb/WOApplication.h>
34 #include <NGObjWeb/WOResourceManager.h>
37 @implementation _WOResourceImage
39 - (id)initWithName:(NSString *)_name
40 associations:(NSDictionary *)_config
41 template:(WOElement *)_t
43 if ((self = [super initWithName:_name associations:_config template:_t])) {
44 self->filename = OWGetProperty(_config, @"filename");
45 self->framework = OWGetProperty(_config, @"framework");
47 if (self->filename == nil) {
48 NSLog(@"missing filename association for WOImage ..");
54 if ([_config objectForKey:@"value"] ||
55 [_config objectForKey:@"data"] ||
56 [_config objectForKey:@"mimeType"] ||
57 [_config objectForKey:@"key"] ||
58 [_config objectForKey:@"src"]) {
59 NSLog(@"WARNING: inconsistent association settings in WOImage !"
60 @" (assign only one of value, src, data or filename)");
68 [self->framework release];
69 [self->filename release];
75 - (void)_appendSrcToResponse:(WOResponse *)_resp inContext:(WOContext *)_ctx {
76 WOComponent *sComponent;
79 WOResourceManager *rm;
80 NSString *frameworkName;
82 sComponent = [_ctx component];
84 if (self->filename == nil) {
85 [_resp appendContentHTMLAttributeValue:
86 @"/missingImage?reason=nofilenamebinding"];
90 if ((uFi = [self->filename stringValueInComponent:sComponent]) == nil) {
91 [_resp appendContentHTMLAttributeValue:
92 @"/missingImage?reason=nilfilenamebinding"];
96 if ((rm = [[_ctx component] resourceManager]) == nil)
97 rm = [[_ctx application] resourceManager];
99 languages = [_ctx hasSession] ? [[_ctx session] languages] : nil;
101 /* If 'framework' binding is not set, use parent component's framework */
102 if (self->framework){
103 frameworkName = [self->framework stringValueInComponent:sComponent];
104 if (frameworkName != nil && [frameworkName isEqualToString:@"app"])
108 frameworkName = [sComponent frameworkName];
110 uFi = [rm urlForResourceNamed:uFi
111 inFramework:frameworkName
113 request:[_ctx request]];
115 uFi = [self->filename stringValueInComponent:sComponent];
116 NSLog(@"%@: did not find resource '%@'", sComponent, uFi);
117 uFi = [@"/missingImage?" stringByAppendingString:uFi];
121 [self logWithFormat:@"RESOURCE IMAGE: %@", uFi];
123 [_resp appendContentHTMLAttributeValue:uFi];
128 - (NSString *)associationDescription {
129 NSMutableString *str = [NSMutableString stringWithCapacity:64];
131 [str appendFormat:@" filename=%@", self->filename];
132 if (self->framework) [str appendFormat:@" framework=%@", self->framework];
133 [str appendString:[super associationDescription]];
137 @end /* _WOResourceImage */