Skip to content

Commit

Permalink
Merge pull request #6510 from vishalduggal/timob-18215-t2-35X
Browse files Browse the repository at this point in the history
CR and FT passed.
  • Loading branch information
cheekiatng committed Dec 19, 2014
2 parents 43f05db + da42878 commit 67d5163
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 61 deletions.
34 changes: 13 additions & 21 deletions iphone/Classes/TiDOMElementProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,12 @@ -(id)insertBefore:(id)args
if (newNodePtr == refNodePtr)
return newChild;

TiDOMNodeListProxy* nodeList = [self childNodes];
[[self node]releaseCachedValues];
NSArray* theChildren = [[self node] children];


TiDOMNodeProxy* cur= nil;
int max = [TiUtils intValue:[nodeList length]];
BOOL found = NO;
for (int i=0; i<max && !found; i++) {
cur = (TiDOMNodeProxy*)[nodeList item:[NSNumber numberWithInt:i]];
if ([[cur node]XMLNode] == refNodePtr) {
for (GDataXMLNode* cur in theChildren) {
if ([cur XMLNode] == refNodePtr) {
found = YES;
}
}
Expand Down Expand Up @@ -625,15 +622,12 @@ -(id)replaceChild:(id)args
if (newNodePtr == refNodePtr)
return refChild;

TiDOMNodeListProxy* nodeList = [self childNodes];


TiDOMNodeProxy* cur= nil;
int max = [TiUtils intValue:[nodeList length]];
[[self node]releaseCachedValues];
NSArray* theChildren = [[self node] children];

BOOL found = NO;
for (int i=0; i<max && !found; i++) {
cur = (TiDOMNodeProxy*)[nodeList item:[NSNumber numberWithInt:i]];
if ([[cur node]XMLNode] == refNodePtr) {
for (GDataXMLNode* cur in theChildren) {
if ([cur XMLNode] == refNodePtr) {
found = YES;
}
}
Expand Down Expand Up @@ -677,13 +671,11 @@ -(id)removeChild:(id)args

xmlNodePtr refNodePtr = [[oldChild node]XMLNode];

TiDOMNodeListProxy* nodeList = [self childNodes];
TiDOMNodeProxy*cur = nil;
int max = [TiUtils intValue:[nodeList length]];
[[self node]releaseCachedValues];
NSArray* theChildren = [[self node] children];
BOOL found = NO;
for (int i=0; i<max && !found; i++) {
cur = (TiDOMNodeProxy*)[nodeList item:[NSNumber numberWithInt:i]];
if ([[cur node]XMLNode] == refNodePtr) {
for (GDataXMLNode* cur in theChildren) {
if ([cur XMLNode] == refNodePtr) {
found = YES;
}
}
Expand Down
6 changes: 3 additions & 3 deletions iphone/Classes/TiDOMNodeListProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
@interface TiDOMNodeListProxy : TiProxy {
@private
NSArray *nodes;
GDataXMLDocument* document;
}

@property(nonatomic,readonly) NSNumber *length;
-(void)setNodes:(NSArray*)nodes_;
-(id)item:(id)args;
-(NSNumber*)length;


-(id)_initWithPageContext:(id<TiEvaluator>)context nodes:(NSArray*)nodeList document:(GDataXMLDocument*)theDocument;

@end

#endif
#endif
45 changes: 20 additions & 25 deletions iphone/Classes/TiDOMNodeListProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@

@implementation TiDOMNodeListProxy

-(id)_initWithPageContext:(id<TiEvaluator>)context nodes:(NSArray*)nodeList document:(GDataXMLDocument*)theDocument;
{
if (self = [super _initWithPageContext:context]) {
nodes = [nodeList retain];
document = [theDocument retain];
}
return self;
}

-(void)dealloc
{
[nodes release];
[document release];
[super dealloc];
}

Expand All @@ -23,34 +33,19 @@ -(NSString*)apiName
return @"Ti.XML.NodeList";
}

-(void)setNodes:(NSArray*)nodes_
{
if (nodes == nodes_) {
return;
}
for (TiDOMNodeProxy *node in nodes) {
if (![nodes_ containsObject:node]) {
[self forgetProxy:node];
}
}
[nodes release];
nodes = [nodes_ retain];
for (TiDOMNodeProxy *node in nodes) {
[[self pageContext] registerProxy:node];
[self rememberProxy:node];
}
}

-(id)item:(id)args
{
ENSURE_SINGLE_ARG(args,NSObject);
int index = [TiUtils intValue:args];
ENSURE_SINGLE_ARG(args,NSObject);
int index = [TiUtils intValue:args];

if ( (index < [nodes count]) && (index >=0) )
{
return [nodes objectAtIndex:index];
}
return [NSNull null];
if ( (index < [nodes count]) && (index >=0) ) {
GDataXMLNode* theNode = [nodes objectAtIndex:index];
id context = ([self executionContext]==nil)?[self pageContext]:[self executionContext];
id nodeProxy = [TiDOMNodeProxy makeNode:theNode context:context];
[(TiDOMNodeProxy*)nodeProxy setDocument:document];
return nodeProxy;
}
return [NSNull null];
}

-(NSNumber*)length
Expand Down
13 changes: 1 addition & 12 deletions iphone/Classes/TiDOMNodeProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,7 @@ +(void)removeNodeForXMLNode:(xmlNodePtr)nodePtr

-(id)makeNodeListProxyFromArray:(NSArray*)nodes context:(id<TiEvaluator>)context
{
NSMutableArray *proxyArray = nil;
if (nodes != nil) {
proxyArray = [NSMutableArray array];
for (GDataXMLNode* child in nodes) {
[proxyArray addObject:[self makeNode:child context:context]];
}
}

TiDOMNodeListProxy *proxy = [[[TiDOMNodeListProxy alloc] _initWithPageContext:context] autorelease];
[proxy setNodes:proxyArray];
return proxy;

return [[[TiDOMNodeListProxy alloc] _initWithPageContext:context nodes:nodes document:[self document]] autorelease];
}

+(void)validateAttributeParameters:(NSString*)tagName withUri:(NSString*)theURI reason:(NSString**)error subreason:(NSString**)suberror
Expand Down

0 comments on commit 67d5163

Please sign in to comment.