2002-05-16 18:01:40 +00:00
/ * * GSWHTMLDynamicElement . m - < title > GSWeb : Class GSWHTMLDynamicElement < / title >
2005-04-05 15:54:24 +00:00
Copyright ( C ) 1999 -2005 Free Software Foundation , Inc .
2000-01-22 12:49:49 +00:00
2002-05-16 18:01:40 +00:00
Written by : Manuel Guesdon < mguesdon @ orange - concept . com >
2000-01-22 12:49:49 +00:00
Date : Feb 1999
2002-05-16 18:01:40 +00:00
$ Revision $
$ Date $
2003-01-19 15:33:07 +00:00
$ Id $
2000-01-22 12:49:49 +00:00
2002-05-16 18:01:40 +00:00
< abstract > < / abstract >
This file is part of the GNUstep Web Library .
< license >
2000-01-22 12:49:49 +00:00
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 .
2002-05-16 18:01:40 +00:00
< / license >
* * /
2000-01-22 12:49:49 +00:00
2003-03-21 14:32:57 +00:00
# include "config.h"
RCS_ID ( "$Id$" )
2000-01-22 12:49:49 +00:00
2003-01-22 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWeb.framework/Makefile.postamble:
o use $(LN_S) -f in install-WO-headers
o added $(MKDIRS) $(GNUSTEP_HEADERS)/$(GSWExtensions_wo_HEADER_FILES_INSTALL_DIR);
* GSWExtensionsGSW.framework/Makefile.postamble: use $(LN_S) -f in install-WO-headers
2003-01-20 David Ayers <d.ayers@inode.at>
* Makefile.postamble
o added support for make gswnames=(gsw,wo,all) (corrected
typo)
o reinserted support for $(INSTALL_ROOT_DIR)
* config.h.in
o added HAVE_GDL2
* configure
o added support for --with-gswnames=(gsw,wo,all)
o set LIBWRAP during configure
o added config.mak.in as configurable file
* configure.ac
o (see configure)
* config.mak: removed (replaced by config.mak.in)
* config.mak.in: new file
o added support for make gswnames=(gsw,wo,all)
* gsweb.make.in
o add GSANTLR as auxiliary lib
o add gsweb libs to AUXILIARY_GSW_LIBS
o include correct extensions for GSW/WO-libs
* gsweb_wo.make: new file
* GSWeb/GSWConfig.h
o changed support for GSWEB_WONAMES
o conditionally import file GSWWOCompatiblity
here instead of in GSWeb.h
* GSWeb/GNUMakefile
o added support for make gswnames=(gsw,wo,all)
o ensure each lib gets built with its own object files
o removed deactivated framework extension determination code
o removed reference to unused files:
GSWeb.m, GSWWOCompatibility.m
o added references to new files:
GSWExtenstions.h, GSWExtWOCompatibility.h
o added support to create WO header files
* GSWeb/Makefile.postamble
o changed support to install WO header files according to
make gswnames=(gsw,wo,all)
o remove Makefile.preamble during distclean
* GSWeb/Makefile.preamble.in
o fixed typo
* GSWeb/GSWeb.h
o moved GSW/WO-Name-mapping to GSWWOCompatibility.h
o replaced inclusions of
<GSWeb/file.h> with "file.h"
* GSWeb/GSWeb.m: removed
* GSWeb/GSWWOCompatibility.h
o changed GSWEB_WONAMES handling
o removed hybrid namespace WO subclasses
o moved & reorganized GSW/WO-Name-mapping from GSWeb.h
o inlucluded missing GSW/WO-Name-mappings
* GSWeb/GSWWOCompatibility.m: removed
* GSWeb/*.m
o replaced inclusions of
<GSWeb/file.h> with "file.h"
* GSWeb/GSWApplication.m
o remove special GSW/WO handling of WOApp
* GSWeb/WebObject/WO*: removed
* GSWeb/WebObject/WebObjects
o replaced inclusions of
<GSWeb/file.h> with "file.h"
* GSWExtensions/GNUMakefile
o added support for make gswnames=(gsw,wo,all)
o ensure each lib gets built with its own object files
o removed deactivated framework extension determination code
o added references to new files:
GSWExtenstions.h, GSWExtWOCompatibility.h
o added support to create WO header files
* GSWExtensions/Makefile.preamble
o let gnustep make figure whether to link agains debug libs
o added support for make gswnames=(gsw,wo,all)
* GSWExtensions/Makefile.postamble
o changed support to install WO header files according to
make gswnames=(gsw,wo,all)
* GSWExtensions/*.m
o replaced inclusions of
<GSWeb/GSWeb.h> with "GSWExtWOCompatibility.h"
o replaces inclusions of
<GSWExtensions/file.h> with "file.h"
* GSWExtensions/GSWExtensions.h: new file
* GSWExtensions/WOExtensions.h: new file
* GSWExtensions/GSWExtWOCompatibility.h: new file
* GSWExtensionsGSW/GNUMakefile
o added support for make gswnames=(gsw,wo,all)
o ensure each lib gets built with its own object files
o removed deactivated framework extension determination code
o added references to new file GSWExtGSWWOCompatibility.h
o added support to create WO header files
* GSWExtensionsGSW/Makefile.pramble
o let gnustep make figure whether to link agains debug libs
o added support for make gswnames=(gsw,wo,all)
o removed GSWExtensions from ADDITIONAL_LIB_DIRS
* GSWExtensionsGSW/*.m
o replaced inclusions of
<GSWeb/GSWeb.h> with "GSWExtGSWWOCompatibility.h"
* GSWExtensions/GSWExtGSWWOCompatibility.h: new file
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@15675 72102866-910b-0410-8b05-ffd578937521
2003-01-22 12:24:26 +00:00
# include "GSWeb.h"
2005-04-05 15:54:24 +00:00
# include "GSWPrivate.h"
2000-01-22 12:49:49 +00:00
2004-12-31 14:33:16 +00:00
2008-08-20 20:32:10 +00:00
// static Class standardClass = Nil ;
2007-04-13 18:32:02 +00:00
static Class NSStringClass = Nil ;
static Class NSNumberClass = Nil ;
static Class NSMutableDictionaryClass = Nil ;
static Class GSCachedIntClass = Nil ;
static NSMutableDictionary * _urlAttributesTable = nil ;
static inline BOOL _needQuote ( NSString * str_needQuote )
{
if ( [ str_needQuote isKindOfClass : NSStringClass ] = = NO ) {
return NO ;
} else {
unsigned int mystrlen = [ str_needQuote length ] ;
return ( ( ( mystrlen < 1 ) || ( [ str_needQuote hasPrefix : @ "\" "] == NO)) || ([str_needQuote hasSuffix:@" \ "" ] = = NO ) ) ;
}
}
2004-12-31 14:33:16 +00:00
2000-01-22 12:49:49 +00:00
// === === === === === === === === === === === === === === === === === === === === === === = =
@ implementation GSWHTMLDynamicElement
2004-12-31 14:33:16 +00:00
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ ( void ) initialize
{
if ( self = = [ GSWHTMLDynamicElement class ] )
{
2007-04-13 18:32:02 +00:00
if ( ! _urlAttributesTable ) {
_urlAttributesTable = [ NSMutableDictionary new ] ;
[ _urlAttributesTable setObject : @ "href" forKey : @ "a" ] ;
[ _urlAttributesTable setObject : @ "codebase" forKey : @ "applet" ] ;
[ _urlAttributesTable setObject : @ "href" forKey : @ "area" ] ;
[ _urlAttributesTable setObject : @ "src" forKey : @ "bgsound" ] ;
[ _urlAttributesTable setObject : @ "href" forKey : @ "base" ] ;
[ _urlAttributesTable setObject : @ "background" forKey : @ "body" ] ;
[ _urlAttributesTable setObject : @ "src" forKey : @ "embed" ] ;
[ _urlAttributesTable setObject : @ "action" forKey : @ "form" ] ;
[ _urlAttributesTable setObject : @ "src" forKey : @ "frame" ] ;
[ _urlAttributesTable setObject : [ NSArray arrayWithObjects : @ "src" , @ "dynsrc" , @ "usemap" , nil ]
forKey : @ "img" ] ;
[ _urlAttributesTable setObject : @ "src" forKey : @ "input" ] ;
[ _urlAttributesTable setObject : @ "href" forKey : @ "link" ] ;
[ _urlAttributesTable setObject : @ "src" forKey : @ "script" ] ;
NSStringClass = [ NSString class ] ;
NSNumberClass = [ NSNumber class ] ;
NSMutableDictionaryClass = [ NSMutableDictionary class ] ;
GSCachedIntClass = NSClassFromString ( @ "GSCachedInt" ) ;
}
2002-05-16 18:01:40 +00:00
} ;
2000-01-22 12:49:49 +00:00
} ;
2007-04-13 18:32:02 +00:00
// returns string or array or nil .
+ ( id ) _urlAttributesForElementNamed : ( NSString * ) str
2000-01-22 12:49:49 +00:00
{
2007-04-13 18:32:02 +00:00
id result = nil ;
if ( str = = nil ) {
return nil ;
} else {
result = [ _urlAttributesTable objectForKey : [ str lowercaseString ] ] ;
if ( ! result ) {
NSLog ( @ "%s:%@ %@ " , __PRETTY _FUNCTION __ , str , self ) ;
}
}
return result ;
}
2002-05-16 18:01:40 +00:00
2007-04-13 18:32:02 +00:00
- ( void ) dealloc
2000-01-22 12:49:49 +00:00
{
2007-04-13 18:32:02 +00:00
DESTROY ( _elementName ) ;
DESTROY ( _nonURLAttributeAssociations ) ;
DESTROY ( _urlAttributeAssociations ) ;
DESTROY ( _constantAttributesRepresentation ) ;
DESTROY ( _associations ) ;
2008-08-20 20:32:10 +00:00
DESTROY ( _secure ) ;
2000-01-22 12:49:49 +00:00
[ super dealloc ] ;
2007-04-13 18:32:02 +00:00
}
2000-01-22 12:49:49 +00:00
2004-12-31 14:33:16 +00:00
2007-04-13 18:32:02 +00:00
- ( BOOL ) escapeHTML
2000-01-22 12:49:49 +00:00
{
2007-04-13 18:32:02 +00:00
return NO ;
}
2000-01-22 12:49:49 +00:00
2007-04-13 18:32:02 +00:00
- ( id ) initWithName : ( NSString * ) name
associations : ( NSDictionary * ) associations
template : ( GSWElement * ) template
{
self = [ super initWithName : nil
associations : nil
template : template ] ;
ASSIGN ( _elementName , name ) ;
if ( associations = = nil ) {
[ NSException raise : NSInvalidArgumentException
format : @ "%s: No associations" ,
__PRETTY _FUNCTION __ ] ;
}
DESTROY ( _associations ) ;
2008-08-20 20:32:10 +00:00
_associations = [ associations mutableCopyWithZone : [ self zone ] ] ;
2007-04-13 18:32:02 +00:00
_finishedInitialization = NO ;
return self ;
}
2000-01-22 12:49:49 +00:00
2007-04-13 18:32:02 +00:00
- ( id ) initWithName : ( NSString * ) name
associations : ( NSDictionary * ) associations
contentElements : ( NSMutableArray * ) children
{
// I am not sure if this mehod should exist here at all . dave @ turbocat . de
[ NSException raise : NSInvalidArgumentException
format : @ "%s: sure you want this?" ,
__PRETTY _FUNCTION __ ] ;
//
// self = [ super initWithName : nil
// associations : nil
// contentElements : children ] ;
//
// ASSIGN ( _elementName , name ) ;
// if ( associations = = nil ) {
// [ NSException raise : NSInvalidArgumentException
// format : @ "%s: No associations" ,
// __PRETTY _FUNCTION __ ] ;
// }
// DESTROY ( _associations ) ;
// _associations = [ associations mutableCopyWithZone : nil ] ;
// _finishedInitialization = NO ;
//
return self ;
}
2000-01-22 12:49:49 +00:00
2007-04-13 18:32:02 +00:00
- ( void ) _finishInitialization
2000-01-22 12:49:49 +00:00
{
2007-04-13 18:32:02 +00:00
// lock for _finishedInitialization ?
2000-01-22 12:49:49 +00:00
2007-04-13 18:32:02 +00:00
_nonURLAttributeAssociations = nil ;
_urlAttributeAssociations = nil ;
NSMutableString * buffer = [ NSMutableString stringWithCapacity : 256 ] ;
NSString * str = nil ;
NSString * s1 = nil ;
GSWAssociation * association = nil ;
id aValue = nil ;
int i = 0 ;
if ( ( _elementName ! = nil ) && ( ( _associations ! = nil ) && ( [ _associations count ] > 0 ) ) ) {
NSEnumerator * enumer = [ [ NSArray arrayWithArray : [ _associations allKeys ] ] objectEnumerator ] ;
2008-08-20 20:32:10 +00:00
while ( ( str = [ enumer nextObject ] ) ) {
2007-04-13 18:32:02 +00:00
association = [ _associations objectForKey : str ] ;
if ( ( [ association isKindOfClass : [ GSWConstantValueAssociation class ] ] ) && ( [ self escapeHTML ] = = NO ) ) {
aValue = [ association valueInComponent : nil ] ;
2013-03-03 02:02:36 +00:00
if ( aValue = = nil ) {
2008-08-20 20:32:10 +00:00
s1 = @ "" ;
} else {
s1 = ( NSString * ) aValue ;
}
2007-04-13 18:32:02 +00:00
if ( [ s1 isKindOfClass : NSStringClass ] = = NO ) {
s1 = [ ( NSNumber * ) s1 stringValue ] ;
2002-01-26 10:43:23 +00:00
}
2007-04-13 18:32:02 +00:00
if ( [ aValue isEqual : @ "otherTagString" ] ) {
[ buffer appendString : @ " " ] ;
[ buffer appendString : s1 ] ;
} else {
[ buffer appendString : @ " " ] ;
[ buffer appendString : str ] ;
[ buffer appendString : @ "=" ] ;
if ( _needQuote ( s1 ) || ( [ s1 length ] = = 0 ) ) {
[ buffer appendString : @ "\" " ] ;
[ buffer appendString : s1 ] ;
[ buffer appendString : @ "\" " ] ;
} else {
[ buffer appendString : s1 ] ;
}
2002-05-16 18:01:40 +00:00
}
2007-04-13 18:32:02 +00:00
[ _associations removeObjectForKey : str ] ;
} else {
id resultattribute = [ [ self class ] _urlAttributesForElementNamed : _elementName ] ;
BOOL flag = NO ;
NSString * lowercaseString = [ str lowercaseString ] ;
if ( resultattribute ! = nil )
2002-05-16 18:01:40 +00:00
{
2007-04-13 18:32:02 +00:00
if ( [ resultattribute isKindOfClass : NSStringClass ] = = NO ) {
int j = [ resultattribute count ] ;
for ( i = 0 ; ( ( i < j ) && ( ! flag ) ) ; i + + ) {
flag = [ lowercaseString isEqual : [ resultattribute objectAtIndex : i ] ] ;
}
} else { // is a string
flag = [ lowercaseString isEqual : resultattribute ] ;
}
2002-05-16 18:01:40 +00:00
}
2007-04-13 18:32:02 +00:00
if ( flag ) {
if ( _urlAttributeAssociations = = nil )
{
_urlAttributeAssociations = [ NSMutableDictionary new ] ;
}
[ _urlAttributeAssociations setObject : association forKey : str ] ;
[ _associations removeObjectForKey : str ] ;
2002-01-26 10:43:23 +00:00
}
2007-04-13 18:32:02 +00:00
}
} // while
if ( [ _associations count ] > 0 ) {
ASSIGN ( _nonURLAttributeAssociations , _associations ) ;
}
}
if ( [ buffer length ] > 0 ) {
ASSIGN ( _constantAttributesRepresentation , buffer ) ;
} else {
DESTROY ( _constantAttributesRepresentation ) ;
}
DESTROY ( _associations ) ;
_finishedInitialization = YES ;
}
2003-11-24 12:07:10 +00:00
2007-04-13 18:32:02 +00:00
- ( NSString * ) description
2003-11-24 12:07:10 +00:00
{
2007-04-13 18:32:02 +00:00
NSString * desStr = [ NSString stringWithFormat : @ "<%@ %p elementName:%@ " ,
[ self class ] ,
( void * ) self , _elementName ] ;
if ( _constantAttributesRepresentation ! = nil ) {
desStr = [ desStr stringByAppendingFormat : @ " Constant Attributes: %@" , _constantAttributesRepresentation ] ;
}
if ( _urlAttributeAssociations ! = nil ) {
desStr = [ desStr stringByAppendingFormat : @ " URL Dynamic Attributes: %@" , _urlAttributeAssociations ] ;
}
if ( _nonURLAttributeAssociations ! = nil ) {
desStr = [ desStr stringByAppendingFormat : @ " non-URL Dynamic Attributes: %@" , _nonURLAttributeAssociations ] ;
}
if ( [ self hasChildrenElements ] ) {
desStr = [ desStr stringByAppendingFormat : @ " Children: %@" , [ self childrenElements ] ] ;
}
desStr = [ desStr stringByAppendingString : @ " >" ] ;
return desStr ;
}
- ( NSString * ) elementName
{
return _elementName ;
}
- ( NSMutableDictionary * ) urlAttributeAssociations
{
if ( ! _finishedInitialization ) {
[ self _finishInitialization ] ;
}
return _urlAttributeAssociations ;
}
- ( NSMutableDictionary * ) nonUrlAttributeAssociations
{
if ( ! _finishedInitialization ) {
[ self _finishInitialization ] ;
}
return _nonURLAttributeAssociations ;
}
- ( NSString * ) constantAttributesRepresentation
{
if ( ! _finishedInitialization ) {
[ self _finishInitialization ] ;
}
return _constantAttributesRepresentation ;
}
// _frameworkNameInComponent
2009-04-06 22:22:14 +00:00
+ ( NSString * ) _frameworkNameForAssociation : ( GSWAssociation * ) association
2007-04-13 18:32:02 +00:00
inComponent : ( GSWComponent * ) component
{
2009-04-06 22:22:14 +00:00
NSString * name = nil ;
2007-04-13 18:32:02 +00:00
2009-04-06 22:22:14 +00:00
if ( association ! = nil )
{
name = [ association valueInComponent : component ] ;
if ( name )
{
2010-04-16 00:18:46 +00:00
if ( [ @ "app" caseInsensitiveCompare : name ] )
2009-04-06 22:22:14 +00:00
{
name = nil ;
}
}
else
{
if ( component ! = nil )
{
name = [ component frameworkName ] ;
}
[ GSWApp debugWithFormat : @ "%s evaluated to nil. Defaulting to %@" ,
__PRETTY _FUNCTION __ ,
2010-04-16 00:18:46 +00:00
( name ? name : ( NSString * ) @ "app" ) ] ;
2009-04-06 22:22:14 +00:00
}
2007-04-13 18:32:02 +00:00
}
2009-04-06 22:22:14 +00:00
else
{
if ( component ! = nil )
{
name = [ component frameworkName ] ;
}
2007-04-13 18:32:02 +00:00
}
2009-04-06 22:22:14 +00:00
return name ;
2007-04-13 18:32:02 +00:00
}
2004-03-01 16:42:41 +00:00
2007-04-13 18:32:02 +00:00
// computeActionStringInContext in wo5
2003-01-19 15:33:07 +00:00
- ( NSString * ) computeActionStringWithActionClassAssociation : ( GSWAssociation * ) actionClass
2007-04-13 18:32:02 +00:00
directActionNameAssociation : ( GSWAssociation * ) directActionName
inContext : ( GSWContext * ) context
2004-03-01 16:42:41 +00:00
2003-01-19 15:33:07 +00:00
{
2007-04-13 18:32:02 +00:00
GSWComponent * component = GSWContext_component ( context ) ;
id componentValue = nil ;
id directActionValue = nil ;
id resultString = nil ;
if ( actionClass ! = nil ) {
componentValue = [ actionClass valueInComponent : component ] ;
if ( [ componentValue isKindOfClass : NSStringClass ] = = NO ) {
2003-01-19 15:33:07 +00:00
2007-04-13 18:32:02 +00:00
[ NSException raise : NSInvalidArgumentException
format : @ "%s: Value for attribute named '%@' must be a string. Received '%@'." ,
__PRETTY _FUNCTION __ , actionClass , componentValue ] ;
2003-01-19 15:33:07 +00:00
}
2007-04-13 18:32:02 +00:00
}
if ( directActionName ! = nil )
{
directActionValue = [ directActionName valueInComponent : component ] ;
if ( [ directActionValue isKindOfClass : NSStringClass ] = = NO ) {
[ NSException raise : NSInvalidArgumentException
format : @ "%s: Value for attribute named '%@' must be a string. Received '%@'." ,
__PRETTY _FUNCTION __ , directActionName , directActionValue ] ;
}
}
if ( ( componentValue ! = nil ) && ( directActionValue ! = nil ) ) {
if ( [ componentValue isEqual : @ "DirectAction" ] ) {
resultString = directActionValue ;
} else {
resultString = [ componentValue stringByAppendingString : @ "/" ] ;
resultString = [ resultString stringByAppendingString : directActionValue ] ;
}
} else {
if ( componentValue ! = nil ) {
resultString = componentValue ;
} else {
if ( directActionValue ! = nil ) {
resultString = directActionValue ;
} else {
[ NSException raise : NSInternalInconsistencyException
format : @ "%s: Both 'actionClass' and 'directActionName' are either absent or evaluated to nil. Cannot generate dynamic url without an actionClass or directActionName." ,
__PRETTY _FUNCTION __ ] ;
}
}
}
return resultString ;
}
2008-08-20 20:32:10 +00:00
- ( NSDictionary * ) __queryDictionary : ( GSWAssociation * ) queryDictionary
inContext : ( GSWContext * ) context
{
NSDictionary * aQueryDict = nil ;
if ( queryDictionary ! = nil ) {
aQueryDict = [ queryDictionary valueInComponent : [ context component ] ] ;
}
if ( aQueryDict ! = nil ) {
return aQueryDict ;
} else {
// or a nil ? - - dw
return [ NSDictionary dictionary ] ;
}
}
- ( NSDictionary * ) __otherQueryDictionary : ( NSDictionary * ) otherQueryAssociations
inContext : ( GSWContext * ) context
{
NSMutableDictionary * queryDict = [ NSMutableDictionary dictionary ] ;
if ( otherQueryAssociations ! = nil ) {
NSEnumerator * keyEnumerator = [ otherQueryAssociations keyEnumerator ] ;
NSString * key ;
while ( ( key = [ keyEnumerator nextObject ] ) ) {
GSWAssociation * association = [ otherQueryAssociations objectForKey : key ] ;
id value = [ association valueInComponent : [ context component ] ] ;
if ( value ) {
[ queryDict setObject : value forKey : key ] ;
}
}
}
// is it really faster / better to copy this here ? - - dw
return [ NSDictionary dictionaryWithDictionary : queryDict ] ;
}
- ( NSDictionary * ) computeQueryDictionaryWithRequestHandlerPath : ( NSString * ) aRequestHandlerPath
queryDictionaryAssociation : ( GSWAssociation * ) queryDictionary
otherQueryAssociations : ( NSDictionary * ) otherQueryAssociations
inContext : ( GSWContext * ) context
{
NSDictionary * aQueryDict = [ self __queryDictionary : queryDictionary
inContext : context ] ;
NSDictionary * anotherQueryDict = [ self __otherQueryDictionary : otherQueryAssociations
inContext : context ] ;
return [ context computeQueryDictionaryWithPath : aRequestHandlerPath
queryDictionary : aQueryDict
otherQueryDictionary : anotherQueryDict ] ;
}
2007-04-13 18:32:02 +00:00
- ( NSDictionary * ) computeQueryDictionaryWithActionClassAssociation : ( GSWAssociation * ) actionClass
directActionNameAssociation : ( GSWAssociation * ) directActionName
queryDictionaryAssociation : ( GSWAssociation * ) queryDictionary
otherQueryAssociations : ( NSDictionary * ) otherQueryAssociations
inContext : ( GSWContext * ) context
{
GSWComponent * component = GSWContext_component ( context ) ;
GSWSession * session = [ context _session ] ;
NSString * s = nil ;
NSMutableDictionary * nsmutabledictionary = nil ;
NSEnumerator * keyEnumerator = nil ;
NSString * key = nil ;
GSWAssociation * otherAssociations = nil ;
id otherValue = nil ;
if ( queryDictionary ! = nil ) {
NSDictionary * nsdictionary1 = [ queryDictionary valueInComponent : component ] ;
if ( [ nsdictionary1 isKindOfClass : NSMutableDictionaryClass ] ) {
2008-08-20 20:32:10 +00:00
nsmutabledictionary = ( NSMutableDictionary * ) nsdictionary1 ;
2007-04-13 18:32:02 +00:00
} else {
2008-08-20 20:32:10 +00:00
nsmutabledictionary = ( NSMutableDictionary * ) AUTORELEASE ( [ nsdictionary1 mutableCopyWithZone : [ self zone ] ] ) ;
2007-04-13 18:32:02 +00:00
}
}
if ( nsmutabledictionary = = nil ) {
nsmutabledictionary = [ NSMutableDictionary dictionary ] ;
}
if ( session ! = nil ) {
s = [ session sessionID ] ;
} else {
if ( [ context request ] ! = nil ) {
s = [ [ context request ] stringFormValueForKey : @ "wosid" ] ;
}
}
if ( ( s ! = nil ) && ( ( directActionName ! = nil ) || ( actionClass ! = nil ) ) && ( ( session = = nil ) || ( ! [ session storesIDsInCookies ] ) || ( [ session storesIDsInURLs ] ) ) ) {
[ nsmutabledictionary setObject : s forKey : @ "wosid" ] ;
}
if ( otherQueryAssociations ! = nil ) {
keyEnumerator = [ otherQueryAssociations keyEnumerator ] ;
2008-08-20 20:32:10 +00:00
while ( ( key = [ keyEnumerator nextObject ] ) ) {
2007-04-13 18:32:02 +00:00
otherAssociations = [ otherQueryAssociations objectForKey : key ] ;
otherValue = [ otherAssociations valueInComponent : component ] ;
if ( otherValue ! = nil && ( [ key isEqual : @ "wosid" ] || ( [ otherValue boolValue ] = = YES ) ) ) {
[ nsmutabledictionary setObject : otherValue forKey : key ] ;
} else {
[ nsmutabledictionary removeObjectForKey : key ] ;
}
2005-04-05 15:54:24 +00:00
}
2003-11-24 12:07:10 +00:00
2007-04-13 18:32:02 +00:00
}
return nsmutabledictionary ;
}
- ( void ) appendConstantAttributesToResponse : ( GSWResponse * ) response
inContext : ( GSWContext * ) aContext
{
NSString * str = [ self constantAttributesRepresentation ] ;
if ( str ! = nil ) {
GSWResponse_appendContentString ( response , str ) ;
}
}
- ( void ) _appendAttributesFromAssociationsToResponse : ( GSWResponse * ) response
inContext : ( GSWContext * ) context
associations : ( NSDictionary * ) associations
{
if ( ( associations ! = nil ) && ( [ associations count ] > 0 ) ) {
NSString * s1 = nil ;
NSEnumerator * enumer = [ associations keyEnumerator ] ;
GSWComponent * component = GSWContext_component ( context ) ;
NSString * key = nil ;
GSWAssociation * currentAssociation = nil ;
id obj = nil ;
2008-08-20 20:32:10 +00:00
while ( ( key = [ enumer nextObject ] ) ) {
2007-04-13 18:32:02 +00:00
currentAssociation = [ associations objectForKey : key ] ;
obj = [ currentAssociation valueInComponent : component ] ;
if ( obj ! = nil ) {
// s1 = [ ( NSNumber * ) obj description ] ;
// mr . ayers says that is not good . .
if ( [ obj isKindOfClass : NSNumberClass ] = = YES ) {
s1 = [ ( NSNumber * ) obj stringValue ] ;
} else {
// we have to set the value !
s1 = obj ;
}
// NSLog ( @ "%s:class %@ '%@'" , __PRETTY _FUNCTION __ , [ obj class ] , obj ) ;
if ( [ key isEqual : @ "otherTagString" ] ) {
GSWResponse_appendContentCharacter ( response , ' ' ) ;
GSWResponse_appendContentString ( response , s1 ) ;
} else {
[ response _appendTagAttribute : key
value : s1
escapingHTMLAttributeValue : NO ] ;
}
}
} // while
}
}
2003-01-19 15:33:07 +00:00
2007-04-13 18:32:02 +00:00
- ( void ) appendNonURLAttributesToResponse : ( GSWResponse * ) response
inContext : ( GSWContext * ) context
2003-01-19 15:33:07 +00:00
{
2007-04-13 18:32:02 +00:00
[ self _appendAttributesFromAssociationsToResponse : response
inContext : context
associations : [ self nonUrlAttributeAssociations ] ] ;
2004-12-31 14:33:16 +00:00
2007-04-13 18:32:02 +00:00
}
2003-01-19 15:33:07 +00:00
2007-04-13 18:32:02 +00:00
- ( void ) appendURLAttributesToResponse : ( GSWResponse * ) response
inContext : ( GSWContext * ) context
{
GSWComponent * component = nil ;
NSMutableDictionary * attributeDict = [ self urlAttributeAssociations ] ;
GSWAssociation * association = nil ;
id value = nil ;
2003-01-19 15:33:07 +00:00
2007-04-13 18:32:02 +00:00
if ( ( attributeDict ! = nil ) && ( [ attributeDict count ] > 0 ) ) {
component = GSWContext_component ( context ) ;
NSEnumerator * enumer = [ attributeDict keyEnumerator ] ;
NSString * key = nil ;
NSString * s1 = nil ;
2008-08-20 20:32:10 +00:00
while ( ( key = [ enumer nextObject ] ) ) {
2007-04-13 18:32:02 +00:00
association = [ attributeDict objectForKey : key ] ;
value = [ association valueInComponent : component ] ;
if ( value ! = nil ) {
// value to string ? ?
s1 = [ context _urlForResourceNamed : value
inFramework : nil ] ;
} else {
[ GSWApp debugWithFormat : @ "%s evaluated to nil in component %@. Inserted nil resource in html tag." ,
__PRETTY _FUNCTION __ , component ] ;
}
if ( s1 ! = nil ) {
[ response _appendTagAttribute : key
value : s1
escapingHTMLAttributeValue : NO ] ;
} else {
GSWResponse_appendContentCharacter ( response , ' ' ) ;
GSWResponse_appendContentString ( response , key ) ;
GSWResponse_appendContentAsciiString ( response , @ "=\" " ) ;
GSWResponse_appendContentAsciiString ( response , [ component baseURL ] ) ;
GSWResponse_appendContentCharacter ( response , ' / ' ) ;
GSWResponse_appendContentAsciiString ( response , value ) ;
GSWResponse_appendContentCharacter ( response , ' " ' ) ;
}
}
}
}
2004-03-01 16:42:41 +00:00
2007-04-13 18:32:02 +00:00
- ( void ) appendAttributesToResponse : ( GSWResponse * ) response
inContext : ( GSWContext * ) context
2004-03-01 16:42:41 +00:00
{
2007-04-13 18:32:02 +00:00
[ self appendConstantAttributesToResponse : response
inContext : context ] ;
[ self appendNonURLAttributesToResponse : response
inContext : context ] ;
2004-03-01 16:42:41 +00:00
2007-04-13 18:32:02 +00:00
[ self appendURLAttributesToResponse : response
inContext : context ] ;
}
2004-03-01 16:42:41 +00:00
2007-04-13 18:32:02 +00:00
- ( void ) _appendOpenTagToResponse : ( GSWResponse * ) response
inContext : ( GSWContext * ) context
2004-03-01 16:42:41 +00:00
{
2007-04-13 18:32:02 +00:00
GSWResponse_appendContentCharacter ( response , ' < ' ) ;
GSWResponse_appendContentAsciiString ( response , [ self elementName ] ) ;
[ self appendAttributesToResponse : response inContext : context ] ;
GSWResponse_appendContentCharacter ( response , ' > ' ) ;
}
2004-03-01 16:42:41 +00:00
2007-04-13 18:32:02 +00:00
- ( void ) _appendCloseTagToResponse : ( GSWResponse * ) response
inContext : ( GSWContext * ) context
{
GSWResponse_appendContentAsciiString ( response , @ "</" ) ;
GSWResponse_appendContentAsciiString ( response , [ self elementName ] ) ;
GSWResponse_appendContentCharacter ( response , ' > ' ) ;
}
2004-03-01 16:42:41 +00:00
2007-04-13 18:32:02 +00:00
- ( void ) appendToResponse : ( GSWResponse * ) response
inContext : ( GSWContext * ) context
2004-03-01 16:42:41 +00:00
{
2007-04-13 18:32:02 +00:00
NSString * myElementName = nil ;
if ( context = = nil || response = = nil ) {
return ;
}
myElementName = [ self elementName ] ;
if ( myElementName ! = nil ) {
[ self _appendOpenTagToResponse : response
inContext : context ] ;
}
[ self appendChildrenToResponse : response
inContext : context ] ;
if ( myElementName ! = nil ) {
[ self _appendCloseTagToResponse : response
inContext : context ] ;
}
}
2004-03-01 16:42:41 +00:00
2008-08-20 20:32:10 +00:00
- ( BOOL ) secureInContext : ( GSWContext * ) context
{
if ( _secure ! = nil ) {
return [ _secure boolValueInComponent : [ context component ] ] ;
} else {
return [ context secureMode ] ;
}
}
2004-03-01 16:42:41 +00:00
@ end