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"
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 #import "WOElement+private.h"
43 #import "WOContext+private.h"
44 #import "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 copyWithZone:[self zone]];
57 [(NSMutableDictionary *)_config removeAllObjects];
59 self->template = RETAIN(_c);
64 #if !LIB_FOUNDATION_BOEHM_GC
66 RELEASE(self->template);
67 RELEASE(self->componentName);
68 RELEASE(self->bindings);
73 - (WOComponent *)lookupComponent:(NSString *)cname inContext:(WOContext *)_ctx {
74 WOComponent *component;
79 if ((component = [[_ctx component] pageWithName:cname]) == nil) {
80 [[_ctx component] debugWithFormat:@"couldn't find component '%@'", cname];
84 [component setParent:[_ctx component]];
85 [component setBindings:self->bindings];
92 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
96 cname = [self->componentName stringValueInComponent:[_ctx component]];
98 if ((c = [self lookupComponent:cname inContext:_ctx]) == nil)
101 [_ctx appendElementIDComponent:cname];
102 [_ctx enterComponent:c content:self->template];
103 [c takeValuesFromRequest:_req inContext:_ctx];
104 [_ctx leaveComponent:c];
105 [_ctx deleteLastElementIDComponent];
108 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
111 NSString *cname, *reqname;
113 if ((reqname = [_ctx currentElementID]) == nil)
114 /* missing id in request */
117 cname = [self->componentName stringValueInComponent:[_ctx component]];
119 if (![cname isEqualToString:reqname]) {
120 /* component mismatch */
121 [[_ctx component] logWithFormat:
122 @"WOSwitchComponent: component name mismatch (%@ vs %@),"
128 if ((c = [self lookupComponent:cname inContext:_ctx]) == nil)
131 [_ctx appendElementIDComponent:cname];
132 [_ctx enterComponent:c content:self->template];
133 result = [c invokeActionForRequest:_req inContext:_ctx];
134 [_ctx leaveComponent:c];
135 [_ctx deleteLastElementIDComponent];
140 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
144 cname = [self->componentName stringValueInComponent:[_ctx component]];
146 if ((c = [self lookupComponent:cname inContext:_ctx]) == nil)
149 [_ctx appendElementIDComponent:cname];
150 [_ctx enterComponent:c content:self->template];
151 [c appendToResponse:_response inContext:_ctx];
152 [_ctx leaveComponent:c];
153 [_ctx deleteLastElementIDComponent];
156 @end /* WOSwitchComponent */