2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "DOMNodeWalker.h"
26 @interface NGDOMNodeWalker(Privates)
27 - (void)_processCurrentNode;
30 @implementation NGDOMNodeWalker
32 - (id)initWithTarget:(id)_target selector:(SEL)_selector context:(id)_ctx {
33 self->target = [_target retain];
34 self->selector = _selector;
35 self->ctx = [_ctx retain];
37 if (self->target == nil) {
41 if (self->selector == NULL) {
50 [self->rootNode release];
51 [self->target release];
62 return self->rootNode;
64 - (id)currentParentNode {
65 return self->currentParentNode;
68 return self->currentNode;
73 - (void)_processCurrentNode {
74 [self->target performSelector:self->selector withObject:self];
77 - (void)_beforeChildren {
79 - (void)_afterChildren {
82 - (void)_walkNodeUsingChildNodes:(id)_node {
83 if (self->isStopped) return;
85 self->currentNode = _node;
87 [self _beforeChildren];
88 if (self->isStopped) return;
90 if ([_node hasChildNodes]) {
95 oldParent = self->currentParentNode;
96 self->currentParentNode = self->currentNode;
98 children = [_node childNodes];
100 for (i = 0, count = [children count]; i < count; i++) {
101 [self _walkNodeUsingChildNodes:[children objectAtIndex:i]];
102 if (self->isStopped) return;
105 self->currentParentNode = oldParent;
108 [self _afterChildren];
109 if (self->isStopped) return;
114 - (void)walkNode:(id)_node {
115 self->rootNode = [_node retain];
116 self->isStopped = NO;
117 self->currentParentNode = nil;
119 [self _walkNodeUsingChildNodes:_node];
121 [self->rootNode release]; self->rootNode = nil;
124 - (void)stopWalking {
125 self->isStopped = YES;
128 @end /* NGDOMNodeWalker */
130 @implementation NGDOMNodePreorderWalker
132 - (void)_beforeChildren {
133 [self _processCurrentNode];
135 - (void)_afterChildren {
138 @end /* NGDOMNodePreorderWalker */
140 @implementation NGDOMNodePostorderWalker
142 - (void)_beforeChildren {
144 - (void)_afterChildren {
145 [self _processCurrentNode];
148 @end /* NGDOMNodePreorderWalker */