From: znek Date: Wed, 28 Feb 2007 07:09:04 +0000 (+0000) Subject: Improved WORepetition's implementation to be more convenient in regards to the 'list... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b422e091df6fe1930595aa628ef6ee7f196f335;p=sope Improved WORepetition's implementation to be more convenient in regards to the 'list' binding. git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1446 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 786b3c71..b6e99af4 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,10 @@ +2007-02-27 Marcus Mueller + + * WORepetition.m: minor code cleanup. Extended the 'list' binding + so that it's possible now to bind any object as a list - this helps + in cases where provided objects are either arrays or ordinary + objects. (v4.7.267) + 2007-02-08 Helge Hess * v4.5.266 diff --git a/sope-appserver/NGObjWeb/DynamicElements/WORepetition.m b/sope-appserver/NGObjWeb/DynamicElements/WORepetition.m index 31262078..e7e1ba6d 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WORepetition.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WORepetition.m @@ -137,6 +137,8 @@ static inline Class _classForConfig(NSDictionary *_config) { @implementation WORepetition +static Class NSArrayClass = Nil; + + (int)version { return [super version] + 1 /* v3 */; } @@ -145,6 +147,8 @@ static inline Class _classForConfig(NSDictionary *_config) { @"invalid superclass (%@) version %i !", NSStringFromClass([self superclass]), [super version]); + NSArrayClass = [NSArray class]; + if (debugTakeValues == -1) { debugTakeValues = [[NSUserDefaults standardUserDefaults] boolForKey:@"WODebugTakeValues"] @@ -257,6 +261,8 @@ _applyIdentifier(_WOComplexRepetition *self, #endif array = [self->list valueInComponent:sComponent]; + if ((array != nil) && ![array isKindOfClass:NSArrayClass]) + array = [NSArray arrayWithObject:array]; count = [array count]; if (count > 0) { @@ -297,7 +303,9 @@ _applyIndex(_WOComplexRepetition *self, WOComponent *sComponent, unsigned _idx) NSArray *array; array = [self->list valueInComponent:sComponent]; - + if ((array != nil) && ![array isKindOfClass:NSArrayClass]) + array = [NSArray arrayWithObject:array]; + if (self->index) [self->index setUnsignedIntValue:_idx inComponent:sComponent]; @@ -332,6 +340,8 @@ _applyIndex(_WOComplexRepetition *self, WOComponent *sComponent, unsigned _idx) sComponent = [_ctx component]; array = [self->list valueInContext:_ctx]; + if ((array != nil) && ![array isKindOfClass:NSArrayClass]) + array = [NSArray arrayWithObject:array]; aCount = [array count]; goCount = self->count @@ -463,26 +473,25 @@ _applyIndex(_WOComplexRepetition *self, WOComponent *sComponent, unsigned _idx) } - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { - static Class NSAutoreleasePoolClass = Nil; - WOComponent *sComponent; - NSArray *array; - unsigned aCount, goCount, startIdx; NSAutoreleasePool *pool; + WOComponent *sComponent; + NSArray *array; + unsigned aCount, goCount, startIdx; #if DEBUG if (descriptiveIDs) [_ctx appendElementIDComponent:self->repName]; #endif - if (NSAutoreleasePoolClass == Nil) - NSAutoreleasePoolClass = [NSAutoreleasePool class]; - - pool = [[NSAutoreleasePoolClass alloc] init]; + pool = [[NSAutoreleasePool alloc] init]; sComponent = [_ctx component]; - array = [self->list valueInContext:_ctx]; - aCount = [array count]; - startIdx = [self->startIndex unsignedIntValueInComponent:sComponent]; + array = [self->list valueInContext:_ctx]; + if ((array != nil) && ![array isKindOfClass:NSArrayClass]) + array = [NSArray arrayWithObject:array]; + + aCount = [array count]; + startIdx = [self->startIndex unsignedIntValueInComponent:sComponent]; goCount = self->count ? [self->count unsignedIntValueInComponent:sComponent] @@ -772,25 +781,23 @@ _sapplyIndex(_WOSimpleRepetition *self, WOComponent *sComponent, NSArray *array, } - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { - static Class NSAutoreleasePoolClass = Nil; - WOComponent *sComponent; - NSArray *array; - unsigned aCount; NSAutoreleasePool *pool; + WOComponent *sComponent; + NSArray *array; + unsigned aCount; #if DEBUG if (descriptiveIDs) [_ctx appendElementIDComponent:self->repName]; #endif - if (NSAutoreleasePoolClass == Nil) - NSAutoreleasePoolClass = [NSAutoreleasePool class]; - - pool = [[NSAutoreleasePoolClass alloc] init]; + pool = [[NSAutoreleasePool alloc] init]; sComponent = [_ctx component]; - array = [self->list valueInContext:_ctx]; - aCount = [array count]; + array = [self->list valueInContext:_ctx]; + if ((array != nil) && ![array isKindOfClass:NSArrayClass]) + array = [NSArray arrayWithObject:array]; + aCount = [array count]; if (aCount > 0) { unsigned cnt; @@ -811,7 +818,7 @@ _sapplyIndex(_WOSimpleRepetition *self, WOComponent *sComponent, NSArray *array, inComponent:sComponent]; } else { - [_ctx pushCursor:[array objectAtIndex:cnt]]; + [_ctx pushCursor:[array objectAtIndex:cnt]]; } #if HTML_DEBUG @@ -829,7 +836,7 @@ _sapplyIndex(_WOSimpleRepetition *self, WOComponent *sComponent, NSArray *array, [_ctx incrementLastElementIDComponent]; if (self->item == nil) - [_ctx popCursor]; + [_ctx popCursor]; } [_ctx deleteLastElementIDComponent]; /* repetition index */ diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 2a92e8b6..a04cfbe7 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,7 +1,7 @@ # version file ifneq ($(GNUSTEP_HOST_VENDOR),apple) # linker overflow -SUBMINOR_VERSION:=266 +SUBMINOR_VERSION:=267 else SUBMINOR_VERSION:=255 endif