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/WODynamicElement.h>
24 @interface WEContextKey : WODynamicElement
34 @implementation WEContextKey
36 - (id)initWithName:(NSString *)_name
37 associations:(NSDictionary *)_config
38 template:(WOElement *)_tmp
40 if ((self = [super initWithName:_name associations:_config template:_tmp])) {
41 self->key = WOExtGetProperty(_config, @"key");
42 self->value = WOExtGetProperty(_config, @"value");
45 NSLog(@"Warning! WEContextKey no key set");
47 if (self->value == nil) {
48 self->value = [WOAssociation associationWithValue:@"YES"];
52 ASSIGN(self->template, _tmp);
57 #if !LIB_FOUNDATION_BOEHM_GC
61 RELEASE(self->template);
67 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
72 k = [self->key stringValueInComponent:[_ctx component]];
73 v = [self->value valueInComponent:[_ctx component]];
76 tmp = [_ctx objectForKey:k]; // save old context value
77 [_ctx setObject:v forKey:k];
80 [self->template takeValuesFromRequest:_req inContext:_ctx];
82 if (k && v) [_ctx removeObjectForKey:k];
83 if (tmp && k) [_ctx setObject:tmp forKey:k]; // restore old context value
86 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
92 k = [self->key stringValueInComponent:[_ctx component]];
93 v = [self->value valueInComponent:[_ctx component]];
96 tmp = [_ctx objectForKey:k]; // save old context value
97 [_ctx setObject:v forKey:k];
100 result = [self->template invokeActionForRequest:_req inContext:_ctx];
102 if (k && v) [_ctx removeObjectForKey:k];
103 if (tmp && k) [_ctx setObject:tmp forKey:k]; // restore old context value
108 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
113 k = [self->key stringValueInComponent:[_ctx component]];
114 v = [self->value valueInComponent:[_ctx component]];
117 tmp = [_ctx objectForKey:k]; // save old context value
118 [_ctx setObject:v forKey:k];
121 [self->template appendToResponse:_response inContext:_ctx];
123 if (k && v) [_ctx removeObjectForKey:k];
124 if (tmp && k) [_ctx setObject:tmp forKey:k]; // restore old context value
127 @end /* WEContextKey */