2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "DOMNode+EOQualifier.h"
24 #include <EOControl/EOQualifier.h>
27 @interface NSObject(DOMNodeEOQualifier)
28 - (NSArray *)_domChildrenMatchingQualifier:(EOQualifier *)_qualifier;
29 - (NSArray *)_domDescendantsMatchingQualifier:(EOQualifier *)_qualifier
30 includeSelf:(BOOL)_includeSelf;
33 @implementation NSObject(DOMNodeEOQualifier)
34 /* this category is used to support DOM ops on any object */
36 static NSArray *emptyArray = nil;
38 - (NSArray *)_domChildrenMatchingQualifier:(EOQualifier *)_qualifier {
42 if (![(DOMNode *)self hasChildNodes])
45 if ((children = [(DOMNode *)self childNodes]) == nil)
48 if ((count = [children count]) == 0) {
49 if (emptyArray == nil) emptyArray = [[NSArray alloc] init];
53 NSMutableArray *marray;
56 marray = [NSMutableArray arrayWithCapacity:(count + 1)];
58 for (i = 0; i < count; i++) {
61 if ((childNode = [children objectAtIndex:i])) {
62 if ((_qualifier == nil) ||
63 [(id<EOQualifierEvaluation>)_qualifier evaluateWithObject:childNode])
64 [marray addObject:childNode];
68 return [[marray copy] autorelease];
72 - (void)_addDOMDescendantsMatchingQualifier:(EOQualifier *)_qualifier
73 toMutableArray:(NSMutableArray *)_array
74 includeSelf:(BOOL)_includeSelf
80 if ([(id<EOQualifierEvaluation>)_qualifier evaluateWithObject:self])
81 [_array addObject:self];
84 if (![(DOMNode *)self hasChildNodes])
87 children = [(DOMNode *)self childNodes];
88 for (i = 0, count = [children count]; i < count; i++) {
89 [[children objectAtIndex:i]
90 _addDOMDescendantsMatchingQualifier:_qualifier
95 - (NSArray *)_domDescendantsMatchingQualifier:(EOQualifier *)_qualifier
96 includeSelf:(BOOL)_includeSelf
98 NSMutableArray *marray;
100 marray = [NSMutableArray arrayWithCapacity:16];
102 [self _addDOMDescendantsMatchingQualifier:_qualifier
103 toMutableArray:marray
104 includeSelf:_includeSelf];
106 return [[marray copy] autorelease];
109 @end /* NSObject(DOMNodeEOQualifier) */
111 @implementation DOMNode(EOQualifier)
113 - (NSArray *)childrenMatchingQualifier:(EOQualifier *)_qualifier {
114 return [self _domChildrenMatchingQualifier:_qualifier];
117 - (NSArray *)descendantsMatchingQualifier:(EOQualifier *)_qualifier {
118 return [self _domDescendantsMatchingQualifier:_qualifier
122 @end /* DOMNode(EOQualifier) */