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>
26 #include <NGObjWeb/WODynamicElement.h>
29 #define FRAME_TYPE_None 0
30 #define FRAME_TYPE_Page 1
31 #define FRAME_TYPE_Href 2
32 #define FRAME_TYPE_Value 3
33 #define FRAME_TYPE_DA 4
35 @interface WOFrame : WOHTMLDynamicElement
37 // WODynamicElement: extraAttributes
38 // WODynamicElement: otherTagString
41 WOAssociation *queryDictionary;
42 NSDictionary *queryParameters; /* associations beginning with ? */
47 @interface _WOPageFrame : WOFrame
49 WOAssociation *pageName;
53 @interface _WOHrefFrame : WOFrame
59 @interface _WOValueFrame : WOFrame
65 @interface _WODirectActionFrame : WOFrame
67 WOAssociation *actionClass;
68 WOAssociation *directActionName;
69 BOOL sidInUrl; /* include session-id in wa URL ? */
73 @interface WOFrame(PrivateMethods)
75 - (id)_initWithName:(NSString *)_name
76 associations:(NSDictionary *)_config
77 template:(WOElement *)_t;
79 - (NSString *)associationDescription;
83 #if COCOA_Foundation_LIBRARY || NeXT_Foundation_LIBRARY
84 @interface NSObject(Miss)
85 - (void)subclassResponsibility:(SEL)_cmd;
89 @implementation WOFrame
95 - (id)initWithName:(NSString *)_name
96 associations:(NSDictionary *)_config
97 template:(WOElement *)_t
99 Class frameClass = Nil;
101 if ([_config objectForKey:@"value"])
102 frameClass = [_WOValueFrame class];
103 else if ([_config objectForKey:@"pageName"])
104 frameClass = [_WOPageFrame class];
105 else if ([_config objectForKey:@"src"])
106 frameClass = [_WOHrefFrame class];
108 frameClass = [_WODirectActionFrame class];
111 return [[frameClass alloc]
112 initWithName:_name associations:_config template:_t];
115 - (id)_initWithName:(NSString *)_name
116 associations:(NSDictionary *)_config
117 template:(WOElement *)_tmpl
119 if ((self = [super initWithName:_name associations:_config template:_tmpl])) {
120 self->queryDictionary = OWGetProperty(_config, @"queryDictionary");
121 self->queryParameters = OWExtractQueryParameters(_config);
127 RELEASE(self->queryDictionary);
128 RELEASE(self->queryParameters);
132 // ******************** responder ********************
134 #define StrVal(__x__) [self->__x__ stringValueInComponent:sComponent]
136 - (BOOL)_appendHrefToResponse:(WOResponse *)_response
137 inContext:(WOContext *)_ctx
139 [self subclassResponsibility:_cmd];
143 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
144 WOComponent *sComponent = [_ctx component];
145 NSString *queryString = nil;
146 if ([[_ctx request] isFromClientComponent])
149 WOResponse_AddCString(_response, "<frame src=\"");
151 if ([self _appendHrefToResponse:_response inContext:_ctx]) {
152 queryString = [self queryStringForQueryDictionary:
153 [self->queryDictionary valueInComponent:sComponent]
154 andQueryParameters:self->queryParameters
159 [_response appendContentCharacter:'?'];
160 WOResponse_AddString(_response, queryString);
162 WOResponse_AddChar(_response, '"');
164 [self appendExtraAttributesToResponse:_response inContext:_ctx];
166 if (self->otherTagString) {
167 WOResponse_AddChar(_response, ' ');
168 WOResponse_AddString(_response,
169 [self->otherTagString stringValueInComponent:
172 WOResponse_AddEmptyCloseParens(_response, _ctx);
177 - (NSString *)associationDescription {
183 @implementation _WOPageFrame
185 - (id)initWithName:(NSString *)_name
186 associations:(NSDictionary *)_config
187 template:(WOElement *)_t
189 if ((self = [super _initWithName:_name associations:_config template:_t])) {
190 self->pageName = OWGetProperty(_config, @"pageName");
192 if (self->pageName == nil) {
193 NSLog(@"missing pageName association for WOFrame ..");
199 if ([_config objectForKey:@"value"] ||
200 [_config objectForKey:@"src"] ||
201 [_config objectForKey:@"directActionName"] ||
202 [_config objectForKey:@"actionClass"]) {
203 NSLog(@"WARNING: inconsistent association settings in WOFrame !"
204 @" (assign only one of pageName, href, "
205 @"directActionName or action)");
212 #if !LIB_FOUNDATION_BOEHM_GC
214 RELEASE(self->pageName);
219 /* value generation */
221 - (id)invokeActionForRequest:(WORequest *)_request
222 inContext:(WOContext *)_ctx
227 name = [self->pageName stringValueInComponent:[_ctx component]];
228 page = [[WOApplication application] pageWithName:name inContext:_ctx];
230 [[_ctx component] debugWithFormat:@"deliver page %@", [page name]];
235 /* href generation */
237 - (BOOL)_appendHrefToResponse:(WOResponse *)_response
238 inContext:(WOContext *)_ctx
240 WOResponse_AddString(_response, [_ctx componentActionURL]);
246 - (NSString *)associationDescription {
247 NSMutableString *str = [NSMutableString stringWithCapacity:256];
249 [str appendFormat:@" pageName=%@", self->pageName];
250 [str appendString:[super associationDescription]];
254 @end /* _WOPageFrame */
256 @implementation _WOHrefFrame
258 - (id)initWithName:(NSString *)_name
259 associations:(NSDictionary *)_config
260 template:(WOElement *)_t
262 if ((self = [super _initWithName:_name associations:_config template:_t])) {
263 self->src = OWGetProperty(_config, @"src");
265 if (self->src == nil) {
266 NSLog(@"missing src association for WOFrame ..");
272 if ([_config objectForKey:@"value"] ||
273 [_config objectForKey:@"pageName"] ||
274 [_config objectForKey:@"directActionName"] ||
275 [_config objectForKey:@"actionClass"]) {
276 NSLog(@"WARNING: inconsistent association settings in WOFrame !"
277 @" (assign only one of pageName, src, directActionName or value)");
284 #if !LIB_FOUNDATION_BOEHM_GC
293 - (BOOL)_appendHrefToResponse:(WOResponse *)_r inContext:(WOContext *)_ctx {
294 WOResponse_AddString(_r, [self->src stringValueInComponent:[_ctx component]]);
300 - (NSString *)associationDescription {
301 NSMutableString *str = [NSMutableString stringWithCapacity:256];
303 [str appendFormat:@" src=%@", self->src];
304 [str appendString:[super associationDescription]];
309 @end /* _WOHrefFrame */
311 @implementation _WODirectActionFrame
313 - (id)initWithName:(NSString *)_name
314 associations:(NSDictionary *)_config
315 template:(WOElement *)_t
317 if ((self = [super _initWithName:_name associations:_config template:_t])) {
318 WOAssociation *sidInUrlAssoc;
320 sidInUrlAssoc = OWGetProperty(_config, @"?wosid");
321 self->actionClass = OWGetProperty(_config, @"actionClass");
322 self->directActionName = OWGetProperty(_config, @"directActionName");
324 self->sidInUrl = (sidInUrlAssoc)
325 ? [sidInUrlAssoc boolValueInComponent:nil]
329 if ([_config objectForKey:@"value"] ||
330 [_config objectForKey:@"src"] ||
331 [_config objectForKey:@"pageName"]) {
332 NSLog(@"WARNING: inconsistent association settings in WOFrame !"
333 @" (assign only one of value, src, directActionName or pageName)");
340 #if !LIB_FOUNDATION_BOEHM_GC
342 RELEASE(self->actionClass);
343 RELEASE(self->directActionName);
350 - (BOOL)_appendHrefToResponse:(WOResponse *)_response
351 inContext:(WOContext *)_ctx
353 WOComponent *sComponent;
356 NSMutableDictionary *qd;
359 sComponent = [_ctx component];
360 daClass = [self->actionClass stringValueInComponent:sComponent];
361 daName = [self->directActionName stringValueInComponent:sComponent];
365 if (![daClass isEqualToString:@"DirectAction"])
366 daName = [NSString stringWithFormat:@"%@/%@", daClass, daName];
372 qd = [NSMutableDictionary dictionaryWithCapacity:16];
374 /* add query dictionary */
376 if (self->queryDictionary) {
377 if ((tmp = [self->queryDictionary valueInComponent:sComponent]))
378 [qd addEntriesFromDictionary:tmp];
381 /* add ?style parameters */
383 if (self->queryParameters) {
387 keys = [self->queryParameters keyEnumerator];
388 while ((key = [keys nextObject])) {
391 assoc = [self->queryParameters objectForKey:key];
392 value = [assoc stringValueInComponent:sComponent];
394 [qd setObject:(value != nil ? value : (id)@"") forKey:key];
400 if (self->sidInUrl) {
401 if ([_ctx hasSession]) {
402 WOSession *sn = [_ctx session];
404 [qd setObject:[sn sessionID] forKey:WORequestValueSessionID];
406 if (![sn isDistributionEnabled]) {
407 [qd setObject:[[WOApplication application] number]
408 forKey:WORequestValueInstance];
413 WOResponse_AddString(_response,
414 [_ctx directActionURLForActionNamed:daName
415 queryDictionary:qd]);
421 - (NSString *)associationDescription {
422 NSMutableString *str = [NSMutableString stringWithCapacity:256];
424 if (self->actionClass)
425 [str appendFormat:@" actionClass=%@", self->actionClass];
426 if (self->directActionName)
427 [str appendFormat:@" directAction=%@", self->directActionName];
429 [str appendString:[super associationDescription]];
433 @end /* _WODirectActionFrame */
435 @implementation _WOValueFrame
437 - (id)initWithName:(NSString *)_name
438 associations:(NSDictionary *)_config
439 template:(WOElement *)_t
441 if ((self = [super _initWithName:_name associations:_config template:_t])) {
442 self->value = OWGetProperty(_config, @"value");
444 if (self->value == nil) {
445 NSLog(@"missing value association for WOFrame ..");
451 if ([_config objectForKey:@"pageName"] ||
452 [_config objectForKey:@"href"] ||
453 [_config objectForKey:@"directActionName"] ||
454 [_config objectForKey:@"actionClass"]) {
455 NSLog(@"WARNING: inconsistent association settings in WOFrame !"
456 @" (assign only one of pageName, href, directActionName or value)");
463 #if !LIB_FOUNDATION_BOEHM_GC
465 RELEASE(self->value);
470 /* dynamic invocation */
472 - (id)invokeActionForRequest:(WORequest *)_request
473 inContext:(WOContext *)_ctx
475 return [self->value valueInComponent:[_ctx component]];
478 - (BOOL)_appendHrefToResponse:(WOResponse *)_response
479 inContext:(WOContext *)_ctx
481 WOResponse_AddString(_response, [_ctx componentActionURL]);
487 - (NSString *)associationDescription {
488 NSMutableString *str = [NSMutableString stringWithCapacity:256];
490 [str appendFormat:@" value=%@", self->value];
491 [str appendString:[super associationDescription]];
495 @end /* _WOValueFrame */