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 WERichString : WODynamicElement
26 WOAssociation *isBold;
27 WOAssociation *isItalic;
28 WOAssociation *isUnderlined;
29 WOAssociation *isSmall;
33 WOAssociation *insertBR;
35 WOAssociation *condition;
36 WOAssociation *negate;
38 WOAssociation *formatter;
47 #include <NGObjWeb/NGObjWeb.h>
50 @implementation WERichString
52 - (id)initWithName:(NSString *)_name
53 associations:(NSDictionary *)_config
54 template:(WOElement *)_t
56 if ((self = [super initWithName:_name associations:_config template:_t])) {
57 self->value = OWGetProperty(_config, @"value");
59 self->isBold = OWGetProperty(_config, @"isBold");
60 self->isItalic = OWGetProperty(_config, @"isItalic");
61 self->isUnderlined = OWGetProperty(_config, @"isUnderlined");
62 self->isSmall = OWGetProperty(_config, @"isSmall");
63 self->color = OWGetProperty(_config, @"color");
64 self->face = OWGetProperty(_config, @"face");
65 self->size = OWGetProperty(_config, @"size");
66 self->insertBR = OWGetProperty(_config, @"insertBR");
68 self->condition = OWGetProperty(_config, @"condition");
69 self->negate = OWGetProperty(_config, @"negate");
71 self->formatter = OWGetProperty(_config, @"formatter");
73 ASSIGN(self->template, _t);
80 RELEASE(self->isBold);
81 RELEASE(self->isItalic);
82 RELEASE(self->isUnderlined);
83 RELEASE(self->isSmall);
87 RELEASE(self->insertBR);
88 RELEASE(self->formatter);
90 RELEASE(self->condition);
91 RELEASE(self->negate);
93 RELEASE(self->template);
98 static inline BOOL _doShow(WERichString *self, WOContext *_ctx) {
102 if (self->condition != nil) {
103 doShow = [self->condition boolValueInComponent:[_ctx component]];
104 doNegate = [self->negate boolValueInComponent:[_ctx component]];
107 return (doNegate) ? !doShow : doShow;
110 - (void)takeValuesFromRequest:(WORequest *)_request
111 inContext:(WOContext *)_ctx
113 if (_doShow(self, _ctx)) {
114 [_ctx appendElementIDComponent:@"1"];
115 [self->template takeValuesFromRequest:_request inContext:_ctx];
116 [_ctx deleteLastElementIDComponent];
120 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
123 state = [[_ctx currentElementID] stringValue];
126 [_ctx consumeElementID]; // consume state-id (on or off)
128 if ([state isEqualToString:@"1"]) {
131 [_ctx appendElementIDComponent:state];
132 result = [self->template invokeActionForRequest:_request inContext:_ctx];
133 [_ctx deleteLastElementIDComponent];
141 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
142 WOComponent *comp = nil;
145 BOOL doUnderlined = NO;
147 NSString *color_ = nil;
148 NSString *face_ = nil;
149 NSString *size_ = nil;
150 NSFormatter *fmt = nil;
154 if (!_doShow(self, _ctx)) return;
156 comp = [_ctx component];
158 doBold = [self->isBold boolValueInComponent:comp];
159 doItalic = [self->isItalic boolValueInComponent:comp];
160 doUnderlined = [self->isUnderlined boolValueInComponent:comp];
161 doSmall = [self->isSmall boolValueInComponent:comp];
162 face_ = [self->face stringValueInComponent:comp];
163 color_ = [self->color stringValueInComponent:comp];
164 size_ = [self->size stringValueInComponent:comp];
165 v = [self->value valueInComponent:comp];
166 fmt = [self->formatter valueInComponent:comp];
169 [_response appendContentString:@"<small>"];
171 [_response appendContentString:@"<b>"];
173 [_response appendContentString:@"<i>"];
175 [_response appendContentString:@"<u>"];
177 [_response appendContentString:@"<font"];
179 [_response appendContentString:@" color='"];
180 [_response appendContentHTMLString:color_];
181 [_response appendContentCharacter:'\''];
184 [_response appendContentString:@" face='"];
185 [_response appendContentHTMLString:face_];
186 [_response appendContentCharacter:'\''];
189 [_response appendContentString:@" size='"];
190 [_response appendContentHTMLString:size_];
191 [_response appendContentCharacter:'\''];
193 [_response appendContentCharacter:'>'];
195 [_ctx appendElementIDComponent:@"1"];
196 [self->template appendToResponse:_response inContext:_ctx];
197 [_ctx deleteLastElementIDComponent];
200 ? [fmt stringForObjectValue:v]
203 if (v && [self->insertBR boolValueInComponent:comp]) {
207 lines = [v componentsSeparatedByString:@"\n"];
208 count = [lines count];
209 for (i = 0; i < count; i++) {
210 NSString *line = [lines objectAtIndex:i];
213 [_response appendContentString:
214 (_ctx->wcFlags.xmlStyleEmptyElements)?@"<br />":@"<br>"];
217 [_response appendContentHTMLString:line];
221 [_response appendContentHTMLString:v];
223 [_response appendContentString:@"</font>"];
225 [_response appendContentString:@"</u>"];
227 [_response appendContentString:@"</i>"];
229 [_response appendContentString:@"</b>"];
231 [_response appendContentString:@"</small>"];