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 <NGObjWeb/WOHTMLDynamicElement.h>
27
@interface WOSwitchComponent : WOHTMLDynamicElement
29
// WODynamicElement: extraAttributes
30
// WODynamicElement: otherTagString
32
WOAssociation *componentName; // WOComponentName attribute
33
NSDictionary *bindings;
39
#include <NGObjWeb/WOComponent.h>
40
#include <NGObjWeb/WOAssociation.h>
41
#include <NGObjWeb/WOContext.h>
42
#include "WOElement+private.h"
43
#include "WOContext+private.h"
44
#include "WOComponent+private.h"
47
@implementation WOSwitchComponent
49
- (id)initWithName:(NSString *)_name
50
associations:(NSDictionary *)_config
51
template:(WOElement *)_c
53
if ((self = [super initWithName:_name associations:_config template:_c])) {
54
self->containsForm = YES;
55
self->componentName = OWGetProperty(_config, @"WOComponentName");
56
self->bindings = [_config copy];
57
[(NSMutableDictionary *)_config removeAllObjects];
59
self->template = [_c retain];
65
[self->template release];
66
[self->componentName release];
67
[self->bindings release];
71
/* component lookup */
73
- (WOComponent *)lookupComponent:(NSString *)cname
74
inContext:(WOContext *)_ctx
76
WOComponent *component;
81
if ((component = [[_ctx component] pageWithName:cname]) == nil) {
82
[[_ctx component] debugWithFormat:@"couldn't find component '%@'", cname];
86
[component setParent:[_ctx component]];
87
[component setBindings:self->bindings];
92
/* handling requests */
94
- (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
98
cname = [self->componentName stringValueInComponent:[_ctx component]];
100
if ((c = [self lookupComponent:cname inContext:_ctx]) == nil)
103
[_ctx appendElementIDComponent:cname];
104
[_ctx enterComponent:c content:self->template];
105
[c takeValuesFromRequest:_req inContext:_ctx];
106
[_ctx leaveComponent:c];
107
[_ctx deleteLastElementIDComponent];
110
- (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
113
NSString *cname, *reqname;
115
if ((reqname = [_ctx currentElementID]) == nil)
116
/* missing id in request */
119
cname = [self->componentName stringValueInComponent:[_ctx component]];
121
if (![cname isEqualToString:reqname]) {
122
/* component mismatch */
123
[[_ctx component] logWithFormat:
124
@"WOSwitchComponent: component name mismatch"
125
@" (%@ vs %@), ignoring action.",
130
if ((c = [self lookupComponent:cname inContext:_ctx]) == nil)
132
[_ctx consumeElementID];
134
[_ctx appendElementIDComponent:cname];
135
[_ctx enterComponent:c content:self->template];
136
result = [c invokeActionForRequest:_req inContext:_ctx];
137
[_ctx leaveComponent:c];
138
[_ctx deleteLastElementIDComponent];
143
/* generate response */
145
- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
149
cname = [self->componentName stringValueInComponent:[_ctx component]];
151
if ((c = [self lookupComponent:cname inContext:_ctx]) == nil)
154
[_ctx appendElementIDComponent:cname];
155
[_ctx enterComponent:c content:self->template];
156
[c appendToResponse:_response inContext:_ctx];
157
[_ctx leaveComponent:c];
158
[_ctx deleteLastElementIDComponent];
161
@end /* WOSwitchComponent */