2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include <NGObjWeb/WODynamicElement.h>
25 @interface WEContextKey : WODynamicElement
35 @implementation WEContextKey
37 - (id)initWithName:(NSString *)_name
38 associations:(NSDictionary *)_config
39 template:(WOElement *)_tmp
41 if ((self = [super initWithName:_name associations:_config template:_tmp])) {
42 self->key = WOExtGetProperty(_config, @"key");
43 self->value = WOExtGetProperty(_config, @"value");
46 NSLog(@"Warning! WEContextKey no key set");
48 if (self->value == nil) {
49 self->value = [WOAssociation associationWithValue:@"YES"];
53 ASSIGN(self->template, _tmp);
58 #if !LIB_FOUNDATION_BOEHM_GC
62 RELEASE(self->template);
68 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
73 k = [self->key stringValueInComponent:[_ctx component]];
74 v = [self->value valueInComponent:[_ctx component]];
77 tmp = [_ctx objectForKey:k]; // save old context value
78 [_ctx setObject:v forKey:k];
81 [self->template takeValuesFromRequest:_req inContext:_ctx];
83 if (k && v) [_ctx removeObjectForKey:k];
84 if (tmp && k) [_ctx setObject:tmp forKey:k]; // restore old context value
87 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
93 k = [self->key stringValueInComponent:[_ctx component]];
94 v = [self->value valueInComponent:[_ctx component]];
97 tmp = [_ctx objectForKey:k]; // save old context value
98 [_ctx setObject:v forKey:k];
101 result = [self->template invokeActionForRequest:_req inContext:_ctx];
103 if (k && v) [_ctx removeObjectForKey:k];
104 if (tmp && k) [_ctx setObject:tmp forKey:k]; // restore old context value
109 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
114 k = [self->key stringValueInComponent:[_ctx component]];
115 v = [self->value valueInComponent:[_ctx component]];
118 tmp = [_ctx objectForKey:k]; // save old context value
119 [_ctx setObject:v forKey:k];
122 [self->template appendToResponse:_response inContext:_ctx];
124 if (k && v) [_ctx removeObjectForKey:k];
125 if (tmp && k) [_ctx setObject:tmp forKey:k]; // restore old context value
128 @end /* WEContextKey */