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 "WOElement+private.h"
23 #include "WOHTMLDynamicElement.h"
24 #include <NGObjWeb/WOApplication.h>
25 #include <NGObjWeb/WOResourceManager.h>
30 @interface WOBody : WOHTMLDynamicElement
32 // WODynamicElement: extraAttributes
33 // WODynamicElement: otherTagString
35 WOAssociation *filename; // path relative to WebServerResources
36 WOAssociation *framework;
37 WOAssociation *src; // absolute URL
38 WOAssociation *value; // image data (eg from a database)
45 @implementation WOBody
47 - (id)initWithName:(NSString *)_name
48 associations:(NSDictionary *)_config
49 template:(WOElement *)_c
51 if ((self = [super initWithName:_name associations:_config template:_c])) {
52 self->filename = OWGetProperty(_config, @"filename");
53 self->framework = OWGetProperty(_config, @"framework");
54 self->src = OWGetProperty(_config, @"src");
55 self->value = OWGetProperty(_config, @"value");
57 self->template = [_c retain];
59 if (self->value) NSLog(@"WARNING: value not yet supported !");
65 [self->template release];
66 [self->framework release];
67 [self->filename release];
69 [self->value release];
75 - (WOElement *)template {
76 return self->template;
79 /* handling requests */
81 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
82 [self->template takeValuesFromRequest:_req inContext:_ctx];
84 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
85 return [self->template invokeActionForRequest:_req inContext:_ctx];
88 /* generating response */
90 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
94 if ([[_ctx request] isFromClientComponent]) {
95 [self->template appendToResponse:_response inContext:_ctx];
99 uUri = [self->src stringValueInComponent:[_ctx component]];
100 uFi = [self->filename stringValueInComponent:[_ctx component]];
102 WOResponse_AddCString(_response, "<body");
104 if ([uFi length] > 0) {
106 WOResourceManager *rm;
107 NSString *frameworkName;
109 WOResponse_AddCString(_response, " background=\"");
111 languages = [_ctx resourceLookupLanguages];
113 if ((rm = [[_ctx component] resourceManager]) == nil)
114 rm = [[_ctx application] resourceManager];
116 /* If 'framework' binding is not set, use parent component's framework */
117 if (self->framework){
118 frameworkName = [self->framework stringValueInComponent:[_ctx component]];
119 if (frameworkName != nil && [frameworkName isEqualToString:@"app"])
123 frameworkName = [[_ctx component] frameworkName];
125 uFi = [rm urlForResourceNamed:uFi
126 inFramework:frameworkName
128 request:[_ctx request]];
130 NSLog(@"%@: did not find resource '%@' (languages=%@)",
132 [self->filename stringValueInComponent:[_ctx component]],
133 [languages componentsJoinedByString:@","]);
136 [_response appendContentHTMLAttributeValue:uFi];
137 WOResponse_AddChar(_response, '"');
139 else if ([uUri length] > 0) {
140 WOResponse_AddCString(_response, " background=\"");
141 [_response appendContentHTMLAttributeValue:uUri];
142 WOResponse_AddChar(_response, '"');
145 [self appendExtraAttributesToResponse:_response inContext:_ctx];
147 if (self->otherTagString) {
148 WOResponse_AddChar(_response, ' ');
149 WOResponse_AddString(_response,
150 [self->otherTagString stringValueInComponent:
153 WOResponse_AddChar(_response, '>');
155 [self->template appendToResponse:_response inContext:_ctx];
157 WOResponse_AddCString(_response, "</body>");
162 - (NSString *)associationDescription {
163 NSMutableString *str;
165 str = [NSMutableString stringWithCapacity:128];
166 if (self->filename) [str appendFormat:@" filename=%@", self->filename];
167 if (self->framework) [str appendFormat:@" framework=%@", self->framework];
168 if (self->src) [str appendFormat:@" src=%@", self->src];
169 if (self->value) [str appendFormat:@" value=%@", self->value];
170 if (self->template) [str appendFormat:@" template=%@", self->template];