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 @implementation WOElement(QueryString)
157 - (NSString *)queryStringForQueryDictionary:(NSDictionary *)_queryDict
158 andQueryParameters:(NSDictionary *)_paras
159 inContext:(WOContext *)_ctx
161 NSMutableString *str;
166 WOComponent *sComponent;
169 if ((_queryDict == nil) && (_paras == nil))
172 str = [NSMutableString stringWithCapacity:128];
173 sComponent = [_ctx component];
176 paraKeys = [_paras allKeys];
178 /* ?style parameters */
180 keys = [_paras keyEnumerator];
181 while ((key = [keys nextObject])) {
182 value = [[_paras objectForKey:key] stringValueInComponent:sComponent];
183 value = value ? [value stringByEscapingURL] : @"";
184 key = key ? [key stringByEscapingURL] : @"";
186 if (isFirst) isFirst = NO;
187 else [str appendString:@"&"];
189 [str appendString:key];
190 [str appendString:@"="];
191 [str appendString:value];
194 keys = [_queryDict keyEnumerator];
195 while ((key = [keys nextObject])) {
196 if(![paraKeys containsObject:key]) {
197 value = [[_queryDict objectForKey:key] stringValue];
198 value = value ? [value stringByEscapingURL] : @"";
199 key = key ? [key stringByEscapingURL] : @"";
201 if (isFirst) isFirst = NO;
202 else [str appendString:@"&"];
204 [str appendString:key];
205 [str appendString:@"="];
206 [str appendString:value];
210 return [str length] > 0 ? str : nil;
213 @end /* WOElement(QueryString) */
215 NGObjWeb_DECLARE id OWGetProperty(NSDictionary *_set, NSString *_name) {
216 id propValue = [_set objectForKey:_name];
219 propValue = RETAIN(propValue);
220 [(id)_set removeObjectForKey:_name];