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/WOElement.h>
23 #include "WOElement+private.h"
24 #include <NGObjWeb/WOComponent.h>
27 @implementation WOElement
33 static id numStrings[100];
36 static BOOL didInitialize = NO;
43 for (cnt = 0; cnt < 100; cnt++) {
46 sprintf(buf, "%i", cnt);
47 numStrings[cnt] = [[NSString alloc] initWithCString:buf];
53 if ((self = [super init])) {
54 #if !NO_METHOD_CACHING
55 self->takeValues = (OWTakeValuesMethod)
56 [self methodForSelector:@selector(takeValuesFromRequest:inContext:)];
57 self->appendResponse = (OWAppendResponseMethod)
58 [self methodForSelector:@selector(appendToResponse:inContext:)];
60 # warning methods are not cached !
68 - (NSString *)stringForInt:(int)_i {
71 if ((_i < 100) && (_i >= 0)) {
72 // MT flaw, should be locked
76 sprintf(buf, "%i", _i);
77 s = [NSString stringWithCString:buf];
78 numStrings[_i] = RETAIN(s);
83 sprintf(buf, "%i", _i);
84 s = [NSString stringWithCString:buf];
89 - (NSString *)elementID {
95 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
98 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
102 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
107 + (BOOL)isDynamicElement {
113 - (NSString *)indentString:(int)_indent {
120 case 10: return @" ";
121 case 12: return @" ";
122 case 14: return @" ";
126 NSMutableString *str = [[NSMutableString alloc] init];
127 for (cnt = 0; cnt < _indent; cnt++)
128 [str appendString:@" "];
129 return AUTORELEASE(str);
134 - (NSString *)elementTreeWithIndent:(int)_indent {
135 NSMutableString *str = [[NSMutableString alloc] init];
137 [str appendString:[self indentString:_indent]];
138 [str appendString:[self description]];
139 [str appendString:@"\n"];
141 return AUTORELEASE(str);
144 - (NSString *)elementTree {
145 return [self elementTreeWithIndent:2];
148 - (NSString *)description {
149 return [NSString stringWithFormat:@"<%@[0x%08X]>",
150 NSStringFromClass([self class]), self];
155 - (NSString *)queryStringForQueryDictionary:(NSDictionary *)_queryDict
156 andQueryParameters:(NSDictionary *)_paras
157 inContext:(WOContext *)_ctx
159 NSMutableString *str;
164 WOComponent *sComponent;
167 if ((_queryDict == nil) && (_paras == nil))
170 str = [NSMutableString stringWithCapacity:128];
171 sComponent = [_ctx component];
174 paraKeys = [_paras allKeys];
176 /* ?style parameters */
178 keys = [_paras keyEnumerator];
179 while ((key = [keys nextObject]) != nil) {
180 value = [[_paras objectForKey:key] stringValueInComponent:sComponent];
181 value = value ? [value stringByEscapingURL] : @"";
182 key = key ? [key stringByEscapingURL] : @"";
184 if (isFirst) isFirst = NO;
185 else [str appendString:@"&"];
187 [str appendString:key];
188 [str appendString:@"="];
189 [str appendString:value];
192 keys = [_queryDict keyEnumerator];
193 while ((key = [keys nextObject]) != nil) {
194 if([paraKeys containsObject:key])
195 /* overridden by a query parameter (?abc=abc) */
198 value = [_queryDict objectForKey:key];
199 if ([value isKindOfClass:[NSArray class]]) {
200 /* if we bind the queryDictionary to request.formValues */
204 values = (NSArray *)value;
205 for (i = 0, count = [values count]; i < count; i++) {
206 value = [values objectAtIndex:i];
207 value = [value stringValue];
208 value = value ? [value stringByEscapingURL] : @"";
209 key = key ? [key stringByEscapingURL] : @"";
211 if (isFirst) isFirst = NO;
212 else [str appendString:@"&"];
214 [str appendString:key];
215 [str appendString:@"="];
216 [str appendString:value];
220 value = [value stringValue];
221 value = value ? [value stringByEscapingURL] : @"";
222 key = key ? [key stringByEscapingURL] : @"";
224 if (isFirst) isFirst = NO;
225 else [str appendString:@"&"];
227 [str appendString:key];
228 [str appendString:@"="];
229 [str appendString:value];
233 return [str length] > 0 ? str : nil;
238 NGObjWeb_DECLARE id OWGetProperty(NSDictionary *_set, NSString *_name) {
239 register id propValue;
241 if ((propValue = [_set objectForKey:_name]) != nil) {
242 propValue = [propValue retain];
243 [(NSMutableDictionary *)_set removeObjectForKey:_name];