]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/_WOResourceImage.m
added svn:keywords and svn:ignore where appropriate. removed CVS artifacts.
[sope] / sope-appserver / NGObjWeb / DynamicElements / _WOResourceImage.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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 "WOImage.h"
24
25 @interface _WOResourceImage : WOImage
26 {
27   WOAssociation *filename;  // path relative to WebServerResources
28   WOAssociation *framework;
29 }
30 @end
31
32 #include "WOElement+private.h"
33 #include <NGObjWeb/WOApplication.h>
34 #include <NGObjWeb/WOResourceManager.h>
35 #include "common.h"
36
37 @implementation _WOResourceImage
38
39 - (id)initWithName:(NSString *)_name
40   associations:(NSDictionary *)_config
41   template:(WOElement *)_t
42 {
43   if ((self = [super initWithName:_name associations:_config template:_t])) {
44     self->filename  = OWGetProperty(_config, @"filename");
45     self->framework = OWGetProperty(_config, @"framework");
46     
47     if (self->filename == nil) {
48       NSLog(@"missing filename association for WOImage ..");
49       [self release];
50       return nil;
51     }
52
53 #if DEBUG
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)");
61     }
62 #endif
63   }
64   return self;
65 }
66
67 - (void)dealloc {
68   [self->framework release];
69   [self->filename  release];
70   [super dealloc];
71 }
72
73 /* HTML generation */
74
75 - (void)_appendSrcToResponse:(WOResponse *)_resp inContext:(WOContext *)_ctx {
76   WOComponent *sComponent;
77   NSString    *uFi;
78   NSArray     *languages;
79   WOResourceManager *rm;
80   NSString    *frameworkName;
81   
82   sComponent = [_ctx component];
83
84   if (self->filename == nil) {
85     [_resp appendContentHTMLAttributeValue:
86              @"/missingImage?reason=nofilenamebinding"];
87     return;
88   }
89   
90   if ((uFi = [self->filename stringValueInComponent:sComponent]) == nil) {
91     [_resp appendContentHTMLAttributeValue:
92              @"/missingImage?reason=nilfilenamebinding"];
93     return;
94   }
95   
96   if ((rm = [[_ctx component] resourceManager]) == nil)
97     rm = [[_ctx application] resourceManager];
98   
99   languages = [_ctx hasSession] ? [[_ctx session] languages] : nil;
100   
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"])
105       frameworkName = nil;
106   }
107   else
108     frameworkName = [sComponent frameworkName];
109
110   uFi = [rm urlForResourceNamed:uFi
111             inFramework:frameworkName
112             languages:languages
113             request:[_ctx request]];
114   if (uFi == nil) {
115     uFi = [self->filename stringValueInComponent:sComponent];
116     NSLog(@"%@: did not find resource '%@'", sComponent, uFi);
117     uFi = [@"/missingImage?" stringByAppendingString:uFi];
118   }
119   
120 #if HEAVY_DEBUG
121   [self logWithFormat:@"RESOURCE IMAGE: %@", uFi];
122 #endif
123   [_resp appendContentHTMLAttributeValue:uFi];
124 }
125
126 /* description */
127
128 - (NSString *)associationDescription {
129   NSMutableString *str = [NSMutableString stringWithCapacity:64];
130
131   [str appendFormat:@" filename=%@", self->filename];
132   if (self->framework) [str appendFormat:@" framework=%@", self->framework];
133   [str appendString:[super associationDescription]];
134   return str;
135 }
136
137 @end /* _WOResourceImage */