]> err.no Git - scalable-opengroupware.org/blob - OGoContentStore/test_quick_extract.m
moved SOGo files up
[scalable-opengroupware.org] / OGoContentStore / test_quick_extract.m
1 /*
2   Copyright (C) 2005 SKYRIX Software AG
3
4   This file is part of SOGo.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22
23 #import <Foundation/NSObject.h>
24
25 @class NSArray;
26
27 @interface TestQuickExtract : NSObject
28
29 - (int)runWithArguments:(NSArray *)_args;
30
31 @end
32
33 #include <GDLContentStore/GCSFieldExtractor.h>
34 #include "common.h"
35
36 @implementation TestQuickExtract
37
38 - (int)usage:(NSArray *)_args {
39   fprintf(stderr, "usage: %s <ExtractorClassName> <file1> <file2>\n",
40           [[_args objectAtIndex:0] cString]);
41   return 1;
42 }
43
44 - (void)extractQuickInfoFromFileAtPath:(NSString *)_path
45   usingExtractorClass:(Class)_clazz
46 {
47   GCSFieldExtractor *extractor;
48   NSString     *content;
49   NSDictionary *quickInfo;
50
51   if ((content = [NSString stringWithContentsOfFile:_path]) == nil) {
52     fprintf(stderr, "ERROR: could not open file: %s\n", [_path cString]);
53     return;
54   }
55   
56   extractor = [[_clazz alloc] init];
57   quickInfo = [[extractor extractQuickFieldsFromContent:content] retain];
58   [extractor release]; extractor = nil;
59   
60   if ([quickInfo count] == 0) {
61     fprintf(stderr, "ERROR: could not extract quickfields from file: %s\n",
62             [_path cString]);
63     return;
64   }
65   
66   printf("File: %s\n", [_path cString]);
67   printf("**************************************************\n");
68   printf("%s\n", [[quickInfo description] cString]);
69
70   [quickInfo release];
71 }
72
73 - (void)extractQuickInfoFromFiles:(NSEnumerator *)_pathes
74   usingExtractorClass:(Class)_clazz
75 {
76   NSString *path;
77   
78   while ((path = [_pathes nextObject]) != nil)
79     [self extractQuickInfoFromFileAtPath:path usingExtractorClass:_clazz];
80 }
81
82 - (int)runWithArguments:(NSArray *)_args {
83   NSEnumerator *e;
84   Class clazz;
85   
86   if ([_args count] < 3)
87     return [self usage:_args];
88   
89   if ((clazz = NSClassFromString([_args objectAtIndex:1])) == Nil) {
90     fprintf(stderr, "ERROR: did not find extractor class: %s\n",
91             [[_args objectAtIndex:1] cString]);
92     return 2;
93   }
94   
95   e = [_args objectEnumerator];
96   [e nextObject]; // skip toolname
97   [e nextObject]; // skip classname
98   
99   [self extractQuickInfoFromFiles:e usingExtractorClass:clazz];
100   
101   return 0;
102 }
103
104 @end /* TestQuickExtract */
105
106
107 int main(int argc, char **argv, char **env) {
108   NSAutoreleasePool *pool;
109   TestQuickExtract  *tool;
110   int rc;
111   
112   pool = [[NSAutoreleasePool alloc] init];
113 #if LIB_FOUNDATION_LIBRARY
114   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
115 #endif
116   
117   tool = [[TestQuickExtract alloc] init];
118   rc = [tool runWithArguments:
119                [[NSProcessInfo processInfo] argumentsWithoutDefaults]];
120   [tool release];
121   [pool release];
122   return rc;
123 }