diff --git a/ChangeLog b/ChangeLog index 4a149a1..0782b9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2008-03-04 David Wetzel + GSWeb.framework/GSWPageDefElement.m + GSWeb.framework/GSWTemplateParserXML.h + GSWeb.framework/GSWTemplateParserXML.m + GSWeb.framework/GSWPageDefParserExt.h + GSWeb.framework/GSWPageDefParserExt.m + GSWeb.framework/NSObject+IVarAccess+PerformSel.h + GSWeb.framework/NSObject+IVarAccess+PerformSel.m + GSWeb.framework/GSWHTMLAttrParserExt.h + GSWeb.framework/GSWHTMLAttrParserExt.m + GSWeb.framework/GSWHTMLParserExt.h + GSWeb.framework/GSWHTMLParserExt.m + GSWeb.framework/GSWPageDefParserTokenTypes.txt + GSWeb.framework/GSWPageDefElement.h + * deleted unused code + GSWeb.framework/GSWWOCompatibility.h + * removed define + 2008-03-02 David Wetzel GSWeb.framework/GSWHTTPIO.m * optimized readDataLine diff --git a/GSWeb.framework/GSWHTMLAttrParserExt.h b/GSWeb.framework/GSWHTMLAttrParserExt.h deleted file mode 100644 index 60be82b..0000000 --- a/GSWeb.framework/GSWHTMLAttrParserExt.h +++ /dev/null @@ -1,49 +0,0 @@ -/** GSWHTMLAttrParserExt.h - GSWeb: Class GSWHTMLAttrParserExt: Categories - - Copyright (C) 1999-2002 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 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. - -**/ - -// $Id$ - -#ifndef _GSWHTMLAttrParserExt_h__ - #define _GSWHTMLAttrParserExt_h__ - - -@interface GSWHTMLAttrParser (GSWHTMLAttrParserExt) --(NSString*)tagName; --(NSDictionary*)attributes; --(void)dealloc; --(void)reportErrorWithException:(NSException*)exception; --(void)reportError:(NSString*)text; --(void)reportWarning:(NSString*)text; --(BOOL)isError; --(BOOL)isWarning; --(NSArray*)errors; --(NSArray*)warnings; -@end - -#endif //_GSWHTMLAttrParserExt_h__ diff --git a/GSWeb.framework/GSWHTMLAttrParserExt.m b/GSWeb.framework/GSWHTMLAttrParserExt.m deleted file mode 100644 index d01829e..0000000 --- a/GSWeb.framework/GSWHTMLAttrParserExt.m +++ /dev/null @@ -1,127 +0,0 @@ -/** GSWHTMLAttrParserExt.m - GSWeb: Class GSWHTMLAttrParserExt: Categories - - Copyright (C) 1999-2002 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 1999 - - $Revision$ - $Date$ - $Id$ - - 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 "GSWeb.h" -#include "GSWHTMLAttrParser.h" - -//==================================================================== -@implementation GSWHTMLAttrParser (GSWHTMLAttrParserExt) - -//-------------------------------------------------------------------- --(NSString*)tagName -{ - return tagName; -}; - -//-------------------------------------------------------------------- --(NSDictionary*)attributes -{ - return attributes; -}; - -//-------------------------------------------------------------------- --(void)dealloc -{ -// GSWLogC("Dealloc GSWHTMLAttrParser"); -// GSWLogC("Dealloc GSWHTMLAttrParser: tagName"); - DESTROY(tagName); -// GSWLogC("Dealloc GSWHTMLAttrParser: attributes"); - DESTROY(attributes); -// GSWLogC("Dealloc GSWPageDefParser: errors"); - DESTROY(errors); -// GSWLogC("Dealloc GSWPageDefParser: warnings"); - DESTROY(warnings); - [super dealloc]; -// GSWLogC("End Dealloc GSWHTMLAttrParser"); -}; - - -//-------------------------------------------------------------------- --(void)reportErrorWithException:(NSException*)exception -{ - NSString* error=nil; - if (!errors) - errors=[NSMutableArray new]; - error=[NSString stringWithFormat:@"Parsing Exception: %@ (Reason:%@)", - [exception description], - [exception reason]]; - [errors addObject:error]; -}; - -//-------------------------------------------------------------------- --(void)reportError:(NSString*)text -{ - NSString* error=nil; - if (!errors) - errors=[NSMutableArray new]; - error=[NSString stringWithFormat:@"Parsing Error: %@", - text]; - [errors addObject:error]; -}; - -//-------------------------------------------------------------------- --(void)reportWarning:(NSString*)text -{ - NSString* warning=nil; - if (!warnings) - warnings=[NSMutableArray new]; - warning=[NSString stringWithFormat:@"Parsing Warning: %@", - text]; - [warnings addObject:warning]; -}; - -//-------------------------------------------------------------------- --(BOOL)isError -{ - return ([errors count]>0); -}; - -//-------------------------------------------------------------------- --(BOOL)isWarning -{ - return ([warnings count]>0); -}; - -//-------------------------------------------------------------------- --(NSArray*)errors -{ - return errors; -}; - -//-------------------------------------------------------------------- --(NSArray*)warnings -{ - return warnings; -}; - - -@end - - diff --git a/GSWeb.framework/GSWHTMLParserExt.h b/GSWeb.framework/GSWHTMLParserExt.h deleted file mode 100644 index 05c9f94..0000000 --- a/GSWeb.framework/GSWHTMLParserExt.h +++ /dev/null @@ -1,48 +0,0 @@ -/** GSWHTMLParserExt.h - GSWeb: Class GSWHTMLParser: Categories - - Copyright (C) 1999-2002 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 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. - -**/ - -// $Id$ - -#ifndef _GSWHTMLParserExt_h__ - #define _GSWHTMLParserExt_h__ - - -@interface GSWHTMLParser (GSWHTMLParserExt) --(void)dealloc; --(void)reportErrorWithException:(NSException*)exception; --(void)reportError:(NSString*)text; --(void)reportWarning:(NSString*)text; --(BOOL)isError; --(BOOL)isWarning; --(NSArray*)errors; --(NSArray*)warnings; - -@end - -#endif //_GSWHTMLParserExt_h__ diff --git a/GSWeb.framework/GSWHTMLParserExt.m b/GSWeb.framework/GSWHTMLParserExt.m deleted file mode 100644 index 249a7bd..0000000 --- a/GSWeb.framework/GSWHTMLParserExt.m +++ /dev/null @@ -1,111 +0,0 @@ -/** GSWHTMLParserExt.m - GSWeb: Class GSWHTMLParser: Categories - - Copyright (C) 1999-2003 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 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 GSWHTMLParser (GSWHTMLParserExt) - -//-------------------------------------------------------------------- --(void)dealloc -{ -// GSWLogC("Dealloc GSWHTMLParser"); -// GSWLogC("Dealloc GSWHTMLParser: errors"); - DESTROY(errors); -// GSWLogC("Dealloc GSWHTMLParser: warnings"); - DESTROY(warnings); - [super dealloc]; -// GSWLogC("End Dealloc GSWHTMLParser"); -}; - -//-------------------------------------------------------------------- --(void)reportErrorWithException:(NSException*)exception -{ - NSString* error=nil; - if (!errors) - errors=[NSMutableArray new]; - error=[NSString stringWithFormat:@"Parsing Exception: %@ (Reason:%@)", - [exception description], - [exception reason]]; - [errors addObject:error]; -}; - -//-------------------------------------------------------------------- --(void)reportError:(NSString*)text -{ - NSString* error=nil; - if (!errors) - errors=[NSMutableArray new]; - error=[NSString stringWithFormat:@"Parsing Error: %@", - text]; - [errors addObject:error]; -}; - -//-------------------------------------------------------------------- --(void)reportWarning:(NSString*)text -{ - NSString* warning=nil; - if (!warnings) - warnings=[NSMutableArray new]; - warning=[NSString stringWithFormat:@"Parsing Warning: %@", - text]; - [warnings addObject:warning]; -}; - -//-------------------------------------------------------------------- --(BOOL)isError -{ - return ([errors count]>0); -}; - -//-------------------------------------------------------------------- --(BOOL)isWarning -{ - return ([warnings count]>0); -}; - -//-------------------------------------------------------------------- --(NSArray*)errors -{ - return errors; -}; - -//-------------------------------------------------------------------- --(NSArray*)warnings -{ - return warnings; -}; - -@end - - diff --git a/GSWeb.framework/GSWPageDefElement.h b/GSWeb.framework/GSWPageDefElement.h deleted file mode 100644 index e238769..0000000 --- a/GSWeb.framework/GSWPageDefElement.h +++ /dev/null @@ -1,58 +0,0 @@ -/** GSWPageDefElement.h - GSWeb: Class GSWPageDefElement - - Copyright (C) 1999-2002 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 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. - -**/ - -// $Id$ - -#ifndef _GSWPageDefElement_h__ - #define _GSWPageDefElement_h__ - -//==================================================================== -@interface GSWPageDefElement: NSObject -{ - NSString* _elementName; - NSString* _className; - NSMutableDictionary* _associations; -}; - --(NSString*)description; --(id)init; --(void)dealloc; --(id)copyWithZone:(NSZone *)zone; --(id)initWithCoder:(NSCoder*)code; --(void)encodeWithCoder:(NSCoder*)code; --(NSString*)elementName; --(void)setElementName:(NSString*)aNname; --(NSString*)className; --(void)setClassName:(NSString*)aNname; --(NSDictionary*)associations; --(void)setAssociation:(GSWAssociation*)association - forKey:(NSString*)key; -@end - -#endif //_GSWPageDefElement_h__ diff --git a/GSWeb.framework/GSWPageDefElement.m b/GSWeb.framework/GSWPageDefElement.m deleted file mode 100644 index e7653e4..0000000 --- a/GSWeb.framework/GSWPageDefElement.m +++ /dev/null @@ -1,149 +0,0 @@ -/** GSWPageDefElement.m - GSWeb: Class GSWPageDefElement - - Copyright (C) 1999-2003 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 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 GSWPageDefElement - -//-------------------------------------------------------------------- -// init - --(id)init -{ - if ((self=[super init])) - { - }; - return self; -}; - -//-------------------------------------------------------------------- --(void)dealloc -{ -// NSDebugFLLog(@"low",@"Dealloc GSWPageDefElement=%p",(void*)self); -// GSWLogC("Dealloc GSWPageDefElement: elementName"); - DESTROY(_elementName); -// GSWLogC("Dealloc GSWPageDefElement: className"); - DESTROY(_className); -// GSWLogC("Dealloc GSWPageDefElement: associations"); - DESTROY(_associations); - [super dealloc]; -// GSWLogC("End Dealloc GSWPageDefElement"); -} - -//-------------------------------------------------------------------- --(id)copyWithZone:(NSZone*)zone -{ - GSWPageDefElement* clone = [[isa allocWithZone:zone] init]; - ASSIGNCOPY(clone->_elementName,_elementName); - ASSIGNCOPY(clone->_className,_className); - ASSIGNCOPY(clone->_associations,_associations); - return clone; -}; - -//-------------------------------------------------------------------- --(id)initWithCoder:(NSCoder*)coder -{ - if ((self = [super init])) - { - [coder decodeValueOfObjCType:@encode(id) - at:&_elementName]; - [coder decodeValueOfObjCType:@encode(id) - at:&_className]; - [coder decodeValueOfObjCType:@encode(id) - at:&_associations]; - }; - return self; -}; - -//-------------------------------------------------------------------- --(void)encodeWithCoder:(NSCoder*)coder -{ - [coder encodeObject:_elementName]; - [coder encodeObject:_className]; - [coder encodeObject:_associations]; -}; - - -//-------------------------------------------------------------------- --(NSString*)elementName -{ - return _elementName; -}; - -//-------------------------------------------------------------------- --(void)setElementName:(NSString*)aName -{ - ASSIGNCOPY(_elementName,aName); -}; - -//-------------------------------------------------------------------- --(NSString*)className -{ - return _className; -}; - -//-------------------------------------------------------------------- --(void)setClassName:(NSString*)aName -{ - ASSIGNCOPY(_className,aName); -}; - -//-------------------------------------------------------------------- --(NSDictionary*)associations -{ - return _associations; -}; - -//-------------------------------------------------------------------- --(void)setAssociation:(GSWAssociation*)association - forKey:(NSString*)key -{ - if (!_associations) - _associations=[NSMutableDictionary new]; - [_associations setObject:association - forKey:key]; -}; - -//-------------------------------------------------------------------- --(NSString*)description -{ - return [NSString stringWithFormat:@"<%@ %p elementName:[%@] className:[%@] associations:\n%@", - [self class], - (void*)self, - _elementName, - _className, - _associations]; -}; -@end diff --git a/GSWeb.framework/GSWPageDefParserExt.h b/GSWeb.framework/GSWPageDefParserExt.h deleted file mode 100644 index 3c3ca84..0000000 --- a/GSWeb.framework/GSWPageDefParserExt.h +++ /dev/null @@ -1,50 +0,0 @@ -/** GSWPageDefParserExt.h - GSWeb: Class GSWPageDefParserExt - - Copyright (C) 1999-2002 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 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. - -**/ - -// $Id$ - -#ifndef _GSWPageDefParserExt_h__ - #define _GSWPageDefParserExt_h__ - - -@interface GSWPageDefParser (GSWPageDefParserExt) --(NSDictionary*)elements; --(NSArray*)includes; --(void)dealloc; --(void)reportErrorWithException:(NSException*)exception; --(void)reportError:(NSString*)text; --(void)reportWarning:(NSString*)text; --(BOOL)isError; --(BOOL)isWarning; --(NSArray*)errors; --(NSArray*)warnings; --(NSString*)unescapedString:(NSString*)string; -@end - -#endif //_GSWPageDefParserExt_h__ diff --git a/GSWeb.framework/GSWPageDefParserExt.m b/GSWeb.framework/GSWPageDefParserExt.m deleted file mode 100644 index 69cc8ed..0000000 --- a/GSWeb.framework/GSWPageDefParserExt.m +++ /dev/null @@ -1,147 +0,0 @@ -/** GSWPageDefParserExt.m - GSWeb: Class GSWPageDefParserExt - - Copyright (C) 1999-2003 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 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 GSWPageDefParser (GSWPageDefParserExt) - -//-------------------------------------------------------------------- --(NSDictionary*)elements -{ - return elements; -}; - --(NSArray*)includes -{ - return includes; -}; - -//-------------------------------------------------------------------- --(void)dealloc -{ -// GSWLogC("Dealloc GSWPageDefParser"); -// GSWLogC("Dealloc GSWPageDefParser: elements"); - DESTROY(elements); -// GSWLogC("Dealloc GSWPageDefParser: includes"); - DESTROY(includes); -// GSWLogC("Dealloc GSWPageDefParser: errors"); - DESTROY(errors); -// GSWLogC("Dealloc GSWPageDefParser: warnings"); - DESTROY(warnings); - [super dealloc]; -// GSWLogC("End Dealloc GSWPageDefParser"); -}; - -//-------------------------------------------------------------------- --(void)reportErrorWithException:(NSException*)exception -{ - NSString* error=nil; - if (!errors) - errors=[NSMutableArray new]; - error=[NSString stringWithFormat:@"Parsing Exception: %@ (Reason:%@)", - [exception description], - [exception reason]]; - [errors addObject:error]; -}; - -//-------------------------------------------------------------------- --(void)reportError:(NSString*)text -{ - NSString* error=nil; - if (!errors) - errors=[NSMutableArray new]; - error=[NSString stringWithFormat:@"Parsing Error: %@", - text]; - [errors addObject:error]; -}; - -//-------------------------------------------------------------------- --(void)reportWarning:(NSString*)text -{ - NSString* warning=nil; - if (!warnings) - warnings=[NSMutableArray new]; - warning=[NSString stringWithFormat:@"Parsing Warning: %@", - text]; - [warnings addObject:warning]; -}; - -//-------------------------------------------------------------------- --(BOOL)isError -{ - return ([errors count]>0); -}; - -//-------------------------------------------------------------------- --(BOOL)isWarning -{ - return ([warnings count]>0); -}; - -//-------------------------------------------------------------------- --(NSArray*)errors -{ - return errors; -}; - -//-------------------------------------------------------------------- --(NSArray*)warnings -{ - return warnings; -}; - -//-------------------------------------------------------------------- --(NSString*)unescapedString:(NSString*)aString -{ - //TODO - aString=[aString stringByReplacingString:@"\\n" - withString:@"\n"]; - aString=[aString stringByReplacingString:@"\\r" - withString:@"\r"]; - aString=[aString stringByReplacingString:@"\\t" - withString:@"\t"]; - aString=[aString stringByReplacingString:@"\\b" - withString:@"\b"]; - aString=[aString stringByReplacingString:@"\\f" - withString:@"\f"]; - aString=[aString stringByReplacingString:@"\\\"" - withString:@"\""]; - aString=[aString stringByReplacingString:@"\\\'" - withString:@"\'"]; - return aString; -}; - -@end - - diff --git a/GSWeb.framework/GSWPageDefParserTokenTypes.txt b/GSWeb.framework/GSWPageDefParserTokenTypes.txt deleted file mode 100644 index 7147222..0000000 --- a/GSWeb.framework/GSWPageDefParserTokenTypes.txt +++ /dev/null @@ -1,30 +0,0 @@ -GSWPageDefParser // tokenVocabulary name -INCLUDE=4 -WS=5 -STRING=6 -IDENT=7 -COLUMN=8 -LCURLY=9 -RCURLY=10 -SEMI=11 -ASSIGN=12 -QUESTIONMARK=13 -EXCLAMATIONMARK=14 -INT=15 -YES=16 -NO=17 -HEXNUM=18 -CIRC=19 -TILDE=20 -IDENTREF=21 -PIDENT=22 -PIDENTREF=23 -SL_COMMENT=24 -ML_COMMENT=25 -POINT=26 -ESC=27 -HEXINT=28 -DIGIT=29 -HEXDIGIT=30 -LCLETTER=31 -LETTER=32 diff --git a/GSWeb.framework/GSWTemplateParserXML.h b/GSWeb.framework/GSWTemplateParserXML.h deleted file mode 100644 index 4df6a2b..0000000 --- a/GSWeb.framework/GSWTemplateParserXML.h +++ /dev/null @@ -1,91 +0,0 @@ -/** GSWTemplateParserXML.h - GSWeb: Class GSWTemplateParserXML - - Copyright (C) 1999-2002 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 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. - -**/ - -// $Id$ - -#ifndef _GSWTemplateParserXML_h__ - #define _GSWTemplateParserXML_h__ - -#include "GSWTemplateParser.h" -#include - - -@class GSWTemplateParser; -//==================================================================== -@interface GSWTemplateParserSAXHandler : GSHTMLSAXHandler -{ - GSWTemplateParser* _templateParser; -}; - -+(void)lock; -+(void)unlock; -+(NSString*)cachedDTDContentForKey:(NSString*)url; -+(void)setCachedDTDContent:(NSString*)externalContent - forKey:(NSString*)url; -+(NSString*)cachedDTDFilePathForKey:(NSString*)url; -+(void)setCachedDTDFilePath:(NSString*)filePath - forKey:(NSString*)url; -+(id)handlerWithTemplateParser:(GSWTemplateParser*)templateParser; --(id)initWithTemplateParser:(GSWTemplateParser*)templateParser; --(id)init; --(void)warning:(NSString*)message - colNumber:(int)colNumber - lineNumber:(int)lineNumber; --(void)error:(NSString*)message - colNumber:(int)colNumber - lineNumber:(int)lineNumber; --(void)fatalError:(NSString*)message - colNumber:(int)colNumber - lineNumber:(int)lineNumber; -@end - -//==================================================================== -@interface GSWTemplateParserXML : GSWTemplateParser -{ - GSXMLDocument* _xmlDocument; - BOOL _isHTMLTag; - BOOL _isBodyTag; -} - --(void)dealloc; --(NSArray*)templateElements; --(NSArray*)createElementsFromNode:(GSXMLNode*)node; - -@end - -//==================================================================== -@interface GSWTemplateParserXMLHTML : GSWTemplateParserXML -{ -}; -/** call htmlHandleOmittedElem(0) if YES, htmlHandleOmittedElem(1) if NO; **/ --(void)setNoOmittedTags:(BOOL)yn; - -@end - -#endif //_GSWTemplateParserXML_h__ diff --git a/GSWeb.framework/GSWTemplateParserXML.m b/GSWeb.framework/GSWTemplateParserXML.m deleted file mode 100644 index 381e6fe..0000000 --- a/GSWeb.framework/GSWTemplateParserXML.m +++ /dev/null @@ -1,1189 +0,0 @@ -/** GSWTemplateParserXML.m - GSWeb: Class GSWTemplateParserXML - - Copyright (C) 1999-2004 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - Date: Mar 1999 - - $Revision$ - $Date$ - $Id$ - - - - 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" -#include "GSWTemplateParserXML.h" -#include -#include -#include -#include - -extern xmlParserInputPtr xmlNewStringInputStream(xmlParserCtxtPtr ctxt, - const xmlChar *buffer); - -static NSLock* GSXMLParserLock=nil; -static NSMutableDictionary* DTDCache=nil; -static NSMutableDictionary* DTDFilePathCache=nil; - -@interface GSWTemplateParserSAXHandler (Private) --(xmlParserInputPtr)resolveEntity:(NSString*)publicIdEntity - systemID:(NSString*)systemIdEntity; -@end - -//==================================================================== -@implementation GSWTemplateParserSAXHandler - -//-------------------------------------------------------------------- -+ (void) initialize -{ - // Initialize DTD Cache, and Lock - if (self==[GSWTemplateParserSAXHandler class]) - { - if (!DTDCache) - DTDCache=[NSMutableDictionary new]; - if (!DTDFilePathCache) - DTDFilePathCache=[NSMutableDictionary new]; - if (!GSXMLParserLock) - GSXMLParserLock=[NSRecursiveLock new]; - }; -}; - -//-------------------------------------------------------------------- -+(void)dealloc -{ - // Dealloc DTD Cache and Lock - if (self==[GSWTemplateParserSAXHandler class]) - { - DESTROY(DTDCache); - DESTROY(DTDFilePathCache); - DESTROY(GSXMLParserLock); - }; -}; - -//-------------------------------------------------------------------- -/*"Lock"*/ -+(void)lock -{ - NS_DURING - { - [GSXMLParserLock lock]; - } - NS_HANDLER - { - NSLog(@"EXCEPTION:(GSXMLParserLock lock) %@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); - [localException raise]; - }; - NS_ENDHANDLER; -}; - -//-------------------------------------------------------------------- -/*"Unlock"*/ -+(void)unlock -{ - NS_DURING - { - [GSXMLParserLock unlock]; - } - NS_HANDLER - { - NSLog(@"EXCEPTION:(GSXMLParserLock unlock) %@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); - [localException raise]; - }; - NS_ENDHANDLER; -}; - -//-------------------------------------------------------------------- -/** Find cached DTD Content for Key url **/ -+(NSString*)cachedDTDContentForKey:(NSString*)url -{ - NSString* content=nil; - [self lock]; - content=[DTDCache objectForKey:url]; - [self unlock]; - return content; -}; - -//-------------------------------------------------------------------- -/** Cache DTD Content externalContent for Key url **/ -+(void)setCachedDTDContent:(NSString*)externalContent - forKey:(NSString*)url -{ - [self lock]; - [DTDCache setObject:externalContent - forKey:url]; - [self unlock]; -}; - -//-------------------------------------------------------------------- -/** Find cached DTD FilePath for Key url **/ -+(NSString*)cachedDTDFilePathForKey:(NSString*)url -{ - NSString* filePath=nil; - [self lock]; - filePath=[DTDFilePathCache objectForKey:url]; - [self unlock]; - return filePath; -}; - -//-------------------------------------------------------------------- -/** Cache DTD FilePath for Key url **/ -+(void)setCachedDTDFilePath:(NSString*)filePath - forKey:(NSString*)url -{ - [self lock]; - [DTDFilePathCache setObject:filePath - forKey:url]; - [self unlock]; -}; - -//-------------------------------------------------------------------- -+(id)handlerWithTemplateParser:(GSWTemplateParser*)templateParser -{ - return AUTORELEASE([[self alloc] initWithTemplateParser:templateParser]); -}; - -extern void externalSubset (void *ctx, - const xmlChar *name, - const xmlChar *ExternalID, - const xmlChar *SystemID); - -//-------------------------------------------------------------------- --(id)initWithTemplateParser:(GSWTemplateParser*)templateParser -{ - if ((self=[self init])) - { - _templateParser=templateParser; - //NSLog(@"my sax lib=%p",lib); - if (lib) - { - xmlSAXHandlerPtr def=NULL; - if ([_templateParser isKindOfClass:[GSWTemplateParserXMLHTML class]]) - def=&htmlDefaultSAXHandler; - else - def=&xmlDefaultSAXHandler; - ((xmlSAXHandlerPtr)lib)->internalSubset = def->internalSubset; - ((xmlSAXHandlerPtr)lib)->isStandalone = def->isStandalone; - ((xmlSAXHandlerPtr)lib)->hasInternalSubset = def->hasInternalSubset; - ((xmlSAXHandlerPtr)lib)->hasExternalSubset = def->hasExternalSubset; - ((xmlSAXHandlerPtr)lib)->resolveEntity = def->resolveEntity; - ((xmlSAXHandlerPtr)lib)->getEntity = def->getEntity; - ((xmlSAXHandlerPtr)lib)->entityDecl = def->entityDecl; - ((xmlSAXHandlerPtr)lib)->notationDecl = def->notationDecl; - ((xmlSAXHandlerPtr)lib)->attributeDecl = def->attributeDecl; - ((xmlSAXHandlerPtr)lib)->elementDecl = def->elementDecl; - ((xmlSAXHandlerPtr)lib)->unparsedEntityDecl = def->unparsedEntityDecl; - ((xmlSAXHandlerPtr)lib)->startDocument = def->startDocument; - ((xmlSAXHandlerPtr)lib)->endDocument = def->endDocument; - ((xmlSAXHandlerPtr)lib)->startElement = def->startElement; - ((xmlSAXHandlerPtr)lib)->endElement = def->endElement; - ((xmlSAXHandlerPtr)lib)->reference = def->reference; - ((xmlSAXHandlerPtr)lib)->characters = def->characters; - ((xmlSAXHandlerPtr)lib)->ignorableWhitespace = def->ignorableWhitespace; - ((xmlSAXHandlerPtr)lib)->processingInstruction = def->processingInstruction; - ((xmlSAXHandlerPtr)lib)->comment = def->comment; - // ((xmlSAXHandlerPtr)lib)->warning = xmlParserWarning; - // ((xmlSAXHandlerPtr)lib)->error = xmlParserError; - // ((xmlSAXHandlerPtr)lib)->fatalError = xmlParserError; - ((xmlSAXHandlerPtr)lib)->getParameterEntity = def->getParameterEntity; - ((xmlSAXHandlerPtr)lib)->cdataBlock = def->cdataBlock; - ((xmlSAXHandlerPtr)lib)->externalSubset = def->externalSubset; - }; - }; - return self; -}; - --(id)init -{ - if ((self=[super init])) - { - }; - return self; -}; - -+ (NSString*) loadEntity: (NSString*)publicId - at: (NSString*)location -{ - NSDebugMLog(@"+LOAD ENTITY pid=%@ l=%@",publicId,location); - return nil; -} - -/** Should return a file path - publicId: for exemple: -//W3C//DTD XHTML 1.0 Transitional//EN - location: for exemple: xhtml1-transitional.dtd -**/ -- (NSString*) loadEntity: (NSString*)publicId - at: (NSString*)location -{ - NSString* filePath=nil; - LOGObjectFnStart(); - NSDebugMLLog(@"GSWTemplateParser",@"loadEntity:%@ at:%@\n", - publicId, - location); - NSAssert(publicId || location, - @"resolveEntity: publicId and location are both nil"); - if (location) - { - NSString* resourceName=location; - if ([[resourceName pathExtension] isEqual:@"dtd"]) - resourceName=[resourceName stringByDeletingPathExtension]; - filePath = [[NSBundle bundleForClass: [self class]] - pathForResource:resourceName - ofType:@"dtd" - inDirectory:@"DTDs"]; - NSDebugMLLog(@"GSWTemplateParser",@"location: fileName=%@ for Resource:%@",filePath,resourceName); - }; - if (!filePath && publicId) - { - filePath=[[self class] cachedDTDFilePathForKey:publicId]; - if (!filePath) - { - //Well Known DTDs / Entities - if ([publicId hasPrefix:@"-//"]) - { - // 0: - - // 1: W3C or IETF - // 2: DTD ... or ENTITIES ... - // 3: EN or ... (language) - NSArray* parts=[publicId componentsSeparatedByString:@"//"]; - if ([parts count]>=2) - { - NSString* whatPart=[parts objectAtIndex:2]; - if ([whatPart hasPrefix:@"DTD"]) - { - NSString* resourceName=nil; - if ([whatPart rangeOfString:@"Transitional"].length>0) - resourceName=@"xhtml1-transitional.dtd"; - else if ([whatPart rangeOfString:@"Strict"].length>0) - resourceName=@"xhtml1-strict.dtd"; - else if ([whatPart rangeOfString:@"Frameset"].length>0) - resourceName=@"xhtml1-frameset.dtd"; - else - { - NSDebugMLog(@"Unknown DTD: %@. Choose default: xhtml1-transitional.dtd",publicId); - resourceName=@"xhtml1-transitional.dtd"; // guess - }; - if (resourceName) - { - if ([[resourceName pathExtension] isEqual:@"dtd"]) - resourceName=[resourceName stringByDeletingPathExtension]; - filePath = [[NSBundle bundleForClass: [self class]] - pathForResource:resourceName - ofType:@"dtd" - inDirectory:@"DTDs"]; - NSDebugMLLog(@"GSWTemplateParser",@"fileName=%@ for Resource:%@",filePath,publicId); - }; - } - else if ([whatPart hasPrefix:@"ENTITIES"]) - { - NSString* resourceName=nil; - if ([whatPart rangeOfString:@"Symbols"].length>0) - resourceName=@"xhtml-symbol.ent"; - else if ([whatPart rangeOfString:@"Special"].length>0) - resourceName=@"xhtml-special.ent"; - else if ([whatPart rangeOfString:@"Latin 1"].length>0) - resourceName=@"xhtml-lat1.ent"; - else - { - NSDebugMLog(@"Unknown ENTITIES: %@",publicId); - }; - if (resourceName) - { - if ([[resourceName pathExtension] isEqual:@"ent"]) - resourceName=[resourceName stringByDeletingPathExtension]; - filePath = [[NSBundle bundleForClass: [self class]] - pathForResource:resourceName - ofType:@"ent" - inDirectory:@"DTDs"]; - NSDebugMLLog(@"GSWTemplateParser",@"fileName=%@ for Resource:%@",filePath,publicId); - }; - } - else - { - NSDebugMLog(@"Unknown publicId %@",publicId); - }; - } - else - { - NSDebugMLog(@"Don't know how to parse publicId %@",publicId); - }; - } - else - { - NSDebugMLog(@"Don't know what to do with publicId %@",publicId); - }; - if (filePath) - [[self class] setCachedDTDFilePath:filePath - forKey:publicId]; - }; - }; - if (!filePath) - { - NSDebugMLog(@"Can't load external (publicId:%@ location:%@)",publicId,location); - } - else - { - NSDebugMLLog(@"GSWTemplateParser",@"LOADED: resolveEntity:%@ location:%@ filePath:%@\n", - publicId, - location, - filePath); - }; - LOGObjectFnStop(); - return filePath; - -} - -- (void*) getEntity: (NSString*)name -{ - NSDebugMLog(@"-GET ENTITY %@",name); - return 0; -} - -/* -xmlParserInputPtr GSWTemplateParserSAXHandler_ExternalLoader(const char *systemId, - const char *publicId, - xmlParserCtxtPtr context) -{ -// NSCAssert(context,@"No Parser Context"); -// NSCAssert(context->_private,@"No GSSAXHandler reference in Parser Context"); -// return [(GSSAXHandler*)(context->_private)resolveEntity:[NSString stringWithCString:publicId] -// systemID:[NSString stringWithCString:systemId]]; - return NULL; -} -*/ - -//-------------------------------------------------------------------- -//exemple: -// publicIdEntity -// -//IETF//DTD HTML//EN -// -//W3C//ENTITIES Special for XHTML//EN -// -//W3C//ENTITIES Symbols for XHTML//EN -// -//W3C//ENTITIES Latin 1 for XHTML//EN -// -//W3C//DTD XHTML 1.0 Transitional//EN -// -//W3C//DTD XHTML 1.0 Strict//EN -// -//W3C//DTD XHTML 1.0 Frameset//EN -// -//W3C//DTD HTML 4.01//EN -// -//W3C//DTD HTML 4.01 Transitional//EN -// -//W3C//DTD HTML 4.01 Frameset//EN -// -//IETF//DTD HTML//EN -// -//W3C//DTD HTML 3.2//EN -// systemIdEntity -// http://www.w3c.org/html.dtd -// html.dtd - --(xmlParserInputPtr)resolveEntity:(NSString*)publicIdEntity - systemID:(NSString*)systemIdEntity -{ - NSString* externalContent=nil; - xmlParserInputPtr result = 0; - LOGObjectFnStart(); - NSDebugMLLog(@"GSWTemplateParser",@"resolveEntity:%@ systemID:%@ inParserContext:%p\n", - publicIdEntity, - systemIdEntity, - lib); - NSAssert(publicIdEntity || systemIdEntity, - @"resolveEntity:systemIdEntity: publicIdEntity and systemIdEntity are both nil"); - if (systemIdEntity) - { - externalContent=[[self class] cachedDTDContentForKey:systemIdEntity]; - if (!externalContent) - { - NSString* fileName=nil; - NSString* resourceName=systemIdEntity; - if ([[resourceName pathExtension] isEqual:@"dtd"]) - resourceName=[resourceName stringByDeletingPathExtension]; - fileName = [[NSBundle bundleForClass: [self class]] - pathForResource:resourceName - ofType:@"dtd" - inDirectory:@"DTDs"]; - NSDebugMLLog(@"GSWTemplateParser",@"systemIdEntity: fileName=%@ for Resource:%@",fileName,resourceName); - if (fileName) - { - externalContent=[NSString stringWithContentsOfFile:fileName]; - }; - externalContent=[NSString stringWithContentsOfFile:fileName]; - if (externalContent) - { - NSString* gswebTag=@"\n\n\n"; - // name NMTOKEN; #IMPLIED - NSDebugMLLog(@"GSWTemplateParser",@"gswebTag=\n%@",gswebTag); - externalContent=[externalContent stringByAppendingString:gswebTag]; - - [[self class] setCachedDTDContent:externalContent - forKey:systemIdEntity]; - }; - }; - }; - if (!externalContent && publicIdEntity) - { - externalContent=[[self class] cachedDTDContentForKey:publicIdEntity]; - if (!externalContent) - { - //Well Known DTDs / Entities - if ([publicIdEntity hasPrefix:@"-//"]) - { - // 0: - - // 1: W3C or IETF - // 2: DTD ... or ENTITIES ... - // 3: EN or ... (language) - NSArray* parts=[publicIdEntity componentsSeparatedByString:@"//"]; - if ([parts count]>=2) - { - NSString* whatPart=[parts objectAtIndex:2]; - if ([whatPart hasPrefix:@"DTD"]) - { - NSString* resourceName=nil; - NSString* fileName=nil; - if ([whatPart rangeOfString:@"Transitional"].length>0) - resourceName=@"xhtml1-transitional.dtd"; - else if ([whatPart rangeOfString:@"Strict"].length>0) - resourceName=@"xhtml1-strict.dtd"; - else if ([whatPart rangeOfString:@"Frameset"].length>0) - resourceName=@"xhtml1-frameset.dtd"; - else - { - NSDebugMLog(@"Unknown DTD: %@. Choose default: xhtml1-transitional.dtd",publicIdEntity); - resourceName=@"xhtml1-transitional.dtd"; // guess - }; - if (resourceName) - { - if ([[resourceName pathExtension] isEqual:@"dtd"]) - resourceName=[resourceName stringByDeletingPathExtension]; - fileName = [[NSBundle bundleForClass: [self class]] - pathForResource:resourceName - ofType:@"dtd" - inDirectory:@"DTDs"]; - NSDebugMLLog(@"GSWTemplateParser",@"systemIdEntity: fileName=%@ for Resource:%@",fileName,publicIdEntity); - if (fileName) - { - externalContent=[NSString stringWithContentsOfFile:fileName]; - }; - }; - } - else if ([whatPart hasPrefix:@"ENTITIES"]) - { - NSString* resourceName=nil; - NSString* fileName=nil; - if ([whatPart rangeOfString:@"Symbols"].length>0) - resourceName=@"xhtml-symbol.ent"; - else if ([whatPart rangeOfString:@"Special"].length>0) - resourceName=@"xhtml-special.ent"; - else if ([whatPart rangeOfString:@"Latin 1"].length>0) - resourceName=@"xhtml-lat1.ent"; - else - { - NSDebugMLog(@"Unknown ENTITIES: %@",publicIdEntity); - }; - if (resourceName) - { - if ([[resourceName pathExtension] isEqual:@"ent"]) - resourceName=[resourceName stringByDeletingPathExtension]; - fileName = [[NSBundle bundleForClass: [self class]] - pathForResource:resourceName - ofType:@"ent" - inDirectory:@"DTDs"]; - NSDebugMLLog(@"GSWTemplateParser",@"systemIdEntity: fileName=%@ for Resource:%@",fileName,publicIdEntity); - if (fileName) - { - externalContent=[NSString stringWithContentsOfFile:fileName]; - }; - }; - } - else - { - NSDebugMLog(@"Unknown publicIdEntity %@",publicIdEntity); - }; - } - else - { - NSDebugMLog(@"Don't know how to parse publicIdEntity %@",publicIdEntity); - }; - } - else - { - NSDebugMLog(@"Don't know what to do with publicIdEntity %@",publicIdEntity); - }; - if (externalContent) - [[self class] setCachedDTDContent:externalContent - forKey:publicIdEntity]; - }; - }; - if (externalContent) - { - result=xmlNewStringInputStream(lib,[externalContent cString]); - }; - NSAssert2(result,@"Can't load external (publicIdEntity:%@ systemIdEntity:%@)",publicIdEntity,systemIdEntity); - NSDebugMLLog(@"GSWTemplateParser",@"LOADED: resolveEntity:%@ systemID:%@ inParserContext:%p\n", - publicIdEntity, - systemIdEntity, - lib); - LOGObjectFnStop(); - return result; -}; - -//-------------------------------------------------------------------- --(void)warning:(NSString*)message - colNumber:(int)colNumber - lineNumber:(int)lineNumber -{ - [[GSWApplication application] logWithFormat:@"%@ Warning (col %d,line %d): %@", - [_templateParser logPrefix], - colNumber, - lineNumber, - message]; -}; - -//-------------------------------------------------------------------- --(void)error: (NSString*)message - colNumber:(int)colNumber - lineNumber:(int)lineNumber -{ - NSString* testMessage=[[message lowercaseString] stringByTrimmingSpaces]; - if (![testMessage isEqualToString:@"tag webobject invalid"] - && ![testMessage isEqualToString:@"tag gsweb invalid"] - && ![testMessage isEqualToString:@"htmlparsestarttag: misplaced tag"] - && ![testMessage isEqualToString:@"htmlparsestarttag: misplaced tag"] - && ![testMessage isEqualToString:@"unexpected end tag : head"]) - { - [[GSWApplication application] logErrorWithFormat:@"%@ Error (line %d,col %d): %@", - [_templateParser logPrefix], - lineNumber, - colNumber, - message]; - }; -}; - -//-------------------------------------------------------------------- --(void)fatalError: (NSString*)message - colNumber:(int)colNumber - lineNumber:(int)lineNumber -{ - [[GSWApplication application] logErrorWithFormat:@"%@ Fatal Error (line %d,col %d): %@", - [_templateParser logPrefix], - lineNumber, - colNumber, - message]; -}; - -@end - -//==================================================================== -@implementation GSWTemplateParserXML - -//-------------------------------------------------------------------- --(void)dealloc -{ - DESTROY(_xmlDocument); - [super dealloc]; -}; - -//-------------------------------------------------------------------- -static NSString* TabsForLevel(int level) -{ - int i=0; - NSMutableString* tabs=[NSMutableString string]; - for (i=0;i0) - _isHTMLTag=YES; - tagRange=[_string rangeOfString:@"0) - _isBodyTag=YES; - parser=[GSHTMLParser parserWithSAXHandler:sax - withData:[_string dataUsingEncoding:stringEncoding]]; - NSDebugMLog(@"_string (%d)=%@",[_string length],_string); - } - else - { - NSData* dataToParse=nil; - NSString* xmlHeader=nil; - //NSRange docTypeRange=NSMakeRange(NSNotFound,0); - NSString* stringToParse=nil; - NSString* encodingString=nil; - encodingString=[GSXMLParser xmlEncodingStringForStringEncoding:stringEncoding]; - if (encodingString) - encodingString=[NSString stringWithFormat:@" encoding=\"%@\"",encodingString]; - else - encodingString=@""; - - stringToParse=_string; - - // Add a null tag around the code because libxml parser doesn't support ....... - stringToParse=[NSString stringWithFormat:@"\n%@\n\n",stringToParse]; - - // Build the header - xmlHeader=[NSString stringWithFormat:@"\n", - @"1.0", - encodingString]; - - /* Don't care about DOCTYPE ! - docTypeRange=[stringToParse rangeOfString:@"\n" - stringByAppendingString:stringToParse]; - */ - stringToParse=[xmlHeader stringByAppendingString:stringToParse]; - NSDebugMLog(@"stringToParse (%d)=%@",[stringToParse length],stringToParse); - dataToParse=[stringToParse dataUsingEncoding:stringEncoding]; - _isHTMLTag=YES; // Don't remove HTML tags in parsed tree - _isBodyTag=YES; // Don't remove BODY tags in parsed tree - parser=[GSXMLParser parserWithSAXHandler:sax - withData:dataToParse]; - [parser keepBlanks:YES]; - }; - [parser doValidityChecking:YES]; - [parser getWarnings:YES]; - //[parser setExternalEntityLoader:GSWTemplateParserSAXHandler_ExternalLoader]; - NS_DURING - { - parseOk=[parser parse]; - } - NS_HANDLER - { - LOGError(@"%@ Exception in parse! Exception: %@", - [self logPrefix], - localException); - localException=ExceptionByAddingUserInfoObjectFrameInfo(localException, - @"%@ - In [parser parse] Exception!", - [self logPrefix]); - [localException retain]; - [localException autorelease]; - [localException raise]; - } - NS_ENDHANDLER; - if (!parseOk) - { - int errNo=[parser errNo]; - // We point out only deep error - switch(errNo) - { - case XML_ERR_NO_DTD: - NSDebugMLLog(@"GSWTemplateParser",@"%@ - Warning: No DTD", - [self logPrefix]); - break; - default: - NSDebugMLLog(@"GSWTemplateParser",@"######Parse FAILED errNo=%d [parser document]=%p", - [parser errNo], - [parser document]); - break; - }; - // May be validity errors only (like no HTML root) - if ([parser document]) - parseOk=YES; - }; - if (parseOk) - { - GSXMLNode* node=nil; - NSDebugMLLog(@"GSWTemplateParser",@"Root"); - ASSIGN(_xmlDocument,[parser document]); - node=[_xmlDocument root]; - NSAssert1(node,@"%@ Empty Document (root)", - [self logPrefix]); -#ifndef NDEBUG - { - NSString* dumpString=[self dumpNode:node - atLevel:0]; - NSDebugMLLog0(@"low",@"Will dump _xmlDocument"); - NSDebugMLLog(@"GSWTemplateParser",@"%@ _xmlDocument=\n%@", - [self logPrefix], - dumpString); - NSDebugMLLog0(@"low",@"_xmlDocument dumped"); - }; -#endif -/* - if ([node type]==XML_DTD_NODE) { - NSLog(@"GSWTemplateParserXML: XML_DTD_NODE is found"); - } - - NSLog(@"ROOT node=%p %@ [Type:%@] [%@] ##%s##\n", - node, - [node name], - [node typeDescription], - [node propertiesAsDictionaryWithKeyTransformationSel:NULL], - [[node content] lossyCString]); -*/ - - /* if (node->type!=XML_DTD_NODE) - { - NSLog(@"Bad first node type: %@ instead of %@", - [nodeTypes objectForKey:[NSString stringWithFormat:@"%d",(int)node->type]], - [nodeTypes objectForKey:[NSString stringWithFormat:@"%d",(int)XML_DTD_NODE]]); - }; - */ -// NSDebugMLLog(@"GSWTemplateParser",@"Test Root"); - if ([node type]!=XML_ELEMENT_NODE) - node=[node firstChild]; -// NSDebugMLLog(@"GSWTemplateParser",@"Test Root children"); - NSAssert1(node,@"%@ Empty Document ([root firstChild])", - [self logPrefix]); - if ([node type]!=XML_ELEMENT_NODE) - node=[node next]; -// NSDebugMLLog(@"GSWTemplateParser",@"Test Root children Next"); - NSAssert1(node,@"%@ Empty Document ([[root firstChild] next])", - [self logPrefix]); - //Remove html and body node when they have been added by html parser - if (!_isHTMLTag || !_isBodyTag) - { - BOOL cont=YES; - while (node && cont) - { - cont=NO; - if ([node type]==XML_ELEMENT_NODE) - { - NSString* nodeName=[node name]; -/* NSDebugMLLog(@"GSWTemplateParser",@"node name=%@",nodeName); - NSDebugMLLog(@"GSWTemplateParser",@"_isHTMLTag=%s _isBodyTag=%s", - (_isHTMLTag ? "YES" : "NO"), - (_isBodyTag ? "YES" : "NO")); -*/ -/* - NSLog(@"while1 node=%p %@ [Type:%@] [%@] ##%s##\n", - node, - [node name], - [node typeDescription], - [node propertiesAsDictionaryWithKeyTransformationSel:NULL], - [[node content] lossyCString]); -*/ - if ((!_isHTMLTag && [nodeName caseInsensitiveCompare:@"html"]==NSOrderedSame) - || (!_isBodyTag && [nodeName caseInsensitiveCompare:@"body"]==NSOrderedSame)) - { -// NSDebugMLLog(@"GSWTemplateParser",@"==> Children"); - node=[node firstChild]; - cont=YES; - }; - }; - }; - }; - if (node) - { - //NSDebugMLLog(@"GSWTemplateParser",@"Call createElementsFromNode:"); - NS_DURING - { - gswebTagN=0; - tagN=0; - elements=[self createElementsFromNode:node]; - // If we've found error raise exception - NSDebugMLog(@"_errorMessages=%@",_errorMessages); - if ([[self errorMessages]count]>0) - { - NSDebugMLog(@"declarationsFilePath=%@",_declarationsFilePath); - ExceptionRaise(@"GSWTemplateParser",@"%@\nDefinitionFiles: %@", - [self errorMessagesAsText], - _processedDeclarationsFilePaths); - }; - } - NS_HANDLER - { - LOGError(@"%@ Exception in elements creation!", - [self logPrefix]); - localException=ExceptionByAddingUserInfoObjectFrameInfo(localException, - @"%@ - Exception in elements creation", - [self logPrefix]); - [localException retain]; - [localException autorelease]; - [localException raise]; - } - NS_ENDHANDLER; - }; - }; - }; - LOGObjectFnStop(); - return elements; -}; - -//-------------------------------------------------------------------- - -/* -text [Type:XML_TEXT_NODE] [{}] #### -head [Type:XML_ELEMENT_NODE] [{}] ##(null)## - title [Type:XML_ELEMENT_NODE] [{}] ##(null)## - text [Type:XML_TEXT_NODE] [{}] ##MyTitle## -text [Type:XML_TEXT_NODE] [{}] #### -body [Type:XML_ELEMENT_NODE] [{bgcolor = white; }] ##(null)## - text [Type:XML_TEXT_NODE] [{}] #### - gsweb [Type:XML_ELEMENT_NODE] [{name = MyObject; }] ##(null)## - text [Type:XML_TEXT_NODE] [{}] ##AText## - p [Type:XML_ELEMENT_NODE] [{align = center; }] ##(null)## - text [Type:XML_TEXT_NODE] [{}] ##Text2## - b [Type:XML_ELEMENT_NODE] [{}] ##(null)## - text [Type:XML_TEXT_NODE] [{}] ##Text3## - text [Type:XML_TEXT_NODE] [{}] #### - text [Type:XML_TEXT_NODE] [{}] ##TEXTB## - comment [Type:XML_COMMENT_NODE] [{}] ##MyComment## - text [Type:XML_TEXT_NODE] [{}] ##TEXTC## -text [Type:XML_TEXT_NODE] [{}] #### -*/ --(NSArray*)createElementsFromNode:(GSXMLNode*)node -{ - GSXMLNode* currentNode=node; - NSMutableArray* _elements=nil; - NSAutoreleasePool* arp = nil; - BOOL includesComment = NO; - LOGObjectFnStart(); - includesComment=[GSWApplication includeCommentsInResponses]; - _elements=[NSMutableArray array]; - arp=[NSAutoreleasePool new]; - GSWLogMemCF("New NSAutoreleasePool: %p",arp); - NS_DURING - { - while(currentNode) - { - GSWElement* elem=nil; - NSDebugMLLog(@"GSWTemplateParser",@"BEGIN node=%p %@ [Type:%@] [%@] ##%s##\n", - currentNode, - [currentNode name], - [currentNode typeDescription], - [currentNode propertiesAsDictionaryWithKeyTransformationSel:NULL], - /* ((xmlNodePtr)[currentNode lib])->content, - [currentNode content],*/ - [[currentNode content] lossyCString]); - - switch([currentNode type]) - { - case XML_TEXT_NODE: - { - NSDebugMLog0(@"TEXT"); - - if ([currentNode content] && ([[currentNode content] length] > 0) ) { - - elem=[GSWHTMLBareString elementWithString: - [NSString stringWithCString: - [[[currentNode content] - stringByConvertingToHTMLEntities] - lossyCString]]];//Because XML Parser decode characters - } else { - elem = nil; - } - - NSDebugMLLog(@"GSWTemplateParser",@"TEXT element=%@",elem); - }; - break; - case XML_CDATA_SECTION_NODE: - { - NSDebugMLog0(@"CDATA_SECTION"); - NSDebugMLLog(@"GSWTemplateParser",@"CDATA_SECTION content=%s",[[currentNode content] lossyCString]); - elem=[GSWHTMLBareString elementWithString:[currentNode content]]; - NSDebugMLLog(@"GSWTemplateParser",@"CDATA_SECTION element=%@",elem); - }; - break; - case XML_COMMENT_NODE: - { - NSDebugMLog0(@"COMMENT"); - if (includesComment) - { - elem=[GSWHTMLBareString elementWithString:[NSString stringWithFormat:@"",[[currentNode content] lossyCString]]]; - NSDebugMLLog(@"GSWTemplateParser",@"COMMENT element=%@",elem); - }; - }; - break; - default: - { - int currentGSWebTagN=0; - int currentTagN=0; - NSArray* children=nil; - NSDictionary* nodeAttributes=nil; - NSString* nodeName=nil; - NSString* nodeNameAttribute=nil; - nodeName=[currentNode name]; - NSDebugMLLog(@"GSWTemplateParser",@"DEFAULT (name=%@ type=%@)",nodeName,[currentNode typeDescription]); - //if (currentNode->type==XML_ELEMENT_NODE) - { - nodeAttributes=[currentNode propertiesAsDictionaryWithKeyTransformationSel:@selector(lowercaseString)]; - nodeNameAttribute=[nodeAttributes objectForKey:@"name"]; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p nodeAttributes=%@",currentNode,nodeAttributes); - NSDebugMLLog(@"GSWTemplateParser",@"node=%p nodeNameAttribute=%@",currentNode,nodeNameAttribute); - tagN++; - if ([nodeName caseInsensitiveCompare:GSWTag_Name[GSWNAMES_INDEX]]==NSOrderedSame - ||[nodeName caseInsensitiveCompare:GSWTag_Name[WONAMES_INDEX]]==NSOrderedSame) - gswebTagN++; - currentGSWebTagN=gswebTagN; - currentTagN=tagN; - if ([currentNode firstChild]) - { - children=[self createElementsFromNode:[currentNode firstChild]]; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p children=%@",currentNode,children); - }; - if ([nodeName caseInsensitiveCompare:GSWTag_Name[GSWNAMES_INDEX]]==NSOrderedSame - ||[nodeName caseInsensitiveCompare:GSWTag_Name[WONAMES_INDEX]]==NSOrderedSame) - { - GSWDeclaration* declaration=nil; - if (!nodeNameAttribute) - { - // allow null name tags - elem=[GSWHTMLStaticGroup elementWithContentElements:children]; - } - else - { - NSDictionary* _associations=nil; - NSString* className=nil; - GSWHTMLStaticGroup* aStaticGroup=nil; - declaration=[_declarations objectForKey:nodeNameAttribute]; - NSDebugMLLog(@"GSWTemplateParser",@"declaration:[%@]", - declaration); - NSDebugMLLog(@"GSWTemplateParser",@"GSWeb Tag declaration:[%@]", - declaration); - if (!declaration) - { - // We don't raise exception know because it's better for developper to collect and report all errors before :-) - [self addErrorMessageFormat:@"No element definition for tag named:%@ [#%d,#%d]", - nodeNameAttribute, - currentGSWebTagN, - currentTagN]; - } - else - { - _associations=[declaration associations]; - className=[declaration type]; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p GSWeb Tag className:[%@]",currentNode,className); - if (!className) - { - // We don't raise exception know because it's better for developper to collect and report all errors before :-) - [self addErrorMessageFormat:@"No class name in page definition for tag named:%@ declaration=%@ [#%d,#%d]", - nodeNameAttribute, - declaration, - currentGSWebTagN, - currentTagN]; - }; - }; - // No class name mean we'll raise an exception after so don't care about this part... - if (className) // - { - NSDebugMLLog(@"GSWTemplateParser",@"node=%p associations:%@",currentNode,_associations); - { - NSEnumerator* _nodeAttributesEnum = [nodeAttributes keyEnumerator]; - id _tagAttrKey=nil; - id _tagAttrValue=nil; - NSMutableDictionary* _addedAssoc=nil; - while ((_tagAttrKey = [_nodeAttributesEnum nextObject])) - { - if (![_tagAttrKey isEqualToString:@"name"] && ![_associations objectForKey:_tagAttrKey]) - { - if (!_addedAssoc) - _addedAssoc=(NSMutableDictionary*)[NSMutableDictionary dictionary]; - _tagAttrValue=[nodeAttributes objectForKey:_tagAttrKey]; - [_addedAssoc setObject:[GSWAssociation associationWithValue:_tagAttrValue] - forKey:_tagAttrKey]; - }; - }; - if (_addedAssoc) - { - _associations=[_associations dictionaryByAddingEntriesFromDictionary:_addedAssoc]; - }; - }; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p gsweb name=%@ dynamicElementWithName: children=%@", - currentNode, - nodeNameAttribute, - children); - NSDebugMLLog(@"GSWTemplateParser",@"node=%p %@ [Type:%@] [%@] ##%s##\n", - currentNode, - [currentNode name], - [currentNode typeDescription], - [currentNode propertiesAsDictionaryWithKeyTransformationSel:NULL], - [[currentNode content] lossyCString]); - aStaticGroup=[[[GSWHTMLStaticGroup alloc]initWithContentElements:children]autorelease]; - elem=[GSWApp dynamicElementWithName:className - associations:_associations - template:aStaticGroup - languages:_languages]; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p element=%@ StaticGroup %p=%@",currentNode,elem,aStaticGroup,aStaticGroup); - if (elem) - [elem setDeclarationName:[declaration name]]; - else - { - // We don't raise exception know because it's better for developper to collect and report all errors before :-) - [self addErrorMessageFormat:@"Creation failed for element named:%@ className:%@", - [declaration name], - className]; - }; - }; - }; - } - else - { - //It's a hack to remove html & body elements where there's not in the template (HTML parser add them when there are missing) - if ((!_isHTMLTag - && [nodeName caseInsensitiveCompare:@"html"]==NSOrderedSame - && [nodeAttributes count]==0) - || (!_isBodyTag - && [nodeName caseInsensitiveCompare:@"body"]==NSOrderedSame - && [nodeAttributes count]==0)) - { - NSDebugMLLog(@"GSWTemplateParser",@"node=%p StaticElement: children=%@",currentNode,children); - elem=[[[GSWHTMLStaticElement alloc]initWithName:nil - attributeDictionary:nil - contentElements:children]autorelease]; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p element=%@",currentNode,elem); - } - else - { - NSDictionary* _associations=nil; - NSEnumerator* _nodeAttributesEnum = [nodeAttributes keyEnumerator]; - id _tagAttrKey=nil; - id _tagAttrValue=nil; - NSMutableDictionary* _addedAssoc=nil; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p Create nodeName=%@ nodeAttributes=%@", - currentNode,nodeName,nodeAttributes); - while ((_tagAttrKey = [_nodeAttributesEnum nextObject])) - { - //Don't remove name for not gsweb tag - //if (![_tagAttrKey isEqualToString:@"name"] && ![_associations objectForKey:_tagAttrKey]) - if (![_associations objectForKey:_tagAttrKey]) - { - if (!_addedAssoc) - _addedAssoc=(NSMutableDictionary*)[NSMutableDictionary dictionary]; - _tagAttrValue=[nodeAttributes objectForKey:_tagAttrKey]; - [_addedAssoc setObject:[GSWAssociation associationWithValue:_tagAttrValue] - forKey:_tagAttrKey]; - }; - }; - if (_addedAssoc) - { - _associations=[NSDictionary dictionaryWithDictionary:_addedAssoc]; - }; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p Create nodeName=%@ nodeAttributes=%@ _associations=%@", - currentNode,nodeName,nodeAttributes,_associations); - //To know if it's an autoclose tag - if (!children && [self isKindOfClass:[GSWTemplateParserXMLHTML class]]) - { - const htmlElemDesc* elemDscr=htmlTagLookup([nodeName lossyCString]); - if (elemDscr - && elemDscr->endTag!=2 //Forbidden End Tag - && elemDscr->endTag!=1) //End can be omitted - { - children=[NSArray array]; - }; - }; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p StaticElement: children=%@",currentNode,children); - elem=[[[GSWHTMLStaticElement alloc]initWithName:nodeName - attributeDictionary:_associations - contentElements:children]autorelease]; - NSDebugMLLog(@"GSWTemplateParser",@"node=%p element=%@",currentNode,elem); - }; - }; - }; - }; - break; - }; - if (elem) - [_elements addObject:elem]; - NSDebugMLLog(@"GSWTemplateParser",@"END node=%p %@ [Type:%@] [%@] ##%s##\n", - currentNode, - [currentNode name], - [currentNode typeDescription], - [currentNode propertiesAsDictionaryWithKeyTransformationSel:NULL], - [[currentNode content] lossyCString]); - currentNode=[currentNode next]; - }; - } - NS_HANDLER - { - LOGError(@"%@ createElementsFromNode: Exception", - [self logPrefix]); - localException=ExceptionByAddingUserInfoObjectFrameInfo(localException, - @"%@ In [GSWTemplateParserXML createElementsFromNode:]...", - [self logPrefix]); - [localException retain]; - GSWLogMemCF("Destroy NSAutoreleasePool: %p",arp); - DESTROY(arp); - [localException autorelease]; - [localException raise]; - } - NS_ENDHANDLER; - GSWLogMemCF("Destroy NSAutoreleasePool: %p",arp); - DESTROY(arp); - LOGObjectFnStop(); - NSDebugMLLog(@"GSWTemplateParser",@"_elements=%@",_elements); - return _elements; -}; - -@end - - -//==================================================================== -// used only for XML/XMLHTML differences -@implementation GSWTemplateParserXMLHTML - -/** call htmlHandleOmittedElem(0) if YES, htmlHandleOmittedElem(1) if NO; **/ --(void)setNoOmittedTags:(BOOL)yn -{ - htmlHandleOmittedElem(yn ? 0 : 1); -}; - -@end - diff --git a/GSWeb.framework/GSWWOCompatibility.h b/GSWeb.framework/GSWWOCompatibility.h index 7357a2c..1a05bac 100644 --- a/GSWeb.framework/GSWWOCompatibility.h +++ b/GSWeb.framework/GSWWOCompatibility.h @@ -75,7 +75,6 @@ #define GSWHTMLStaticGroup WOHTMLStaticGroup #define GSWInput WOInput #define GSWComponentReference WOComponentReference -#define GSWPageDefElement WOPageDefElement #define GSWBundle WOBundle #define GSWSessionTimeOutManager WOSessionTimeOutManager #define GSWServerSessionStore WOServerSessionStore diff --git a/GSWeb.framework/NSObject+IVarAccess+PerformSel.h b/GSWeb.framework/NSObject+IVarAccess+PerformSel.h deleted file mode 100644 index 6d187ec..0000000 --- a/GSWeb.framework/NSObject+IVarAccess+PerformSel.h +++ /dev/null @@ -1,66 +0,0 @@ -/* NSObject+IVarAccess+PerformSel.h - Copyright (C) 1999 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - 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. -*/ - -// $Id$ - -#ifndef _NSObject_IVarAccess_PerformSel_h__ -#define _NSObject_IVarAccess_PerformSel_h__ - -//=================================================================================== -@interface NSObject (IVarsAccess) - -// A class can return YES to disable IVar access Caching -+(BOOL)isIVarAccessCachingDisabled; - -// return function name with template _tpl for an IVar -+(NSString*)getFunctionNameWithTemplate:(NSString*)tpl - forVariable:(NSString*)iVarName - uppercaseFirstLetter:(BOOL)uppercaseFirstLetter; - --(SEL)getSelectorWithFunctionTemplate:(NSString*)tpl - forVariable:(NSString*)iVarName - uppercaseFirstLetter:(BOOL)uppercaseFirstLetter; - --(id)getIVarNamed:(NSString*)iVarName; - --(void)setIVarNamed:(NSString*)iVarName - withValue:(id)value; - --(id)performSelector:(SEL)aSelector - withIntValue:(int)value; - --(id)performSelector:(SEL)aSelector - withFloatValue:(float)value; - --(id)performSelector:(SEL)aSelector - withDoubleValue:(double)value; - --(id)performSelector:(SEL)aSelector - withShortValue:(short)value; - --(id)performSelector:(SEL)aSelector - withUShortValue:(ushort)value; - -@end - -#endif //_NSObject_IVarAccess_PerformSel_h__ diff --git a/GSWeb.framework/NSObject+IVarAccess+PerformSel.m b/GSWeb.framework/NSObject+IVarAccess+PerformSel.m deleted file mode 100644 index 40daf01..0000000 --- a/GSWeb.framework/NSObject+IVarAccess+PerformSel.m +++ /dev/null @@ -1,842 +0,0 @@ -/* NSObject+IVarAccess+PerformSel.m - Copyright (C) 1999 Free Software Foundation, Inc. - - Written by: Manuel Guesdon - 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.h" - -NSMutableDictionary* objectIVarAccessCache_Set=nil; -NSMutableDictionary* objectIVarAccessCache_Get=nil; -NSLock* objectClassLock=nil; - -//=================================================================================== -typedef enum -{ - NSObjectIVarsAccessType_Error = -1, - NSObjectIVarsAccessType_None = 0, - NSObjectIVarsAccessType_PerformSelector, - NSObjectIVarsAccessType_Invocation, - - NSObjectIVarsAccessType_Direct, - - NSObjectIVarsAccessType_Dictionary, - NSObjectIVarsAccessType_DictionaryWithRemoveObject, - NSObjectIVarsAccessType_DictionaryWithoutRemoveObject, - NSObjectIVarsAccessType_EO - -} NSObjectIVarsAccessType; - -//==================================================================== -@interface NSObjectIVarsAccess : NSObject -{ - @public - NSObjectIVarsAccessType accessType; - union - { - SEL selector; - NSInvocation* invocation; - struct objc_ivar* ivar; - } infos; -}; - -+(id)ivarAccess; -@end - -//==================================================================== -@implementation NSObjectIVarsAccess - -//-------------------------------------------------------------------- -+(id)ivarAccess -{ - return [[self new]autorelease]; -}; - -//-------------------------------------------------------------------- --(void)dealloc -{ - if (accessType==NSObjectIVarsAccessType_Invocation) - { - DESTROY(infos.invocation); - }; - [super dealloc]; -}; -@end - -//==================================================================== -struct objc_ivar* GSGetInstanceVariableStruct(id obj, - NSString* iVarName, - BOOL underscored) -{ - const char* name=NULL; - Class class; - struct objc_ivar_list *ivars=NULL; - struct objc_ivar *ivar=NULL; - if (underscored) - iVarName=[NSString stringWithFormat:@"_%@",iVarName]; - name=[iVarName cString]; - class=[obj class]; - while (class && !ivar) - { - ivars = class->ivars; - class = class->super_class; - if (ivars) - { - int i; - for (i=0;!ivar && iivar_count;i++) - { - if (strcmp(ivars->ivar_list[i].ivar_name, name)==0) - ivar = &ivars->ivar_list[i]; - }; - }; - }; - return ivar; -}; - -//-------------------------------------------------------------------- -const char* GSGetInstanceVariableType(id obj, - NSString *iVarName, - BOOL underscored) -{ - struct objc_ivar *ivar = GSGetInstanceVariableStruct(obj,iVarName,underscored); - if (ivar) - return ivar->ivar_type; - else - return NULL; -}; - -//==================================================================== -@implementation NSObject (IVarsAccess) - -//-------------------------------------------------------------------- -+(BOOL)isIVarAccessCachingDisabled -{ - return NO; -}; - -//-------------------------------------------------------------------- -+(NSString*)getFunctionNameWithTemplate:(NSString*)tpl - forVariable:(NSString*)varName - uppercaseFirstLetter:(BOOL)uppercaseFirstLetter -{ - NSString* fn=nil; - if (tpl && [tpl length]>0) - { - NSString* fnMain=nil; - if (uppercaseFirstLetter) - { - NSString* first=[[varName substringToIndex:1] uppercaseString]; - NSString* next=[varName substringFromIndex:1]; - fnMain=[NSString stringWithFormat:@"%@%@",first,next]; - } - else - fnMain=varName; - fn=[NSString stringWithFormat:tpl,fnMain]; - } - else - fn=[NSString stringWithString:varName]; - return fn; -}; - -//-------------------------------------------------------------------- --(SEL)getSelectorWithFunctionTemplate:(NSString*)tpl - forVariable:(NSString*)varName - uppercaseFirstLetter:(BOOL)uppercaseFirstLetter -{ - NSString* fnName=nil; - SEL selector=NULL; - fnName=[NSObject getFunctionNameWithTemplate:tpl - forVariable:varName - uppercaseFirstLetter:uppercaseFirstLetter]; - selector=NSSelectorFromString(fnName); - if (selector && ![self respondsToSelector:selector]) - selector=NULL; - return selector; -}; - -#if HAVE_GDL2 - -//-------------------------------------------------------------------- - -- (id)getIVarNamed:(NSString *)name_ -{ - id value=nil; - SEL sel = @selector(valueForKey:); - - NS_DURING - value = [self valueForKey:name_];//MGNEW - //MGNEW value = (*imp)(self, sel, name_); - NS_HANDLER - { - if([self respondsToSelector:@selector(objectForKey:)] == YES) { - if (name_) { - value = [self objectForKey:name_]; - } else { - value=nil; - } - } else { - LOGException(@"==> %@ (%@) gvfk from string=%p gvfk sel=%p initWithCapacity from string:=%p initWithCapacity sel:=%p NSStringFromSelector(sel)", - localException, - [localException reason], - NSSelectorFromString(@"valueForKey:"), - @selector(valueForKey:), - NSSelectorFromString(@"initWithCapacity:"), - @selector(initWithCapacity:), - NSStringFromSelector(sel)); - [localException raise]; - } - } - NS_ENDHANDLER; - - return value; -} - -//-------------------------------------------------------------------- -- (void)setIVarNamed:(NSString *)name_ - withValue:(id)value_ -{ - SEL sel = @selector(takeValue:forKey:);//NEW NSSelectorFromString(@"takeValue:forKey:"); -//MGNEW id (*imp)(id, SEL, id, id) = (id (*)(id, SEL, id, id))[NSObject instanceMethodForSelector: sel]; - - //NSLog(@"sel (takeValue:forKey: ) : %d", (int)sel); - - NS_DURING - [self takeValue:value_ forKey:name_];//MGNEW - NS_HANDLER - { - if (![name_ isEqualToString:@"self"]) { - - if([self respondsToSelector:@selector(setObject:forKey:)] == YES) { - if (value_ && name_) { - [self setObject:value_ forKey:name_]; - } - } else { - [localException raise]; - } - } - } - NS_ENDHANDLER; -} - -#else - -//-------------------------------------------------------------------- -id PDataToId(const char* retType,void* pdata) -{ - id value=nil; - switch(*retType) - { - case _C_CLASS: - value=*((id*)pdata); - break; - case _C_ID: - value=*((id*)pdata); - break; - case _C_CHR: - value=[NSNumber numberWithChar:*((char*)pdata)]; - break; - case _C_UCHR: - value=[NSNumber numberWithUnsignedChar:*((unsigned char*)pdata)]; - break; - case _C_SHT: - value=[NSNumber numberWithShort:*((short*)pdata)]; - break; - case _C_USHT: - value=[NSNumber numberWithUnsignedShort:*((unsigned short*)pdata)]; - break; - case _C_INT: - value=[NSNumber numberWithInt:*((int*)pdata)]; - break; - case _C_UINT: - value=[NSNumber numberWithUnsignedInt:*((unsigned int*)pdata)]; - break; - case _C_LNG: - value=[NSNumber numberWithLong:*((long*)pdata)]; - break; - case _C_ULNG: - value=[NSNumber numberWithUnsignedLong:*((unsigned long*)pdata)]; - break; - case _C_FLT: - value=[NSNumber numberWithFloat:*((float*)pdata)]; - break; - case _C_DBL: - value=[NSNumber numberWithFloat:*((double*)pdata)]; - break; - case _C_CHARPTR: - value=[NSString stringWithCString:*((char**)pdata)]; - break; - case _C_SEL: - case _C_VOID: - case _C_PTR: - case _C_STRUCT_B: - default: - //TODO - break; - }; - return value; -}; - -//-------------------------------------------------------------------- -void IdToPData(const char* retType,id _value,void* pdata) -{ - switch(*retType) - { - case _C_CLASS: - *((Class*)pdata)=_value; - break; - case _C_ID: - *((id*)pdata)=_value; - break; - case _C_CHR: - *((char*)pdata)=[_value charValue]; - break; - case _C_UCHR: - *((unsigned char*)pdata)=[_value unsignedCharValue]; - break; - case _C_SHT: - *((short*)pdata)=[_value shortValue]; - break; - case _C_USHT: - *((unsigned short*)pdata)=[_value unsignedShortValue]; - break; - case _C_INT: - *((int*)pdata)=[_value intValue]; - break; - case _C_UINT: - *((unsigned int*)pdata)=[_value unsignedIntValue]; - break; - case _C_LNG: - *((long*)pdata)=[_value longValue]; - break; - case _C_ULNG: - *((unsigned long*)pdata)=[_value unsignedLongValue]; - break; - case _C_FLT: - *((float*)pdata)=[_value floatValue]; - break; - case _C_DBL: - *((double*)pdata)=[_value doubleValue]; - break; - case _C_CHARPTR: - case _C_SEL: - case _C_VOID: - case _C_PTR: - case _C_STRUCT_B: - default: - //TODO - break; - }; -}; - -//-------------------------------------------------------------------- --(id)getIVarNamed:(NSString*)name_ - withCacheObject:(NSObjectIVarsAccess*)ivarAccess_ -{ - id _value=nil; - switch(ivarAccess_->accessType) - { - case NSObjectIVarsAccessType_Error: - break; - case NSObjectIVarsAccessType_None: - break; - case NSObjectIVarsAccessType_PerformSelector: - _value=[self performSelector:ivarAccess_->infos.selector]; - break; - case NSObjectIVarsAccessType_Invocation: - { - const char* retType=[[ivarAccess_->infos.invocation methodSignature] methodReturnType]; - NSAssert([ivarAccess_->infos.invocation selector],@"No Selector in Invocation"); - [ivarAccess_->infos.invocation setTarget:self]; - [ivarAccess_->infos.invocation invoke]; - if (*retType!=_C_VOID) - { - void* pdata=objc_atomic_malloc(objc_sizeof_type(retType)); - if (!pdata) - { - NSAssert(pdata,@"No ret value buffer"); - //TODO - } - else - { - [ivarAccess_->infos.invocation getReturnValue:pdata]; - _value=PDataToId(retType,pdata); - objc_free(pdata); - }; - }; - }; - break; - case NSObjectIVarsAccessType_Direct: - { - const char* IVarType=ivarAccess_->infos.ivar->ivar_type; - unsigned int size=objc_sizeof_type(IVarType); - void* pdata=objc_atomic_malloc(size); - if (pdata) - { - int offset = ivarAccess_->infos.ivar->ivar_offset; - memcpy(pdata,((void*)self)+offset, size); - _value=PDataToId(IVarType,pdata); - objc_free(pdata); - } - else - { - //TODO - NSAssert(NO,@"no pdata"); - }; - }; - break; - case NSObjectIVarsAccessType_Dictionary: - _value=[self objectForKey:name_]; - break; - case NSObjectIVarsAccessType_EO: - _value=[self valueForKey:name_]; - break; - default: - break; - }; - return _value; -}; - -//-------------------------------------------------------------------- --(id)getIVarNamed:(NSString*)name_ -{ - id _value=nil; - NSException* _exception=nil; - BOOL _cachindEnabled=YES; - Class _class=Nil; - NSObjectIVarsAccess* _ivarAccess=nil; - NSMutableDictionary* _classCache=nil; - - _class=[self class]; - _classCache=[objectIVarAccessCache_Get objectForKey:_class]; - if (!_classCache) - { - _cachindEnabled=![_class isIVarAccessCachingDisabled]; - if (_cachindEnabled) - { - if (!objectClassLock) - objectClassLock=[NSLock new]; - LoggedLockBeforeDate(objectClassLock, GSW_LOCK_LIMIT); - _classCache=[NSMutableDictionary dictionary]; - if (!objectIVarAccessCache_Get) - objectIVarAccessCache_Get=[NSMutableDictionary new]; - [objectIVarAccessCache_Get setObject:_classCache - forKey:_class]; - LoggedUnlock(objectClassLock); - }; - }; - if (_cachindEnabled) - _ivarAccess=[_classCache objectForKey:name_]; - if (!_ivarAccess) - { - SEL sel=NULL; - _ivarAccess=[NSObjectIVarsAccess ivarAccess]; - sel=[self getSelectorWithFunctionTemplate:@"get%@" - forVariable:name_ - uppercaseFirstLetter:YES]; - if (!sel) - sel=[self getSelectorWithFunctionTemplate:@"%@" - forVariable:name_ - uppercaseFirstLetter:NO]; - if (sel) - { - NSMethodSignature* _sig = [self methodSignatureForSelector:sel]; - if ([_sig numberOfArguments]!=2) - { - _exception =[NSException exceptionWithName: @"NSObject IVar" - format: @"Can't get Variable named " - @"%@ in %@ %p (superClass:%@): " - @"fn args mismatch", - name_, - [self class], - self, - [self superclass]]; - } - else - { - const char* retType=[_sig methodReturnType]; - - if (!retType) - { - _exception=[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't get Variable named " - @"%@ in %@ %p (superClass:%@): " - @"fn unknown type", - name_, - [self class], - self, - [self superclass]]; - } - else - { - if (*retType==_C_ID) - { - _ivarAccess->accessType - = NSObjectIVarsAccessType_PerformSelector; - _ivarAccess->infos.selector=sel; - } - else - { - NSInvocation* _invocation = [NSInvocation invocationWithMethodSignature:_sig]; - [_invocation setSelector:sel]; - _ivarAccess->accessType = NSObjectIVarsAccessType_Invocation; - _ivarAccess->infos.invocation=_invocation; - NSAssert([_ivarAccess->infos.invocation selector], @"No Selector in Invocation"); - [_ivarAccess->infos.invocation retain]; - }; - }; - }; - } - else - { - struct objc_ivar* ivar=GSGetInstanceVariableStruct(self,name_,YES); - if (!ivar) - ivar=GSGetInstanceVariableStruct(self,name_,NO); - if (ivar) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_Direct; - _ivarAccess->infos.ivar=ivar; - } - else - { - if ([self respondsToSelector:@selector(objectForKey:)]) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_Dictionary; - } - else if ([self respondsToSelector:@selector(valueForKey:)]) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_EO; - } - else - { - _exception=[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't get Variable named " - @"%@ in %@ %p (superClass:%@) " - @"with objectForKey", - name_, - [self class], - self, - [self superclass]]; - }; - }; - }; - - if (_exception) - _ivarAccess->accessType=NSObjectIVarsAccessType_Error; - if (_cachindEnabled) - { - if (!objectClassLock) - objectClassLock=[NSLock new]; - LoggedLockBeforeDate(objectClassLock, GSW_LOCK_LIMIT); - [_classCache setObject:_ivarAccess - forKey:name_]; - LoggedUnlock(objectClassLock); - }; - }; - if (_exception) - [_exception raise]; - else - _value=[self getIVarNamed:name_ - withCacheObject:_ivarAccess]; - - return _value; -}; - -//-------------------------------------------------------------------- --(void)setIVarNamed:(NSString*)name_ - withValue:(id)value_ - withCacheObject:(NSObjectIVarsAccess*)ivarAccess_ -{ - switch(ivarAccess_->accessType) - { - case NSObjectIVarsAccessType_Error: - break; - case NSObjectIVarsAccessType_None: - break; - case NSObjectIVarsAccessType_PerformSelector: - - [self performSelector:ivarAccess_->infos.selector - withObject:value_]; - break; - case NSObjectIVarsAccessType_Invocation: - { - const char* type=[[ivarAccess_->infos.invocation methodSignature] getArgumentTypeAtIndex:2]; - void* pdata=objc_atomic_malloc(objc_sizeof_type(type)); - IdToPData(type,value_,pdata); - NSAssert([ivarAccess_->infos.invocation selector],@"No Selector in Invocation"); - [ivarAccess_->infos.invocation setTarget:self]; - [ivarAccess_->infos.invocation setArgument:pdata - atIndex:2]; - - [ivarAccess_->infos.invocation invoke]; - objc_free(pdata); - }; - break; - case NSObjectIVarsAccessType_Direct: - { - const char* IVarType=ivarAccess_->infos.ivar->ivar_type; - if (IVarType) - { - unsigned int size=objc_sizeof_type(IVarType); - void* pdata=objc_atomic_malloc(size); - int offset = ivarAccess_->infos.ivar->ivar_offset; - IdToPData(IVarType,value_,pdata); - memcpy(((void*)self)+offset,pdata, size); - objc_free(pdata); - } - else - { - ExceptionRaise(@"NSObject IVar", - @"Can't set Variable named %@ in %@ %p (superClass:%@)", - name_, - [self class], - self, - [self superclass]); - }; - }; - break; - case NSObjectIVarsAccessType_DictionaryWithRemoveObject: - case NSObjectIVarsAccessType_DictionaryWithoutRemoveObject: - if (value_ || ivarAccess_->accessType==NSObjectIVarsAccessType_DictionaryWithoutRemoveObject) - { - // keyvalue coding - [self setObject:value_ - forKey:name_]; - } - else - { - // keyvalue coding - [self removeObjectForKey:name_]; - }; - break; - case NSObjectIVarsAccessType_EO: - // keyvalue coding - [self takeValue:value_ - forKey:name_]; - break; - default: - break; - }; -}; - -//-------------------------------------------------------------------- --(void)setIVarNamed:(NSString*)name_ - withValue:(id)value_ -{ - NSException* _exception=nil; - BOOL _cachindEnabled=YES; - Class _class=[self class]; - NSObjectIVarsAccess* _ivarAccess=nil; - NSMutableDictionary* _classCache = [objectIVarAccessCache_Set objectForKey:_class]; - - if (!_classCache) - { - _cachindEnabled=![_class isIVarAccessCachingDisabled]; - if (_cachindEnabled) - { - if (!objectClassLock) - objectClassLock=[NSLock new]; - LoggedLockBeforeDate(objectClassLock, GSW_LOCK_LIMIT); - _classCache=[NSMutableDictionary dictionary]; - if (!objectIVarAccessCache_Set) - objectIVarAccessCache_Set=[NSMutableDictionary new]; - [objectIVarAccessCache_Set setObject:_classCache - forKey:_class]; - LoggedUnlock(objectClassLock); - }; - }; - if (_cachindEnabled) - _ivarAccess=[_classCache objectForKey:name_]; - if (!_ivarAccess) - { - SEL sel=NULL; - - _ivarAccess=[NSObjectIVarsAccess ivarAccess]; - sel=[self getSelectorWithFunctionTemplate:@"set%@:" - forVariable:name_ - uppercaseFirstLetter:YES]; - if (sel) - { - NSMethodSignature* _sig = [self methodSignatureForSelector:sel]; - if ([_sig numberOfArguments]!=3) - { - _exception=[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't set Variable named %@ " - @"in %@ %p (superClass:%@) " - @"(fn Bad number of Arguments)", - name_, - [self class], - self, - [self superclass]]; - } - else - { - const char* type=[_sig getArgumentTypeAtIndex:2]; - if (!type) - { - _exception - =[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't set Variable named %@ " - @"in %@ %p (superClass:%@) " - @"(fn get argument type)", - name_, - [self class], - self, - [self superclass]]; - } - else - { - if (*type==_C_ID) - { - _ivarAccess->accessType = NSObjectIVarsAccessType_PerformSelector; - _ivarAccess->infos.selector=sel; - } - else - { - NSInvocation* _invocation = [NSInvocation invocationWithMethodSignature:_sig]; - [_invocation setSelector:sel]; - _ivarAccess->accessType = NSObjectIVarsAccessType_Invocation; - _ivarAccess->infos.invocation=_invocation; - NSAssert([_ivarAccess->infos.invocation selector], @"No Selector in Invocation"); - [_ivarAccess->infos.invocation retain]; - }; - }; - }; - } - else - { - struct objc_ivar* ivar=GSGetInstanceVariableStruct(self,name_,YES); - if (!ivar) - ivar=GSGetInstanceVariableStruct(self,name_,NO); - if (ivar) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_Direct; - _ivarAccess->infos.ivar=ivar; - } - else - { - BOOL _respondsToSetObject=NO; - BOOL _respondsToRemoveObject=NO; - _respondsToSetObject = [self respondsToSelector:@selector(setObject:forKey:)]; - _respondsToRemoveObject = [self respondsToSelector:@selector(removeObjectForKey:)]; - if (_respondsToSetObject) - { - if (_respondsToRemoveObject) - _ivarAccess->accessType - = NSObjectIVarsAccessType_DictionaryWithRemoveObject; - else - _ivarAccess->accessType - = NSObjectIVarsAccessType_DictionaryWithoutRemoveObject; - } - else - { - BOOL _respondsToTakeValue - = [self respondsToSelector:@selector(takeValue:forKey:)]; - if (_respondsToTakeValue) - _ivarAccess->accessType=NSObjectIVarsAccessType_EO; - else - { - _exception - = [NSException exceptionWithName:@"NSObject IVar" - format:@"Can't set Variable named %@ " - @"in %@ %p (superClass:%@) value=%@", - name_, - [self class], - self, - [self superclass], - value_]; - }; - }; - }; - }; - - if (_exception) - _ivarAccess->accessType=NSObjectIVarsAccessType_Error; - if (_cachindEnabled) - { - if (!objectClassLock) - objectClassLock=[NSLock new]; - LoggedLockBeforeDate(objectClassLock, GSW_LOCK_LIMIT); - [_classCache setObject:_ivarAccess - forKey:name_]; - LoggedUnlock(objectClassLock); - }; - }; - if (_exception) - [_exception raise]; - else - [self setIVarNamed:name_ - withValue:value_ - withCacheObject:_ivarAccess]; -}; -#endif - - - -//-------------------------------------------------------------------- -#define PERFORM_SELECTOR_WITH_XX_VALUE \ - id retValue=nil; \ - NSMethodSignature* methodSignature=[NSObject methodSignatureForSelector:_selector]; \ - const char* retType=[methodSignature methodReturnType]; \ - NSInvocation* invocation= [NSInvocation invocationWithMethodSignature:methodSignature]; \ - [invocation setTarget:self]; \ - [invocation setSelector:_selector]; \ - [invocation setArgument:&_value atIndex:2]; \ - [invocation invoke]; \ - if (retType && *retType==_C_ID) \ - [invocation getReturnValue:&retValue]; \ - return retValue; - -//-------------------------------------------------------------------- --(id)performSelector:(SEL)_selector - withIntValue:(int)_value -{ - PERFORM_SELECTOR_WITH_XX_VALUE -}; - -//-------------------------------------------------------------------- --(id)performSelector:(SEL)_selector - withFloatValue:(float)_value -{ - PERFORM_SELECTOR_WITH_XX_VALUE -}; - -//-------------------------------------------------------------------- --(id)performSelector:(SEL)_selector - withDoubleValue:(double)_value -{ - PERFORM_SELECTOR_WITH_XX_VALUE -}; -//-------------------------------------------------------------------- --(id)performSelector:(SEL)_selector - withShortValue:(short)_value -{ - PERFORM_SELECTOR_WITH_XX_VALUE -}; -//-------------------------------------------------------------------- --(id)performSelector:(SEL)_selector - withUShortValue:(ushort)_value -{ - PERFORM_SELECTOR_WITH_XX_VALUE -}; - -@end -