From 3f43e4a9c32dff73e91d07448a4429f16af5c7f5 Mon Sep 17 00:00:00 2001 From: dwetzel Date: Fri, 13 Apr 2007 18:46:41 +0000 Subject: [PATCH] added git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@25030 72102866-910b-0410-8b05-ffd578937521 --- GSWeb.framework/GSWDynamicGroup.h | 61 ++++++++ GSWeb.framework/GSWDynamicGroup.m | 251 ++++++++++++++++++++++++++++++ 2 files changed, 312 insertions(+) create mode 100644 GSWeb.framework/GSWDynamicGroup.h create mode 100644 GSWeb.framework/GSWDynamicGroup.m diff --git a/GSWeb.framework/GSWDynamicGroup.h b/GSWeb.framework/GSWDynamicGroup.h new file mode 100644 index 0000000..b0ed13c --- /dev/null +++ b/GSWeb.framework/GSWDynamicGroup.h @@ -0,0 +1,61 @@ +/** GSWHyperlink.h - GSWeb: Class GSWHyperlink + + Copyright (C) 2005-2006 Free Software Foundation, Inc. + + Written by: David Wetzel + Date: Dec 2005 + + $Revision: 1.17 $ + $Date: 2004/12/31 14:33:16 $ + + 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: GSWHyperlink.h,v 1.9 2005/04/24 11:56:45 mguesdon Exp $ + +#ifndef _GSWDynamicGroup_h__ + #define _GSWDynamicGroup_h__ + + +@interface GSWDynamicGroup: GSWDynamicElement +{ + NSMutableArray * _children; +} + + +-(id)initWithName:(NSString*)name + associations:(NSDictionary*)associations + template:(GSWElement*)template; + + +-(id)initWithName:(NSString*) name + associations:(NSDictionary*) associations + contentElements:(NSMutableArray*) children; + +-(NSMutableArray*) childrenElements; + +- (BOOL) hasChildrenElements; + +-(void) appendChildrenToResponse:(GSWResponse*) response + inContext:(GSWContext*)aContext; + +@end + +#endif //_GSWDynamicGroup_h__ + diff --git a/GSWeb.framework/GSWDynamicGroup.m b/GSWeb.framework/GSWDynamicGroup.m new file mode 100644 index 0000000..cc927b1 --- /dev/null +++ b/GSWeb.framework/GSWDynamicGroup.m @@ -0,0 +1,251 @@ +/** GSWDynamicGroup.m - GSWeb: Class GSWDynamicGroup + + Copyright (C) 2005-2006 Free Software Foundation, Inc. + + Written by: David Wetzel + Date: Dec 2005 + + $Revision: 1.17 $ + $Date: 2004/12/31 14:33:16 $ + + 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: GSWDynamicGroup.m,v 1.17 2004/12/31 14:33:16 mguesdon Exp $") + +#include "GSWeb.h" + +static Class GSWHTMLBareStringClass = Nil; + +//==================================================================== +@implementation GSWDynamicGroup + ++ (void) initialize +{ + if (self == [GSWDynamicGroup class]) + { + GSWHTMLBareStringClass = [GSWHTMLBareString class]; + }; +}; + + ++ (GSWDynamicGroup*) emptyGroup +{ + GSWDynamicGroup * theGroup = [GSWDynamicGroup alloc]; + + theGroup = [theGroup initWithName:nil + associations:nil + template:nil]; + + return AUTORELEASE(theGroup); +} + + +-(NSMutableArray*) childrenElements +{ + return _children; +} + +- (void) _initChildrenFromTemplate:(GSWElement*) element +{ + NSMutableArray * array = nil; + if (element) { + + // [element isKindOfClass:[GSWDynamicGroup class]] + if ([element isKindOfClass:[GSWHTMLStaticGroup class]]) { + array = [(GSWDynamicGroup*) element childrenElements]; +//NSLog(@"%s element is %@ array is %@", __PRETTY_FUNCTION__, element, array); + } + // normally, this should be called only if the above isKindOfClass is NO. + // BUT some elements seem be parsed wrong/different than in WO. + if (array == nil) { + array = [NSMutableArray array]; + [array addObject:element]; + } + } + DESTROY(_children); + if ((array) && ([array count] > 0)) { + ASSIGN(_children,array); + } +} + + +-(id)initWithName:(NSString*)name + associations:(NSDictionary*)associations + template:(GSWElement*)template +{ + id ourid = [super initWithName:nil + associations:nil + template:nil]; + + if (! ourid) { + [self release]; + return nil; + } + + [ourid _initChildrenFromTemplate:template]; + + return ourid; +} + +// YES it is called like that +// initWithName:associations:contentElements +// NOT initWithName: attributeAssociations: contentElements: + +-(id)initWithName:(NSString*)name + associations:(NSDictionary*)associations + contentElements:(NSMutableArray*) children +{ + id ourid = [super initWithName:nil + associations:nil + template:nil]; + + DESTROY(_children); + + if (! ourid) { + [self release]; + return nil; + } + + if ((children) && ([children count] > 0)) { + ASSIGN(_children, children); + } + return ourid; +} + +-(void) dealloc +{ + DESTROY(_children); + + [super dealloc]; +} + +-(void) addChildElement:(id) element +{ + if (_children == nil) { + _children = [NSMutableArray new]; + } + [_children addObject:element]; +} + +- (BOOL) hasChildrenElements +{ + return ((_children != nil) && ([_children count] > 0)); +} + +-(void) takeChildrenValuesFromRequest:(GSWRequest*)request + inContext:(GSWContext*)aContext +{ + if ([self hasChildrenElements]) { + int i = [_children count]; + int j = 0; + + [aContext appendZeroElementIDComponent]; + + for (; j < i; j++) { + GSWElement * element = [_children objectAtIndex:j]; + [element takeValuesFromRequest: request + inContext: aContext]; + [aContext incrementLastElementIDComponent]; + } + + [aContext deleteLastElementIDComponent]; + } +} + +-(void) takeValuesFromRequest:(GSWRequest*)request + inContext:(GSWContext*)aContext + +{ + [self takeChildrenValuesFromRequest:request + inContext:aContext]; +} + +-(id ) invokeChildrenAction:(GSWRequest*)request + inContext:(GSWContext*)aContext + +{ + id actionresults = nil; + if ([self hasChildrenElements]) { + int kidsCount = [_children count]; + int j = 0; + + [aContext appendZeroElementIDComponent]; + + for (; (j < kidsCount) && (actionresults == nil); j++) { + GSWElement * element = [_children objectAtIndex:j]; + if ([element class] != GSWHTMLBareStringClass) { + + actionresults = [element invokeActionForRequest: request + inContext: aContext]; + } + [aContext incrementLastElementIDComponent]; + } + [aContext deleteLastElementIDComponent]; + } + return actionresults; +} + +-(id ) invokeActionForRequest:(GSWRequest*)request + inContext:(GSWContext*)aContext +{ + return [self invokeChildrenAction:request + inContext:aContext]; +} + +-(void) appendChildrenToResponse:(GSWResponse*) response + inContext:(GSWContext*)aContext +{ + if ([self hasChildrenElements]) { + int kidsCount = [_children count]; + int j = 0; + + [aContext appendZeroElementIDComponent]; + + for (; j < kidsCount; j++) { + GSWElement * element = [_children objectAtIndex:j]; + [element appendToResponse: response + inContext: aContext]; + + [aContext incrementLastElementIDComponent]; + } + [aContext deleteLastElementIDComponent]; + } +} + +-(void) appendToResponse:(GSWResponse*) response + inContext:(GSWContext*)aContext +{ + [self appendChildrenToResponse: response + inContext: aContext]; +} + +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p children:%@>", + object_get_class_name(self), + (void*)self, + _children]; +}; + + +@end