2 Copyright (C) 2005 SKYRIX Software AG
4 This file is part of SOGo.
6 SOGo 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 SOGo 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 SOGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #import <Foundation/NSObject.h>
27 @interface TestQuickExtract : NSObject
29 - (int)runWithArguments:(NSArray *)_args;
33 #include <GDLContentStore/GCSFieldExtractor.h>
36 @implementation TestQuickExtract
38 - (int)usage:(NSArray *)_args {
39 fprintf(stderr, "usage: %s <ExtractorClassName> <file1> <file2>\n",
40 [[_args objectAtIndex:0] cString]);
44 - (void)extractQuickInfoFromFileAtPath:(NSString *)_path
45 usingExtractorClass:(Class)_clazz
47 GCSFieldExtractor *extractor;
49 NSDictionary *quickInfo;
51 if ((content = [NSString stringWithContentsOfFile:_path]) == nil) {
52 fprintf(stderr, "ERROR: could not open file: %s\n", [_path cString]);
56 extractor = [[_clazz alloc] init];
57 quickInfo = [[extractor extractQuickFieldsFromContent:content] retain];
58 [extractor release]; extractor = nil;
60 if ([quickInfo count] == 0) {
61 fprintf(stderr, "ERROR: could not extract quickfields from file: %s\n",
66 printf("File: %s\n", [_path cString]);
67 printf("**************************************************\n");
68 printf("%s\n", [[quickInfo description] cString]);
73 - (void)extractQuickInfoFromFiles:(NSEnumerator *)_pathes
74 usingExtractorClass:(Class)_clazz
78 while ((path = [_pathes nextObject]) != nil)
79 [self extractQuickInfoFromFileAtPath:path usingExtractorClass:_clazz];
82 - (int)runWithArguments:(NSArray *)_args {
86 if ([_args count] < 3)
87 return [self usage:_args];
89 if ((clazz = NSClassFromString([_args objectAtIndex:1])) == Nil) {
90 fprintf(stderr, "ERROR: did not find extractor class: %s\n",
91 [[_args objectAtIndex:1] cString]);
95 e = [_args objectEnumerator];
96 [e nextObject]; // skip toolname
97 [e nextObject]; // skip classname
99 [self extractQuickInfoFromFiles:e usingExtractorClass:clazz];
104 @end /* TestQuickExtract */
107 int main(int argc, char **argv, char **env) {
108 NSAutoreleasePool *pool;
109 TestQuickExtract *tool;
112 pool = [[NSAutoreleasePool alloc] init];
113 #if LIB_FOUNDATION_LIBRARY
114 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
117 tool = [[TestQuickExtract alloc] init];
118 rc = [tool runWithArguments:
119 [[NSProcessInfo processInfo] argumentsWithoutDefaults]];