2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include <NGObjWeb/WOElement.h>
24 #include "WOElement+private.h"
25 #include <NGObjWeb/WOComponent.h>
28 @implementation WOElement
34 static id numStrings[100];
37 static BOOL didInitialize = NO;
44 for (cnt = 0; cnt < 100; cnt++) {
47 sprintf(buf, "%i", cnt);
48 numStrings[cnt] = [[NSString alloc] initWithCString:buf];
54 if ((self = [super init])) {
55 #if !NO_METHOD_CACHING
56 self->takeValues = (OWTakeValuesMethod)
57 [self methodForSelector:@selector(takeValuesFromRequest:inContext:)];
58 self->appendResponse = (OWAppendResponseMethod)
59 [self methodForSelector:@selector(appendToResponse:inContext:)];
61 # warning methods are not cached !
69 - (NSString *)stringForInt:(int)_i {
72 if ((_i < 100) && (_i >= 0)) {
73 // MT flaw, should be locked
77 sprintf(buf, "%i", _i);
78 s = [NSString stringWithCString:buf];
79 numStrings[_i] = RETAIN(s);
84 sprintf(buf, "%i", _i);
85 s = [NSString stringWithCString:buf];
90 - (NSString *)elementID {
96 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
99 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
103 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
108 + (BOOL)isDynamicElement {
114 - (NSString *)indentString:(int)_indent {
121 case 10: return @" ";
122 case 12: return @" ";
123 case 14: return @" ";
127 NSMutableString *str = [[NSMutableString alloc] init];
128 for (cnt = 0; cnt < _indent; cnt++)
129 [str appendString:@" "];
130 return AUTORELEASE(str);
135 - (NSString *)elementTreeWithIndent:(int)_indent {
136 NSMutableString *str = [[NSMutableString alloc] init];
138 [str appendString:[self indentString:_indent]];
139 [str appendString:[self description]];
140 [str appendString:@"\n"];
142 return AUTORELEASE(str);
145 - (NSString *)elementTree {
146 return [self elementTreeWithIndent:2];
149 - (NSString *)description {
150 return [NSString stringWithFormat:@"<%@[0x%08X]>",
151 NSStringFromClass([self class]), self];
156 @implementation WOElement(QueryString)
158 - (NSString *)queryStringForQueryDictionary:(NSDictionary *)_queryDict
159 andQueryParameters:(NSDictionary *)_paras
160 inContext:(WOContext *)_ctx
162 NSMutableString *str;
167 WOComponent *sComponent;
169 if ((_queryDict == nil) && (_paras == nil))
172 str = [NSMutableString stringWithCapacity:128];
173 sComponent = [_ctx component];
175 keys = [_queryDict keyEnumerator];
177 while ((key = [keys nextObject])) {
178 value = [[_queryDict objectForKey:key] stringValue];
179 value = value ? [value stringByEscapingURL] : @"";
180 key = key ? [key stringByEscapingURL] : @"";
182 if (isFirst) isFirst = NO;
183 else [str appendString:@"&"];
185 [str appendString:key];
186 [str appendString:@"="];
187 [str appendString:value];
190 /* ?style parameters */
192 keys = [_paras keyEnumerator];
193 while ((key = [keys nextObject])) {
194 value = [[_paras objectForKey:key] stringValueInComponent:sComponent];
195 value = value ? [value stringByEscapingURL] : @"";
196 key = key ? [key stringByEscapingURL] : @"";
198 if (isFirst) isFirst = NO;
199 else [str appendString:@"&"];
201 [str appendString:key];
202 [str appendString:@"="];
203 [str appendString:value];
206 return [str length] > 0 ? str : nil;
209 @end /* WOElement(QueryString) */
211 NGObjWeb_DECLARE id OWGetProperty(NSDictionary *_set, NSString *_name) {
212 id propValue = [_set objectForKey:_name];
215 propValue = RETAIN(propValue);
216 [(id)_set removeObjectForKey:_name];