mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-23 11:41:20 +00:00
* GSWeb.framework/GSWSwitchComponent.m: o logs o corected bug: use GSWComponentName__Key[] * GSWeb.framework/GSWSession.m: o logs * GSWExtensions.framework/GSWExtensions.m: o added better formatting * GSWExtensions.framework/GSWExtensions.gswc/GSWExtensions.HTML: o added better formatting * GSWExtensions.framework/French.lproj/GSWExtensions.gswc/GSWExtensions.HTML: o added better formatting * GSWExtensionsGSW.framework/GSWLogin.m: o added -login exception cataching to add exception verbosity. * GSWeb.framework/GSWDynamicElement.m/.h: o logs o added ivar _definitionName and associated methods * GSWeb.framework/GSWElement.m/.h: o added ivar -definitionName * GSWeb.framework/GSWTemplateParserANTLR.m: o set dynamic element definition name * GSWeb.framework/GSWTemplateParserXML.m: o set dynamic element definition name * GSWeb.framework/GSWConditional.m: o logs * GSWeb.framework/GSWComponent.m: o logs o remove GDL2 code in -valueForBinding: and setValue:forBinding: I don't see a reason for this code and it may make a loop * GSWeb.framework/GSWAssociation.m: o logs o Fix in validateValue:forKeyPath: test & call * GSWeb.framework/GSWDisplayGroup.m: o logs * GSWeb.framework/GSWBundle.m: o logs * GSWeb.framework/GSWImageButton.m: o logs (element definition name) * GSWeb.framework/GSWForm.m: o logs (element definition name) o stop invokeActionForRequest:inContext: when the current Id is after senderID * GSWeb.framework: GSWElementIDString.m o added -compare:options:range: * GSWeb.framework: GSWHTMLDynamicElement.m o stop invokeActionForRequest:inContext: when the current Id is after senderID * GSWeb.framework: GSWHTMLStaticElement.m o stop invokeActionForRequest:inContext: when the current Id is after senderID * GSWExtensions.framework/WebServerResources: o converted .gif to .png * GSWeb.framework/GSWUtils.m: o removed members in NSUserDefaults description git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@12219 72102866-910b-0410-8b05-ffd578937521
459 lines
16 KiB
Objective-C
459 lines
16 KiB
Objective-C
/* GSWForm.m - GSWeb: Class GSWForm
|
|
Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
|
|
Date: Jan 1999
|
|
|
|
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.
|
|
*/
|
|
|
|
static char rcsId[] = "$Id$";
|
|
|
|
#include <GSWeb/GSWeb.h>
|
|
|
|
//====================================================================
|
|
@implementation GSWForm
|
|
|
|
//--------------------------------------------------------------------
|
|
-(id)initWithName:(NSString*)name_
|
|
associations:(NSDictionary*)associations_
|
|
contentElements:(NSArray*)elements_
|
|
{
|
|
NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_];
|
|
LOGObjectFnStartC("GSWForm");
|
|
NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ elements_=%@",name_,associations_,elements_);
|
|
if (![_associations objectForKey:@"method"])
|
|
{
|
|
if ([_associations objectForKey:@"get"])
|
|
[_associations setObject:[GSWAssociation associationWithValue:@"get"]
|
|
forKey:@"method"];
|
|
else
|
|
[_associations setObject:[GSWAssociation associationWithValue:@"post"]
|
|
forKey:@"method"];
|
|
};
|
|
[_associations removeObjectForKey:action__Key];
|
|
[_associations removeObjectForKey:href__Key];
|
|
[_associations removeObjectForKey:multipleSubmit__Key];
|
|
[_associations removeObjectForKey:actionClass__Key];
|
|
if (directActionName)
|
|
[_associations removeObjectForKey:directActionName];
|
|
|
|
if (!WOStrictFlag)
|
|
{
|
|
[_associations removeObjectForKey:disabled__Key];
|
|
[_associations removeObjectForKey:enabled__Key];
|
|
};
|
|
[_associations 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_);
|
|
};
|
|
};
|
|
|
|
queryDictionary = [[associations_ objectForKey:queryDictionary__Key
|
|
withDefaultObject:[queryDictionary autorelease]] retain];
|
|
NSDebugMLLog(@"gswdync",@"GSWForm: queryDictionary=%@",queryDictionary);
|
|
|
|
if ((self=[super initWithName:name_
|
|
attributeAssociations:_associations
|
|
contentElements:elements_]))
|
|
{
|
|
};
|
|
return self;
|
|
};
|
|
|
|
//--------------------------------------------------------------------
|
|
-(void)dealloc
|
|
{
|
|
DESTROY(action);
|
|
DESTROY(href);
|
|
DESTROY(multipleSubmit);
|
|
DESTROY(actionClass);
|
|
DESTROY(directActionName);
|
|
DESTROY(queryDictionary);
|
|
DESTROY(disabled);
|
|
DESTROY(enabled);
|
|
DESTROY(otherQueryAssociations);
|
|
[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_
|
|
{
|
|
//OK
|
|
NSDictionary* _hiddenFields=nil;
|
|
GSWRequest* _request=nil;
|
|
NSString* _gswsid=nil;
|
|
|
|
_hiddenFields=[self computeQueryDictionaryInContext:context_];
|
|
if (_hiddenFields)
|
|
{
|
|
//TODO
|
|
};
|
|
_request=[context_ request];
|
|
_gswsid=[_request formValueForKey:GSWKey_SessionID[GSWebNamingConv]];
|
|
if (_gswsid)
|
|
{
|
|
//TODO
|
|
};
|
|
LOGObjectFnNotImplemented(); //TODOFN
|
|
};
|
|
|
|
//--------------------------------------------------------------------
|
|
-(NSDictionary*)computeQueryDictionaryInContext:(GSWContext*)context_
|
|
{
|
|
//OK
|
|
GSWComponent* _component=[context_ component];
|
|
GSWSession* _session=[context_ existingSession];
|
|
NSString* _sessionID=[_session sessionID];
|
|
LOGObjectFnNotImplemented(); //TODOFN
|
|
return [[NSDictionary new] autorelease];
|
|
};
|
|
|
|
//--------------------------------------------------------------------
|
|
-(void)appendToResponse:(GSWResponse*)response_
|
|
inContext:(GSWContext*)context_
|
|
{
|
|
//OK
|
|
#ifndef NDEBBUG
|
|
int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb];
|
|
#endif
|
|
LOGObjectFnStartC("GSWForm");
|
|
NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]);
|
|
|
|
GSWSaveAppendToResponseElementID(context_);//Debug Only
|
|
|
|
if (!WOStrictFlag)
|
|
{
|
|
BOOL _disabledInContext=NO;
|
|
_disabledInContext=[self disabledInContext:context_];
|
|
[context_ setInForm:!_disabledInContext];
|
|
}
|
|
else
|
|
[context_ setInForm:YES];
|
|
|
|
[self appendToResponse:response_
|
|
inContext:context_
|
|
elementsFromIndex:0
|
|
toIndex:[elementsMap length]-2];
|
|
[self _appendHiddenFieldsToResponse:response_
|
|
inContext:context_];
|
|
[self appendToResponse:response_
|
|
inContext:context_
|
|
elementsFromIndex:[elementsMap length]-1
|
|
toIndex:[elementsMap length]-1];
|
|
[context_ setInForm:NO];
|
|
NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]);
|
|
#ifndef NDEBBUG
|
|
NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWForm appendToResponse: bad elementID");
|
|
#endif
|
|
LOGObjectFnStopC("GSWForm");
|
|
};
|
|
|
|
//--------------------------------------------------------------------
|
|
-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_
|
|
inContext:(GSWContext*)context_
|
|
{
|
|
//OK
|
|
GSWElement* _element=nil;
|
|
NSString* _senderID=nil;
|
|
NSString* _elementID=nil;
|
|
BOOL _isFormSubmited=NO;
|
|
#ifndef NDEBBUG
|
|
int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb];
|
|
#endif
|
|
BOOL _multipleSubmit=NO;
|
|
int i=0;
|
|
LOGObjectFnStartC("GSWForm");
|
|
_senderID=[context_ senderID];
|
|
_elementID=[context_ elementID];
|
|
NSDebugMLLog(@"gswdync",@"ET=%@ definition name=%@ id=%@ senderId=%@",
|
|
[self class],[self definitionName],_elementID,_senderID);
|
|
NS_DURING
|
|
{
|
|
GSWAssertCorrectElementID(context_);// Debug Only
|
|
if ([self prefixMatchSenderIDInContext:context_]) //Avoid trying to find action if we are not the good component
|
|
{
|
|
BOOL searchIsOver=NO;
|
|
_isFormSubmited=[_elementID isEqualToString:_senderID];
|
|
NSDebugMLLog(@"gswdync",@"ET=%@ id=%@ senderId=%@ _isFormSubmited=%s",
|
|
[self class],
|
|
_elementID,
|
|
_senderID,
|
|
(_isFormSubmited ? "YES" : "NO"));
|
|
if (!WOStrictFlag && _isFormSubmited && [self disabledInContext:context_])
|
|
_isFormSubmited=NO;
|
|
|
|
if (_isFormSubmited)
|
|
{
|
|
[context_ setInForm:YES];
|
|
[context_ _setFormSubmitted:YES];
|
|
_multipleSubmit=[self evaluateCondition:multipleSubmit
|
|
inContext:context_];
|
|
NSDebugMLLog(@"gswdync",@"ET=%@ id=%@ senderId=%@ _multipleSubmit=%s",
|
|
[self class],
|
|
_elementID,
|
|
_senderID,
|
|
(_multipleSubmit ? "YES" : "NO"));
|
|
[context_ _setIsMultipleSubmitForm:_multipleSubmit];
|
|
};
|
|
[context_ appendZeroElementIDComponent];
|
|
for(i=0;!_element && !searchIsOver && i<[dynamicChildren count];i++)
|
|
{
|
|
NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",
|
|
[[dynamicChildren objectAtIndex:i] class],
|
|
[context_ elementID]);
|
|
_element=[[dynamicChildren objectAtIndex:i] invokeActionForRequest:request_
|
|
inContext:context_];
|
|
// if (![context_ _wasFormSubmitted] && [[context_ elementID] compare:_senderID]==NSOrderedDescending)
|
|
if (![context_ _wasFormSubmitted] && [[context_ elementID] isSearchOverForSenderID:_senderID])
|
|
{
|
|
NSDebugMLLog(@"gswdync",@"id=%@ senderid=%@ => search is over",
|
|
[context_ elementID],
|
|
_senderID);
|
|
searchIsOver=YES;
|
|
};
|
|
[context_ incrementLastElementIDComponent];
|
|
};
|
|
[context_ deleteLastElementIDComponent];
|
|
if (_isFormSubmited)
|
|
{
|
|
if ([context_ _wasActionInvoked])
|
|
[context_ _setIsMultipleSubmitForm:NO];
|
|
else
|
|
{
|
|
NSDebugMLLog0(@"gswdync",@"formSubmitted but no action was invoked!");
|
|
};
|
|
[context_ setInForm:NO];
|
|
[context_ _setFormSubmitted:NO];
|
|
};
|
|
_elementID=[context_ elementID];
|
|
NSDebugMLLog(@"gswdync",@"END ET=%@ def name=%@ id=%@",
|
|
[self class],
|
|
[self definitionName],
|
|
_elementID);
|
|
#ifndef NDEBBUG
|
|
NSAssert(elementsNb==[(GSWElementIDString*)_elementID elementsNb],
|
|
@"GSWForm invokeActionForRequest: bad elementID");
|
|
#endif
|
|
};
|
|
}
|
|
NS_HANDLER
|
|
{
|
|
LOGException0(@"exception in GSWForm invokeActionForRequest:inContext");
|
|
LOGException(@"exception=%@",localException);
|
|
localException=ExceptionByAddingUserInfoObjectFrameInfo(localException,
|
|
@"In GSWForm invokeActionForRequest:inContext");
|
|
LOGException(@"exception=%@",localException);
|
|
[localException raise];
|
|
}
|
|
NS_ENDHANDLER;
|
|
_senderID=[context_ senderID];
|
|
_elementID=[context_ elementID];
|
|
//if (![context_ _wasActionInvoked] && [_elementID compare:_senderID]!=NSOrderedAscending)
|
|
if (![context_ _wasActionInvoked] && [_elementID isSearchOverForSenderID:_senderID])
|
|
{
|
|
LOGError(@"Action not invoked at the end of %@ (def name=%@) (id=%@) senderId=%@",
|
|
[self class],
|
|
[self definitionName],
|
|
_elementID,
|
|
_senderID);
|
|
};
|
|
LOGObjectFnStopC("GSWForm");
|
|
return _element;
|
|
};
|
|
|
|
//--------------------------------------------------------------------
|
|
-(void)takeValuesFromRequest:(GSWRequest*)request_
|
|
inContext:(GSWContext*)context_
|
|
{
|
|
//OK
|
|
NSString* _senderID=nil;
|
|
NSString* _elementID=nil;
|
|
BOOL _isFormSubmited=NO;
|
|
int i=0;
|
|
#ifndef NDEBBUG
|
|
int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb];
|
|
#endif
|
|
LOGObjectFnStartC("GSWForm");
|
|
NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]);
|
|
GSWAssertCorrectElementID(context_);// Debug Only
|
|
_senderID=[context_ senderID];
|
|
_elementID=[context_ elementID];
|
|
NSDebugMLLog(@"gswdync",@"_senderID=%@",_senderID);
|
|
NSDebugMLLog(@"gswdync",@"_elementID=%@",_elementID);
|
|
if ([self prefixMatchSenderIDInContext:context_]) //Avoid taking values if we are not the good form
|
|
{
|
|
_isFormSubmited=[_elementID isEqualToString:_senderID];
|
|
NSDebugMLLog(@"gswdync",@"_isFormSubmited=%d",(int)_isFormSubmited);
|
|
if (!WOStrictFlag && _isFormSubmited && [self disabledInContext:context_])
|
|
_isFormSubmited=NO;
|
|
|
|
NSDebugMLLog(@"gswdync",@"Starting GSWForm TV ET=%@ id=%@",[self class],[context_ elementID]);
|
|
if (_isFormSubmited)
|
|
{
|
|
[context_ setInForm:YES];
|
|
[context_ _setFormSubmitted:YES];
|
|
};
|
|
[context_ appendZeroElementIDComponent];
|
|
NSDebugMLLog(@"gswdync",@"\n\ndynamicChildren=%@",dynamicChildren);
|
|
NSDebugMLLog(@"gswdync",@"[dynamicChildren count]=%d",[dynamicChildren count]);
|
|
for(i=0;i<[dynamicChildren count];i++)
|
|
{
|
|
NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[[dynamicChildren objectAtIndex:i] class],[context_ elementID]);
|
|
NSDebugMLLog(@"gswdync",@"\n[dynamicChildren objectAtIndex:i]=%@",[dynamicChildren objectAtIndex:i]);
|
|
[[dynamicChildren objectAtIndex:i] takeValuesFromRequest:request_
|
|
inContext:context_];
|
|
[context_ incrementLastElementIDComponent];
|
|
};
|
|
[context_ deleteLastElementIDComponent];
|
|
if (_isFormSubmited)
|
|
{
|
|
[context_ setInForm:NO];
|
|
[context_ _setFormSubmitted:NO];
|
|
};
|
|
};
|
|
NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]);
|
|
#ifndef NDEBBUG
|
|
NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWForm takeValuesFromRequest: bad elementID");
|
|
#endif
|
|
LOGObjectFnStopC("GSWForm");
|
|
};
|
|
|
|
@end
|
|
|
|
//====================================================================
|
|
@implementation GSWForm (GSWFormB)
|
|
|
|
//--------------------------------------------------------------------
|
|
-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_
|
|
inContext:(GSWContext*)context_
|
|
{
|
|
//OK//TODOV
|
|
BOOL _disabledInContext=NO;
|
|
LOGObjectFnStartC("GSWForm");
|
|
if (!WOStrictFlag)
|
|
{
|
|
_disabledInContext=[self disabledInContext:context_];
|
|
NSDebugMLLog(@"gswdync",@"_disabledInContext=%s",(_disabledInContext ? "YES" : "NO"));
|
|
};
|
|
if (!_disabledInContext)
|
|
{
|
|
GSWComponent* _component=[context_ component];
|
|
id _actionValue=nil;
|
|
if (href)
|
|
_actionValue=[href valueInComponent:_component];
|
|
else
|
|
_actionValue=[context_ componentActionURL];
|
|
[response_ appendContentCharacter:' '];
|
|
[response_ _appendContentAsciiString:@"action"];
|
|
[response_ appendContentCharacter:'='];
|
|
[response_ appendContentCharacter:'"'];
|
|
[response_ appendContentString:_actionValue];
|
|
[response_ appendContentCharacter:'"'];
|
|
};
|
|
LOGObjectFnStopC("GSWForm");
|
|
};
|
|
|
|
//--------------------------------------------------------------------
|
|
-(void)_appendCGIActionToResponse:(GSWResponse*)response_
|
|
inContext:(GSWContext*)context_
|
|
{
|
|
LOGObjectFnNotImplemented(); //TODOFN
|
|
};
|
|
|
|
@end
|
|
|
|
//====================================================================
|
|
@implementation GSWForm (GSWFormC)
|
|
|
|
//--------------------------------------------------------------------
|
|
+(BOOL)hasGSWebObjectsAssociations
|
|
{
|
|
return YES;
|
|
};
|
|
|
|
@end
|
|
|