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 "DOMNode+EOQualifier.h"
23 #include <EOControl/EOQualifier.h>
26 @interface NSObject(DOMNodeEOQualifier)
27 - (NSArray *)_domChildrenMatchingQualifier:(EOQualifier *)_qualifier;
28 - (NSArray *)_domDescendantsMatchingQualifier:(EOQualifier *)_qualifier
29 includeSelf:(BOOL)_includeSelf;
32 @implementation NSObject(DOMNodeEOQualifier)
33 /* this category is used to support DOM ops on any object */
35 static NSArray *emptyArray = nil;
37 - (NSArray *)_domChildrenMatchingQualifier:(EOQualifier *)_qualifier {
41 if (![(id<DOMNode>)self hasChildNodes])
44 if ((children = [(id<DOMNode>)self childNodes]) == nil)
47 if ((count = [children count]) == 0) {
48 if (emptyArray == nil) emptyArray = [[NSArray alloc] init];
52 NSMutableArray *marray;
55 marray = [NSMutableArray arrayWithCapacity:(count + 1)];
57 for (i = 0; i < count; i++) {
60 if ((childNode = [children objectAtIndex:i])) {
61 if ((_qualifier == nil) ||
62 [(id<EOQualifierEvaluation>)_qualifier evaluateWithObject:childNode])
63 [marray addObject:childNode];
67 return [[marray copy] autorelease];
71 - (void)_addDOMDescendantsMatchingQualifier:(EOQualifier *)_qualifier
72 toMutableArray:(NSMutableArray *)_array
73 includeSelf:(BOOL)_includeSelf
79 if ([(id<EOQualifierEvaluation>)_qualifier evaluateWithObject:self])
80 [_array addObject:self];
83 if (![(id<DOMNode>)self hasChildNodes])
86 children = [(id<DOMNode>)self childNodes];
87 for (i = 0, count = [children count]; i < count; i++) {
88 [[children objectAtIndex:i]
89 _addDOMDescendantsMatchingQualifier:_qualifier
94 - (NSArray *)_domDescendantsMatchingQualifier:(EOQualifier *)_qualifier
95 includeSelf:(BOOL)_includeSelf
97 NSMutableArray *marray;
99 marray = [NSMutableArray arrayWithCapacity:16];
101 [self _addDOMDescendantsMatchingQualifier:_qualifier
102 toMutableArray:marray
103 includeSelf:_includeSelf];
105 return [[marray copy] autorelease];
108 @end /* NSObject(DOMNodeEOQualifier) */
110 @implementation NGDOMNode(EOQualifier)
112 - (NSArray *)childrenMatchingQualifier:(EOQualifier *)_qualifier {
113 return [self _domChildrenMatchingQualifier:_qualifier];
116 - (NSArray *)descendantsMatchingQualifier:(EOQualifier *)_qualifier {
117 return [self _domDescendantsMatchingQualifier:_qualifier
121 @end /* NGDOMNode(EOQualifier) */