~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-xml/DOM/DOMNodeWalker.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2000-2005 SKYRIX Software AG
 
3
 
 
4
  This file is part of SOPE.
 
5
 
 
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
 
9
  later version.
 
10
 
 
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.
 
15
 
 
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
 
19
  02111-1307, USA.
 
20
*/
 
21
 
 
22
#include "DOMNodeWalker.h"
 
23
#include "DOMNode.h"
 
24
#include "common.h"
 
25
 
 
26
@interface DOMNodeWalker(Privates)
 
27
- (void)_processCurrentNode;
 
28
@end
 
29
 
 
30
@implementation DOMNodeWalker
 
31
 
 
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];
 
36
 
 
37
  if (self->target == nil) {
 
38
    [self release];
 
39
    return nil;
 
40
  }
 
41
  if (self->selector == NULL) {
 
42
    [self release];
 
43
    return nil;
 
44
  }
 
45
  
 
46
  return self;
 
47
}
 
48
- (void)dealloc {
 
49
  [self->ctx      release];
 
50
  [self->rootNode release];
 
51
  [self->target   release];
 
52
  [super dealloc];
 
53
}
 
54
 
 
55
/* accessors */
 
56
 
 
57
- (id)context {
 
58
  return self->ctx;
 
59
}
 
60
 
 
61
- (id)rootNode {
 
62
  return self->rootNode;
 
63
}
 
64
- (id)currentParentNode {
 
65
  return self->currentParentNode;
 
66
}
 
67
- (id)currentNode {
 
68
  return self->currentNode;
 
69
}
 
70
 
 
71
/* private */
 
72
 
 
73
- (void)_processCurrentNode {
 
74
  [self->target performSelector:self->selector withObject:self];
 
75
}
 
76
 
 
77
- (void)_beforeChildren {
 
78
}
 
79
- (void)_afterChildren {
 
80
}
 
81
 
 
82
- (void)_walkNodeUsingChildNodes:(id)_node {
 
83
  if (self->isStopped) return;
 
84
  
 
85
  self->currentNode = _node;
 
86
  
 
87
  [self _beforeChildren];
 
88
  if (self->isStopped) return;
 
89
 
 
90
  if ([_node hasChildNodes]) {
 
91
    id       children;
 
92
    unsigned i, count;
 
93
    id oldParent;
 
94
 
 
95
    oldParent = self->currentParentNode;
 
96
    self->currentParentNode = self->currentNode;
 
97
    
 
98
    children = [_node childNodes];
 
99
    
 
100
    for (i = 0, count = [children count]; i < count; i++) {
 
101
      [self _walkNodeUsingChildNodes:[children objectAtIndex:i]];
 
102
      if (self->isStopped) return;
 
103
    }
 
104
    
 
105
    self->currentParentNode = oldParent;
 
106
  }
 
107
 
 
108
  [self _afterChildren];
 
109
  if (self->isStopped) return;
 
110
}
 
111
 
 
112
/* public */
 
113
 
 
114
- (void)walkNode:(id)_node {
 
115
  self->rootNode  = [_node retain];
 
116
  self->isStopped = NO;
 
117
  self->currentParentNode = nil;
 
118
  
 
119
  [self _walkNodeUsingChildNodes:_node];
 
120
 
 
121
  [self->rootNode release]; self->rootNode = nil;
 
122
}
 
123
 
 
124
- (void)stopWalking {
 
125
  self->isStopped = YES;
 
126
}
 
127
 
 
128
@end /* DOMNodeWalker */
 
129
 
 
130
@implementation DOMNodePreorderWalker
 
131
 
 
132
- (void)_beforeChildren {
 
133
  [self _processCurrentNode];
 
134
}
 
135
- (void)_afterChildren {
 
136
}
 
137
 
 
138
@end /* DOMNodePreorderWalker */
 
139
 
 
140
@implementation DOMNodePostorderWalker
 
141
 
 
142
- (void)_beforeChildren {
 
143
}
 
144
- (void)_afterChildren {
 
145
  [self _processCurrentNode];
 
146
}
 
147
 
 
148
@end /* DOMNodePreorderWalker */