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 "DAVParserTest.h"
25 #include <NGObjWeb/SaxDAVHandler.h>
26 #include <SaxObjC/SaxObjC.h>
28 @implementation DAVParserTest
30 static id<NSObject,SaxXMLReader> xmlParser = nil;
31 static SaxDAVHandler *davsax = nil;
34 if ((self = [super init])) {
35 if (xmlParser == nil) {
37 [[[SaxXMLReaderFactory standardXMLReaderFactory]
38 createXMLReaderForMimeType:@"text/xml"]
40 if (xmlParser == nil) {
41 [self logWithFormat:@"found no XML-parser !"];
46 if ((davsax = [[SaxDAVHandler alloc] init]) == nil) {
47 [self logWithFormat:@"found no DAV SAX handler ..."];
50 [davsax setDelegate:self];
57 [self->propQueue release];
63 - (void)lockParser:(id)_sax {
65 [xmlParser setContentHandler:_sax];
66 [xmlParser setErrorHandler:_sax];
68 - (void)unlockParser:(id)_sax {
69 [xmlParser setContentHandler:nil];
70 [xmlParser setErrorHandler:nil];
74 /* the DAV parser reports properties using the prop-queue */
76 - (void)startPropQueue {
78 [self->propQueue removeAllObjects];
80 self->propQueue = [[NSMutableDictionary alloc] initWithCapacity:128];
82 - (void)clearPropQueue {
83 [self->propQueue release];
84 self->propQueue = nil;
87 - (void)davHandler:(SaxDAVHandler *)_handler
88 receivedProperties:(NSDictionary *)_record
89 forURI:(NSString *)_uri
91 /* Note: _record is volatile ! */
95 [self logWithFormat:@"PROPS on %@: %@", _uri, _record];
97 lurl = [NSURL URLWithString:_uri];
99 [self->propQueue setObject:r forKey:(lurl ? [lurl path] : _uri)];
103 - (NSDictionary *)doQueueParseDict:(id)_src {
106 [self startPropQueue];
107 [self lockParser:davsax];
108 [xmlParser parseFromSource:_src];
109 [self unlockParser:davsax];
110 results = [self->propQueue retain];
111 [self clearPropQueue];
112 return [results autorelease];
114 - (NSArray *)doQueueParse:(id)_src {
115 return [[self doQueueParseDict:_src] allValues];
120 - (void)printResults {
121 EOFetchSpecification *fs;
126 if ([self->propQueue count] > 0) {
127 [self logWithFormat:@"collected %i property sets: %@",
128 [self->propQueue count],
134 if ((tmp = [davsax propPatchValues]))
135 [self logWithFormat:@"patch %i values: %@", [tmp count], tmp];
136 if ((tmp = [davsax propPatchPropertyNamesToRemove]))
137 [self logWithFormat:@"remove %i properties: %@", [tmp count], tmp];
141 if ([davsax propFindAllProperties])
142 [self logWithFormat:@"find all properties !"];
143 if ([davsax propFindPropertyNames])
144 [self logWithFormat:@"deliver only property names (not their values)"];
146 if ((tmp = [davsax propFindQueriedNames]))
147 [self logWithFormat:@"find %i attributes: %@", [tmp count], tmp];
149 if ((tmp = [davsax bpropFindTargets]))
150 [self logWithFormat:@"bulkfind %i targets: %@", [tmp count], tmp];
152 if ((fs = [davsax searchFetchSpecification]))
153 [self logWithFormat:@"search: %@", fs];
156 - (void)runOnArgument:(NSString *)_arg {
159 if (xmlParser == nil || davsax == nil)
160 [self logWithFormat:@"missing XML-parser ..."];
162 if (![_arg isAbsolutePath]) {
163 _arg = [[[NSFileManager defaultManager] currentDirectoryPath]
164 stringByAppendingPathComponent:_arg];
166 url = [[[NSURL alloc] initFileURLWithPath:_arg] autorelease];
167 [self logWithFormat:@"process %@: %@", _arg, url];
169 [self startPropQueue];
170 [self lockParser:davsax];
172 [xmlParser parseFromSource:url];
175 [self unlockParser:davsax];
176 [self clearPropQueue];
179 - (void)runWithArguments:(NSArray *)_args {
182 if ((count = [_args count]) == 1) {
183 [self logWithFormat:@"usage: %@ <files*>", [_args objectAtIndex:0]];
188 for (i = 1; i < count; i++)
189 [self runOnArgument:[_args objectAtIndex:i]];
192 @end /* DAVParserTest */