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 "WOHTMLDynamicElement.h"
23
#include "WOElement+private.h"
24
#include <NGObjWeb/WOResourceManager.h>
25
#include <NGObjWeb/WOApplication.h>
28
@interface WOEmbeddedObject : WOHTMLDynamicElement
30
// WODynamicElement: extraAttributes
31
// WODynamicElement: otherTagString
33
WOAssociation *filename; // path relative to WebServerResources
34
WOAssociation *framework;
35
WOAssociation *src; // absolute URL
36
WOAssociation *value; // data (eg from a database)
40
WOAssociation *mimeType;
44
@end /* WOEmbeddedObject */
46
@implementation WOEmbeddedObject
48
- (id)initWithName:(NSString *)_name
49
associations:(NSDictionary *)_config
50
template:(WOElement *)_tmpl
52
if ((self = [super initWithName:_name associations:_config template:_tmpl])) {
53
self->filename = OWGetProperty(_config, @"filename");
54
self->framework = OWGetProperty(_config, @"framework");
55
self->src = OWGetProperty(_config, @"src");
56
self->value = OWGetProperty(_config, @"value");
58
self->data = OWGetProperty(_config, @"data");
59
self->mimeType = OWGetProperty(_config, @"mimeType");
60
self->key = OWGetProperty(_config, @"key");
63
NSLog(@"WARNING: 'key' association in WOEmbeddedObject not supported !");
68
#if !LIB_FOUNDATION_BOEHM_GC
72
RELEASE(self->mimeType);
73
RELEASE(self->framework);
74
RELEASE(self->filename);
81
// ******************** responder ********************
83
- (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
87
if ((element = [self->value valueInComponent:[_ctx component]]) == nil) {
88
[[_ctx session] debugWithFormat:
89
@"WARNING: missing element value for WOEmbeddedObject %@", self];
93
[element appendToResponse:[_ctx response] inContext:_ctx];
94
return [_ctx response];
96
else if (self->data) {
97
WOComponent *sComponent;
100
WOResponse *response;
102
sComponent = [_ctx component];
103
adata = [self->data valueInComponent:sComponent];
104
atype = [self->mimeType stringValueInComponent:sComponent];
106
response = [_ctx response];
108
[response setContent:adata];
109
[response setHeader:atype ? atype : @"application/octet-stream"
110
forKey:@"content-type"];
115
[[_ctx session] debugWithFormat:
116
@"no value configured for WOEmbeddedObject %@", self];
121
#define StrVal(__x__) [self->__x__ stringValueInComponent:sComponent]
123
- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
124
if (![[_ctx request] isFromClientComponent]) {
125
WOComponent *sComponent = [_ctx component];
126
NSString *uUri = [self->src stringValueInComponent:sComponent];
127
NSString *uFi = [self->filename stringValueInComponent:sComponent];
130
sComponent = [_ctx component];
131
uUri = [self->src stringValueInComponent:sComponent];
132
uFi = [self->filename stringValueInComponent:sComponent];
134
WOResponse_AddCString(_response, "<embed src=\"");
136
if ((self->data != nil) || (self->value != nil)) {
137
/* a component action link */
138
uUri = [_ctx componentActionURL];
140
uUri = [uUri stringByAppendingString:@"/"];
141
uUri = [uUri stringByAppendingString:uFi];
143
WOResponse_AddString(_response, uUri);
146
WOResourceManager *rm;
147
NSString *frameworkName;
149
if ((rm = [[_ctx component] resourceManager]) == nil)
150
rm = [[_ctx application] resourceManager];
152
/* If 'framework' binding is not set, use parent component's framework */
153
if (self->framework){
154
frameworkName = [self->framework stringValueInComponent:[_ctx component]];
155
if (frameworkName != nil && [frameworkName isEqualToString:@"app"])
159
frameworkName = [[_ctx component] frameworkName];
161
languages = [_ctx hasSession]
162
? [[_ctx session] languages]
163
: [[_ctx request] browserLanguages];
164
uFi = [rm urlForResourceNamed:uFi
165
inFramework:frameworkName
167
request:[_ctx request]];
169
NSLog(@"%@: did not find resource '%@'", sComponent,
170
[self->filename stringValueInComponent:sComponent]);
173
[_response appendContentHTMLAttributeValue:uFi];
176
[_response appendContentHTMLAttributeValue:uUri];
179
[sComponent logWithFormat:@"missing resource URL for element %@", self];
182
WOResponse_AddChar(_response, '"');
184
[self appendExtraAttributesToResponse:_response inContext:_ctx];
185
if (self->otherTagString) {
186
WOResponse_AddChar(_response, ' ');
187
WOResponse_AddString(_response,
188
[self->otherTagString stringValueInComponent:
191
WOResponse_AddCString(_response, " />");
197
- (NSString *)associationDescription {
198
NSMutableString *str = [[NSMutableString alloc] init];
200
if (self->filename) [str appendFormat:@" filename=%@", self->filename];
201
if (self->framework) [str appendFormat:@" framework=%@", self->framework];
202
if (self->src) [str appendFormat:@" src=%@", self->src];
203
if (self->value) [str appendFormat:@" value=%@", self->value];
205
return AUTORELEASE(str);
208
@end /* WOEmbeddedObject */