/** GSWForm.m - GSWeb: Class GSWForm Copyright (C) 1999-2004 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Jan 1999 $Revision$ $Date$ This file is part of the GNUstep Web Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. **/ #include "config.h" RCS_ID("$Id$") #include "GSWeb.h" //==================================================================== @implementation GSWForm //-------------------------------------------------------------------- -(id)initWithName:(NSString*)aName associations:(NSDictionary*)associations contentElements:(NSArray*)elements { NSMutableDictionary* tmpAssociations=[NSMutableDictionary dictionaryWithDictionary:associations]; LOGObjectFnStartC("GSWForm"); NSDebugMLLog(@"gswdync",@"aName=%@ associations:%@ elements=%@",aName,associations,elements); if (![tmpAssociations objectForKey:@"method"]) { if ([tmpAssociations objectForKey:@"get"]) [tmpAssociations setObject:[GSWAssociation associationWithValue:@"get"] forKey:@"method"]; else [tmpAssociations setObject:[GSWAssociation associationWithValue:@"post"] forKey:@"method"]; }; [tmpAssociations removeObjectForKey:action__Key]; [tmpAssociations removeObjectForKey:href__Key]; [tmpAssociations removeObjectForKey:multipleSubmit__Key]; [tmpAssociations removeObjectForKey:actionClass__Key]; if (_directActionName) [tmpAssociations removeObjectForKey:_directActionName]; if (!WOStrictFlag) { [tmpAssociations removeObjectForKey:disabled__Key]; [tmpAssociations removeObjectForKey:enabled__Key]; }; [tmpAssociations removeObjectForKey:queryDictionary__Key]; //call isValueSettable sur value (return YES) _action = [[associations objectForKey:action__Key withDefaultObject:[_action autorelease]] retain]; NSDebugMLLog(@"gswdync",@"GSWForm: action=%@",_action); _href = [[associations objectForKey:href__Key withDefaultObject:[_href autorelease]] retain]; NSDebugMLLog(@"gswdync",@"GSWForm: href=%@",_href); _multipleSubmit = [[associations objectForKey:multipleSubmit__Key withDefaultObject:[_multipleSubmit autorelease]] retain]; NSDebugMLLog(@"gswdync",@"GSWForm: multipleSubmit=%@",_multipleSubmit); _actionClass = [[associations objectForKey:actionClass__Key withDefaultObject:[_actionClass autorelease]] retain]; NSDebugMLLog(@"gswdync",@"GSWForm: actionClass=%@",_actionClass); _directActionName = [[associations objectForKey:directActionName__Key withDefaultObject:[_directActionName autorelease]] retain]; NSDebugMLLog(@"gswdync",@"GSWForm: directActionName=%@",_directActionName); if (!WOStrictFlag) { _disabled = [[associations objectForKey:disabled__Key withDefaultObject:[_disabled autorelease]] retain]; NSDebugMLLog(@"gswdync",@"GSWForm disabled=%@",_disabled); _enabled = [[associations objectForKey:enabled__Key withDefaultObject:[_enabled autorelease]] retain]; NSDebugMLLog(@"gswdync",@"GSWForm enabled=%@",_enabled); if (_disabled && _enabled) { ExceptionRaise(@"GSWForm",@"You can't specify 'disabled' and 'enabled' together. componentAssociations:%@", associations); }; _fragmentIdentifier = [[associations objectForKey:fragmentIdentifier__Key withDefaultObject:[_fragmentIdentifier autorelease]] retain]; NSDebugMLLog(@"gswdync",@"fragmentIdentifier=%@",_fragmentIdentifier); [tmpAssociations removeObjectForKey:fragmentIdentifier__Key]; }; _queryDictionary = [[associations objectForKey:queryDictionary__Key withDefaultObject:[_queryDictionary autorelease]] retain]; NSDebugMLLog(@"gswdync",@"GSWForm: queryDictionary=%@",_queryDictionary); if ([tmpAssociations count]>0) { ASSIGN(_otherQueryAssociations,([tmpAssociations extractObjectsForKeysWithPrefix:@"?" removePrefix:YES])); if ([_otherQueryAssociations count]==0) DESTROY(_otherQueryAssociations); if (!WOStrictFlag) { ASSIGN(_otherPathQueryAssociations,([tmpAssociations extractObjectsForKeysWithPrefix:@"!" removePrefix:YES])); if ([_otherPathQueryAssociations count]==0) DESTROY(_otherPathQueryAssociations); }; }; NSDebugMLLog(@"gswdync",@"_otherQueryAssociations=%@",_otherQueryAssociations); NSDebugMLLog(@"gswdync",@"_otherPathQueryAssociations=%@",_otherPathQueryAssociations); if ((self=[super initWithName:aName attributeAssociations:tmpAssociations contentElements:elements])) { }; return self; }; //-------------------------------------------------------------------- -(void)dealloc { DESTROY(_action); DESTROY(_href); DESTROY(_multipleSubmit); DESTROY(_actionClass); DESTROY(_directActionName); DESTROY(_queryDictionary); DESTROY(_disabled); DESTROY(_enabled); DESTROY(_fragmentIdentifier); DESTROY(_otherQueryAssociations); DESTROY(_otherPathQueryAssociations); [super dealloc]; }; //-------------------------------------------------------------------- -(id)description { return [NSString stringWithFormat:@"<%s %p>", object_get_class_name(self), (void*)self]; }; //-------------------------------------------------------------------- -(id)elementName { //OK return @"form"; }; @end //==================================================================== @implementation GSWForm (GSWFormA) //GSWeb Additions { //-------------------------------------------------------------------- -(BOOL)disabledInContext:(GSWContext*)context { //OK if (_enabled) return ![self evaluateCondition:_enabled inContext:context]; else return [self evaluateCondition:_disabled inContext:context]; }; // } //-------------------------------------------------------------------- -(BOOL)compactHTMLTags { LOGObjectFnNotImplemented(); //TODOFN return NO; }; //-------------------------------------------------------------------- -(void)_appendHiddenFieldsToResponse:(GSWResponse*)response inContext:(GSWContext*)context { NSDictionary* hiddenFields = nil; LOGObjectFnStart(); hiddenFields = [self computeQueryDictionaryInContext:context]; if([hiddenFields count]>0) { NSEnumerator* enumerator=[hiddenFields keyEnumerator]; id key=nil; while((key=[enumerator nextObject])) { id value=[hiddenFields objectForKey:key]; [response _appendContentAsciiString:@"