mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-24 12:11:18 +00:00
o added +handlerWithDefaultActionClassName:defaultActionName:displayExceptionPages:
o adedd _displayExceptionPages o added GSWActionRequestHandler as superclass of GSWDirectActionRequestHandler o moved some code in GSWActionRequestHandler git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@18159 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ae60d0e96c
commit
a365f52a4a
2 changed files with 103 additions and 158 deletions
|
@ -33,23 +33,27 @@
|
||||||
#define _GSWDirectActionRequestHandler_h__
|
#define _GSWDirectActionRequestHandler_h__
|
||||||
|
|
||||||
|
|
||||||
@interface GSWDirectActionRequestHandler: GSWRequestHandler
|
@interface GSWDirectActionRequestHandler: GSWActionRequestHandler
|
||||||
{
|
{
|
||||||
|
BOOL _displayExceptionPages;
|
||||||
|
BOOL _allowsContentInputStream;
|
||||||
};
|
};
|
||||||
|
|
||||||
-(GSWResponse*)handleRequest:(GSWRequest*)aRequest;
|
-(GSWResponse*)generateNullResponse;
|
||||||
-(GSWResponse*)_nilResponse;
|
|
||||||
-(void)_initializeRequestSessionIDInContext:(GSWContext*)aContext;
|
|
||||||
-(id)submitButtonsActionPathFromRequest:(GSWRequest*)aRequest;
|
-(id)submitButtonsActionPathFromRequest:(GSWRequest*)aRequest;
|
||||||
+(NSArray*)additionalRequestPathArrayFromRequest:(GSWRequest*)aRequest;
|
+(NSArray*)additionalRequestPathArrayFromRequest:(GSWRequest*)aRequest;
|
||||||
|
-(void)setAllowsContentInputStream:(BOOL)yn;
|
||||||
|
-(BOOL)allowsContentInputStream;
|
||||||
|
-(void)setDisplayExceptionPages:(BOOL)yn;
|
||||||
|
-(BOOL)displayExceptionPages;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
//====================================================================
|
//====================================================================
|
||||||
@interface GSWDirectActionRequestHandler (GSWRequestHandlerClassA)
|
@interface GSWDirectActionRequestHandler (GSWRequestHandlerClassA)
|
||||||
+(id)handler;
|
+(id)handler;
|
||||||
|
+(GSWDirectActionRequestHandler*)handlerWithDefaultActionClassName:(NSString*)defaultActionClassName
|
||||||
|
defaultActionName:(NSString*)defaultActionName
|
||||||
|
displayExceptionPages:(BOOL)displayExceptionPages;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //GSWDirectActionRequestHandler
|
#endif //GSWDirectActionRequestHandler
|
||||||
|
|
|
@ -37,180 +37,86 @@ RCS_ID("$Id$")
|
||||||
//====================================================================
|
//====================================================================
|
||||||
@implementation GSWDirectActionRequestHandler
|
@implementation GSWDirectActionRequestHandler
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
-(NSString*)defaultActionClassName
|
||||||
-(GSWResponse*)handleRequest:(GSWRequest*)aRequest
|
|
||||||
{
|
{
|
||||||
//OK
|
return @"DirectAction";
|
||||||
GSWResponse* response=nil;
|
|
||||||
GSWStatisticsStore* statisticsStore=nil;
|
|
||||||
GSWApplication* application=nil;
|
|
||||||
LOGObjectFnStart();
|
|
||||||
application=[GSWApplication application];
|
|
||||||
if (0/*[application isRefusingNewSessions]*/)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
-(void)registerWillHandleActionRequest
|
||||||
{
|
{
|
||||||
|
[[[GSWApplication application]statisticsStore]
|
||||||
|
applicationWillHandleDirectActionRequest];
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
-(void)registerDidHandleActionRequestWithActionNamed:(NSString*)actionName
|
||||||
|
{
|
||||||
|
[[[GSWApplication application]statisticsStore]
|
||||||
|
applicationDidHandleDirectActionRequestWithActionNamed:actionName];
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
-(NSArray*)getRequestHandlerPathForRequest:(GSWRequest*)aRequest
|
||||||
|
{
|
||||||
|
NSArray* requestHandlerPath=nil;
|
||||||
id submitButtonsActionPathFromRequest=nil;
|
id submitButtonsActionPathFromRequest=nil;
|
||||||
NSArray* requestHandlerPathArray=nil;
|
submitButtonsActionPathFromRequest=[self submitButtonsActionPathFromRequest:aRequest];
|
||||||
NSString* actionName=nil;
|
|
||||||
NSString* className=nil;
|
|
||||||
GSWContext* context=nil;
|
|
||||||
[application lockRequestHandling];
|
|
||||||
NS_DURING
|
|
||||||
{
|
|
||||||
NS_DURING
|
|
||||||
{
|
|
||||||
statisticsStore=[[GSWApplication application]statisticsStore];
|
|
||||||
[statisticsStore _applicationWillHandleDirectActionRequest];
|
|
||||||
submitButtonsActionPathFromRequest=[self submitButtonsActionPathFromRequest:aRequest]; //So what ?
|
|
||||||
NSDebugMLLog(@"requests",@"submitButtonsActionPathFromRequest=%@",
|
NSDebugMLLog(@"requests",@"submitButtonsActionPathFromRequest=%@",
|
||||||
submitButtonsActionPathFromRequest);
|
submitButtonsActionPathFromRequest);
|
||||||
requestHandlerPathArray=[aRequest requestHandlerPathArray];
|
if (submitButtonsActionPathFromRequest)
|
||||||
NSDebugMLLog(@"requests",@"requestHandlerPathArray=%@",
|
requestHandlerPath=[submitButtonsActionPathFromRequest componentsSeparatedByString:@"/"];
|
||||||
requestHandlerPathArray);
|
else
|
||||||
switch([requestHandlerPathArray count])
|
requestHandlerPath=[aRequest requestHandlerPathArray];
|
||||||
{
|
return requestHandlerPath;
|
||||||
case 0:
|
}
|
||||||
actionName=@"default";
|
|
||||||
className=@"DirectAction";
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
NSString* tmpActionName=[NSString stringWithFormat:@"%@Action",
|
|
||||||
[requestHandlerPathArray objectAtIndex:0]];
|
|
||||||
SEL tmpActionSel=NSSelectorFromString(tmpActionName);
|
|
||||||
Class aClass = NSClassFromString(@"DirectAction");
|
|
||||||
NSDebugMLLog(@"requests",@"tmpActionName=%@",
|
|
||||||
tmpActionName);
|
|
||||||
if (tmpActionSel && aClass)
|
|
||||||
{
|
|
||||||
if ([aClass instancesRespondToSelector:tmpActionSel])
|
|
||||||
{
|
|
||||||
actionName=[requestHandlerPathArray objectAtIndex:0];
|
|
||||||
className=@"DirectAction";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
if (!actionName)
|
|
||||||
{
|
|
||||||
className=[requestHandlerPathArray objectAtIndex:0];
|
|
||||||
actionName=@"default";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
default:
|
|
||||||
className=[requestHandlerPathArray objectAtIndex:0];
|
|
||||||
actionName=[NSString stringWithFormat:@"%@",
|
|
||||||
[requestHandlerPathArray objectAtIndex:1]];
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
NSDebugMLLog(@"requests",@"className=%@",className);
|
|
||||||
NSDebugMLLog(@"requests",@"actionName=%@",actionName);
|
|
||||||
if ([application isCachingEnabled])
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
};
|
|
||||||
{
|
|
||||||
GSWResourceManager* resourceManager=nil;
|
|
||||||
GSWDeployedBundle* appBundle=nil;
|
|
||||||
GSWDirectAction* directAction=nil;
|
|
||||||
id<GSWActionResults> actionResult=nil;
|
|
||||||
Class aClass=nil;
|
|
||||||
resourceManager=[application resourceManager];
|
|
||||||
appBundle=[resourceManager _appProjectBundle];
|
|
||||||
[resourceManager _allFrameworkProjectBundles];//So what ?
|
|
||||||
[application awake];
|
|
||||||
aClass=NSClassFromString(className);
|
|
||||||
NSAssert1(aClass,@"No direct action class named %@",
|
|
||||||
className);
|
|
||||||
directAction=[[aClass alloc]initWithRequest:aRequest];
|
|
||||||
NSAssert1(directAction,@"Direct action of class named %@ can't be created",
|
|
||||||
className);
|
|
||||||
context=[directAction _context];
|
|
||||||
actionResult=[directAction performActionNamed:actionName];
|
|
||||||
response=[actionResult generateResponse];
|
|
||||||
|
|
||||||
//Finir ?
|
//--------------------------------------------------------------------
|
||||||
|
-(NSString*)submitButtonsActionPathFromRequest:(GSWRequest*)aRequest
|
||||||
|
{
|
||||||
|
NSString* path=nil;
|
||||||
|
LOGObjectFnStart();
|
||||||
|
|
||||||
|
if (!_allowsContentInputStream)
|
||||||
|
{
|
||||||
|
NSArray* submitActions=[aRequest formValuesForKey:GSWKey_SubmitAction[GSWebNamingConv]];
|
||||||
|
if (submitActions)
|
||||||
|
{
|
||||||
|
int count=[submitActions count];
|
||||||
|
int i=0;
|
||||||
|
for(i=0;!path && i<count;i++)
|
||||||
|
{
|
||||||
|
NSString* submitAction=[submitActions objectAtIndex:i];
|
||||||
|
if ([aRequest formValuesForKey:submitAction])
|
||||||
|
path = submitAction;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Try image buttons
|
||||||
|
NSString* imageButtonFormValueName=[submitAction stringByAppendingString:@".x"];
|
||||||
|
if ([aRequest formValuesForKey:imageButtonFormValueName])
|
||||||
|
path = submitAction;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
NS_HANDLER
|
|
||||||
{
|
|
||||||
LOGException(@"%@ (%@)",localException,[localException reason]);
|
|
||||||
if (!context)
|
|
||||||
context=[GSWApp _context];
|
|
||||||
response=[application handleException:localException
|
|
||||||
inContext:context];
|
|
||||||
//TODO
|
|
||||||
};
|
};
|
||||||
NS_ENDHANDLER;
|
};
|
||||||
NSDebugMLLog(@"requests",@"response=%@",response);
|
|
||||||
RETAIN(response);
|
|
||||||
if (!context)
|
|
||||||
context=[GSWApp _context];
|
|
||||||
[context _putAwakeComponentsToSleep];
|
|
||||||
[application saveSessionForContext:context];
|
|
||||||
NSDebugMLLog(@"requests",@"response=%@",response);
|
|
||||||
AUTORELEASE(response);
|
|
||||||
|
|
||||||
//Here ???
|
|
||||||
[application sleep];
|
|
||||||
//TODO do not fnalize if already done (in handleException for exemple)
|
|
||||||
[response _finalizeInContext:context];
|
|
||||||
[application _setContext:nil];
|
|
||||||
statisticsStore=[[GSWApplication application] statisticsStore];
|
|
||||||
[statisticsStore _applicationDidHandleDirectActionRequestWithActionNamed:actionName];
|
|
||||||
}
|
|
||||||
NS_HANDLER
|
|
||||||
{
|
|
||||||
LOGException(@"%@ (%@)",localException,[localException reason]);
|
|
||||||
[application unlockRequestHandling];
|
|
||||||
[localException raise];//TODO
|
|
||||||
};
|
|
||||||
NS_ENDHANDLER;
|
|
||||||
[application unlockRequestHandling];
|
|
||||||
};
|
|
||||||
LOGObjectFnNotImplemented(); //TODOFN
|
|
||||||
LOGObjectFnStop();
|
LOGObjectFnStop();
|
||||||
return response;
|
return path;
|
||||||
};
|
};
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
-(GSWResponse*)_nilResponse
|
-(GSWResponse*)generateNullResponse
|
||||||
{
|
{
|
||||||
//OK
|
|
||||||
GSWResponse* response=nil;
|
GSWResponse* response=nil;
|
||||||
LOGObjectFnStart();
|
LOGObjectFnStart();
|
||||||
response=[GSWApp createResponseInContext:nil];
|
response=[GSWApp createResponseInContext:nil];
|
||||||
[response appendContentString:@"<HTML><HEAD><TITLE>DirectAction Error</TITLE></HEAD><BODY>The result of a direct action returned nothing.</BODY></HTML>"];
|
[response appendContentString:@"<HTML><HEAD><TITLE>DirectAction Error</TITLE></HEAD><BODY><CENTER>The result of a direct action returned nothing.</CENTER></BODY></HTML>"];
|
||||||
LOGObjectFnStop();
|
LOGObjectFnStop();
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
|
||||||
-(void)_initializeRequestSessionIDInContext:(GSWContext*)aContext
|
|
||||||
{
|
|
||||||
LOGObjectFnNotImplemented(); //TODOFN
|
|
||||||
};
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
-(id)submitButtonsActionPathFromRequest:(GSWRequest*)aRequest
|
|
||||||
{
|
|
||||||
//OK
|
|
||||||
NSArray* submitActions=nil;
|
|
||||||
LOGObjectFnStart();
|
|
||||||
submitActions=[aRequest formValuesForKey:GSWKey_SubmitAction[GSWebNamingConv]];
|
|
||||||
if (submitActions)
|
|
||||||
{
|
|
||||||
//TODO
|
|
||||||
};
|
|
||||||
|
|
||||||
LOGObjectFnNotImplemented(); //TODOFN
|
|
||||||
LOGObjectFnStop();
|
|
||||||
return nil;
|
|
||||||
};
|
|
||||||
|
|
||||||
//NDFN: return additional path elements
|
//NDFN: return additional path elements
|
||||||
+(NSArray*)additionalRequestPathArrayFromRequest:(GSWRequest*)aRequest
|
+(NSArray*)additionalRequestPathArrayFromRequest:(GSWRequest*)aRequest
|
||||||
{
|
{
|
||||||
|
@ -223,6 +129,27 @@ RCS_ID("$Id$")
|
||||||
LOGObjectFnStart();
|
LOGObjectFnStart();
|
||||||
return additionalRequestPathArray;
|
return additionalRequestPathArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
-(void)setAllowsContentInputStream:(BOOL)yn
|
||||||
|
{
|
||||||
|
_allowsContentInputStream = yn;
|
||||||
|
};
|
||||||
|
|
||||||
|
-(BOOL)allowsContentInputStream
|
||||||
|
{
|
||||||
|
return _allowsContentInputStream;
|
||||||
|
};
|
||||||
|
|
||||||
|
-(void)setDisplayExceptionPages:(BOOL)yn
|
||||||
|
{
|
||||||
|
_displayExceptionPages=yn;
|
||||||
|
};
|
||||||
|
|
||||||
|
-(BOOL)displayExceptionPages
|
||||||
|
{
|
||||||
|
return _displayExceptionPages;
|
||||||
|
};
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
//====================================================================
|
//====================================================================
|
||||||
|
@ -231,7 +158,21 @@ RCS_ID("$Id$")
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
+(id)handler
|
+(id)handler
|
||||||
{
|
{
|
||||||
return [[GSWDirectActionRequestHandler new] autorelease];
|
return [self handlerWithDefaultActionClassName:@"DirectAction"
|
||||||
|
defaultActionName:@"default"
|
||||||
|
shouldAddToStatistics:YES];
|
||||||
|
};
|
||||||
|
|
||||||
|
+(GSWDirectActionRequestHandler*)handlerWithDefaultActionClassName:(NSString*)defaultActionClassName
|
||||||
|
defaultActionName:(NSString*)defaultActionName
|
||||||
|
displayExceptionPages:(BOOL)displayExceptionPages
|
||||||
|
{
|
||||||
|
GSWDirectActionRequestHandler* darh=[[[self alloc]initWithDefaultActionClassName:defaultActionClassName
|
||||||
|
defaultActionName:defaultActionName
|
||||||
|
shouldAddToStatistics:YES]autorelease];
|
||||||
|
[darh setDisplayExceptionPages:displayExceptionPages];
|
||||||
|
return darh;
|
||||||
};
|
};
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue