]> err.no Git - sope/blob - sope-appserver/WEExtensions/WEComponentValue.m
added strict OSX bundle dependencies
[sope] / sope-appserver / WEExtensions / WEComponentValue.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include <NGObjWeb/WODynamicElement.h>
23
24 @interface WEComponentValue : WODynamicElement
25 {
26   WOAssociation *value;
27   WOAssociation *boolValue;
28   WOAssociation *stringValue;
29   WOAssociation *intValue;
30   WOAssociation *unsignedIntValue;
31   WOAssociation *key;
32 }
33 @end
34
35 #include "common.h"
36
37 @implementation WEComponentValue
38
39 - (id)initWithName:(NSString *)_name
40   associations:(NSDictionary *)_config
41   template:(WOElement *)_tmp
42 {
43   if ((self = [super initWithName:_name associations:_config template:_tmp])) {
44     int cnt = 0;
45     
46     self->value            = WOExtGetProperty(_config, @"value");
47     self->boolValue        = WOExtGetProperty(_config, @"boolValue");
48     self->stringValue      = WOExtGetProperty(_config, @"stringValue");
49     self->intValue         = WOExtGetProperty(_config, @"intValue");
50     self->unsignedIntValue = WOExtGetProperty(_config, @"unsignedIntValue");
51     self->key              = WOExtGetProperty(_config, @"key");
52
53     if (self->value)            cnt++;
54     if (self->boolValue)        cnt++;
55     if (self->stringValue)      cnt++;
56     if (self->intValue)         cnt++;
57     if (self->unsignedIntValue) cnt++;
58
59     if (cnt == 0)
60       NSLog(@"Warning: WEComponentValue neither 'value', 'boolValue',"
61             @"  'stringValue', 'intValue' nor 'unsignedIntValue' is set");
62     if (cnt > 0)
63       NSLog(@"Warning: WEComponentValue more than one '*Value' is set");
64   }
65   return self;
66 }
67
68 #if !LIB_FOUNDATION_BOEHM_GC
69 - (void)dealloc {
70   RELEASE(self->value);
71   RELEASE(self->boolValue);
72   RELEASE(self->stringValue);
73   RELEASE(self->intValue);
74   RELEASE(self->unsignedIntValue);
75   RELEASE(self->key);
76   [super dealloc];
77 }
78 #endif
79   
80 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
81   WOComponent *comp;
82   NSString    *k;
83   id          v;
84   SEL         sel;
85
86   comp = [_ctx component];
87   k    = [self->key stringValueInComponent:comp];
88
89   if (k == nil) return;
90
91   sel = NSSelectorFromString([k stringByAppendingString:@":"]);
92   sel = ([comp respondsToSelector:sel]) ? sel : NULL;
93
94 #define _assign(_v_, _k_)                                            \
95                    {                                                 \
96                      if (sel != NULL)                                \
97                        [comp performSelector:sel withObject:_v_];    \
98                      else                                            \
99                        [comp takeValue:_v_ forKey:_k_];              \
100                    }                                                 \
101
102   if ((v = [self->value valueInComponent:comp])) {
103     _assign(v, k);
104   }
105   else if (self->boolValue) {
106     v = [NSNumber numberWithBool:[self->boolValue boolValueInComponent:comp]];
107     _assign(v, k);
108   }
109   else if ((v = [self->stringValue stringValueInComponent:comp])) {
110     _assign(v, k);
111   }
112   else if (self->intValue) {
113     v = [NSNumber numberWithInt:[self->intValue intValueInComponent:comp]];
114     _assign(v, k);
115   }
116   else if (self->unsignedIntValue) {
117     v = [NSNumber numberWithUnsignedInt:
118                   [self->unsignedIntValue unsignedIntValueInComponent:comp]];
119     _assign(v, k);
120   }
121     
122 #undef _assignValue
123 }
124
125 @end /* WEComponentValue */