From a9daffafa53f552457cae4c23afeda1a1678ef5c Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 5 Jul 2005 10:51:51 +0000 Subject: [PATCH] improved iCal extractor added test_quick_extract tool git-svn-id: http://svn.opengroupware.org/SOGo/trunk@659 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/OGoContentStore/ChangeLog | 9 ++ SOGo/OGoContentStore/GNUmakefile | 6 + SOGo/OGoContentStore/GNUmakefile.preamble | 4 + SOGo/OGoContentStore/OCSiCalFieldExtractor.m | 28 ++++- SOGo/OGoContentStore/Version | 2 +- SOGo/OGoContentStore/test_quick_extract.m | 123 +++++++++++++++++++ 6 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 SOGo/OGoContentStore/test_quick_extract.m diff --git a/SOGo/OGoContentStore/ChangeLog b/SOGo/OGoContentStore/ChangeLog index f2df7b13..351cb92f 100644 --- a/SOGo/OGoContentStore/ChangeLog +++ b/SOGo/OGoContentStore/ChangeLog @@ -1,3 +1,12 @@ +2005-07-05 Helge Hess + + * v0.9.28 + + * added test_quick_extract.m tool to test the quick-field extraction + + * OCSiCalFieldExtractor.m: properly deal with the iCal parser returning + just the iCalEvent + 2005-07-04 Marcus Mueller * v0.9.27 diff --git a/SOGo/OGoContentStore/GNUmakefile b/SOGo/OGoContentStore/GNUmakefile index 687f3f40..b997ef8e 100644 --- a/SOGo/OGoContentStore/GNUmakefile +++ b/SOGo/OGoContentStore/GNUmakefile @@ -5,6 +5,7 @@ include $(GNUSTEP_MAKEFILES)/common.make include ./Version LIBRARY_NAME = libOGoContentStore +TOOL_NAME = test_quick_extract TYPEMODELS_DIR = $(GNUSTEP_USER_ROOT)/Library/OCSTypeModels/ @@ -22,6 +23,11 @@ libOGoContentStore_TYPEMODELS += \ appointment.ocs \ contact.ocs \ + +test_quick_extract_OBJC_FILES += \ + test_quick_extract.m + -include GNUmakefile.preamble include $(GNUSTEP_MAKEFILES)/library.make +include $(GNUSTEP_MAKEFILES)/tool.make -include GNUmakefile.postamble diff --git a/SOGo/OGoContentStore/GNUmakefile.preamble b/SOGo/OGoContentStore/GNUmakefile.preamble index 07b77940..15fd604e 100644 --- a/SOGo/OGoContentStore/GNUmakefile.preamble +++ b/SOGo/OGoContentStore/GNUmakefile.preamble @@ -18,3 +18,7 @@ ifeq ($(FOUNDATION_LIB),apple) libOGoContentStore_PREBIND_ADDR="0xC7700000" libOGoContentStore_LDFLAGS += -seg1addr $(libOGoContentStore_PREBIND_ADDR) endif + +test_quick_extract_TOOL_LIBS += \ + -lNGExtensions \ + -lOGoContentStore diff --git a/SOGo/OGoContentStore/OCSiCalFieldExtractor.m b/SOGo/OGoContentStore/OCSiCalFieldExtractor.m index e89bf18c..a35e7576 100644 --- a/SOGo/OGoContentStore/OCSiCalFieldExtractor.m +++ b/SOGo/OGoContentStore/OCSiCalFieldExtractor.m @@ -197,13 +197,23 @@ static NSNumber *distantFutureNumber = nil; } - (NSMutableDictionary *)extractQuickFieldsFromCalendar:(iCalCalendar *)_cal { - id event; + NSArray *events; if (_cal == nil) return nil; - event = [[_cal events] lastObject]; - return [self extractQuickFieldsFromEvent:event]; + events = [_cal events]; + if ([events count] == 0) { + [self logWithFormat:@"ERROR: given calendar contains no events: %@", _cal]; + return nil; + } + if ([events count] > 1) { + [self logWithFormat: + @"WARNING: given calendar contains more than one event: %@", + _cal]; + } + + return [self extractQuickFieldsFromEvent:[events objectAtIndex:0]]; } - (NSMutableDictionary *)extractQuickFieldsFromContent:(NSString *)_content { @@ -220,7 +230,17 @@ static NSNumber *distantFutureNumber = nil; [parser parseFromSource:_content]; cal = [sax rootObject]; - fields = [[self extractQuickFieldsFromCalendar:cal] retain]; + + fields = nil; + if ([cal isKindOfClass:[iCalEvent class]]) + fields = [[self extractQuickFieldsFromEvent:cal] retain]; + else if ([cal isKindOfClass:[iCalCalendar class]]) + fields = [[self extractQuickFieldsFromCalendar:cal] retain]; + else if ([cal isNotNull]) { + [self logWithFormat:@"ERROR: unexpected iCalendar parse result: %@", + cal]; + } + [sax reset]; [pool release]; diff --git a/SOGo/OGoContentStore/Version b/SOGo/OGoContentStore/Version index bc1f83ae..7d69e771 100644 --- a/SOGo/OGoContentStore/Version +++ b/SOGo/OGoContentStore/Version @@ -2,7 +2,7 @@ MAJOR_VERSION=0 MINOR_VERSION=9 -SUBMINOR_VERSION:=27 +SUBMINOR_VERSION:=28 # v0.9.26 requires libGDLContentStore v4.5.26 # v0.9.19 requires libNGiCal v4.5.40 diff --git a/SOGo/OGoContentStore/test_quick_extract.m b/SOGo/OGoContentStore/test_quick_extract.m new file mode 100644 index 00000000..b2e46796 --- /dev/null +++ b/SOGo/OGoContentStore/test_quick_extract.m @@ -0,0 +1,123 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of SOGo. + + SOGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + + +#import + +@class NSArray; + +@interface TestQuickExtract : NSObject + +- (int)runWithArguments:(NSArray *)_args; + +@end + +#include +#include "common.h" + +@implementation TestQuickExtract + +- (int)usage:(NSArray *)_args { + fprintf(stderr, "usage: %s \n", + [[_args objectAtIndex:0] cString]); + return 1; +} + +- (void)extractQuickInfoFromFileAtPath:(NSString *)_path + usingExtractorClass:(Class)_clazz +{ + GCSFieldExtractor *extractor; + NSString *content; + NSDictionary *quickInfo; + + if ((content = [NSString stringWithContentsOfFile:_path]) == nil) { + fprintf(stderr, "ERROR: could not open file: %s\n", [_path cString]); + return; + } + + extractor = [[_clazz alloc] init]; + quickInfo = [[extractor extractQuickFieldsFromContent:content] retain]; + [extractor release]; extractor = nil; + + if ([quickInfo count] == 0) { + fprintf(stderr, "ERROR: could not extract quickfields from file: %s\n", + [_path cString]); + return; + } + + printf("File: %s\n", [_path cString]); + printf("**************************************************\n"); + printf("%s\n", [[quickInfo description] cString]); + + [quickInfo release]; +} + +- (void)extractQuickInfoFromFiles:(NSEnumerator *)_pathes + usingExtractorClass:(Class)_clazz +{ + NSString *path; + + while ((path = [_pathes nextObject]) != nil) + [self extractQuickInfoFromFileAtPath:path usingExtractorClass:_clazz]; +} + +- (int)runWithArguments:(NSArray *)_args { + NSEnumerator *e; + Class clazz; + + if ([_args count] < 3) + return [self usage:_args]; + + if ((clazz = NSClassFromString([_args objectAtIndex:1])) == Nil) { + fprintf(stderr, "ERROR: did not find extractor class: %s\n", + [[_args objectAtIndex:1] cString]); + return 2; + } + + e = [_args objectEnumerator]; + [e nextObject]; // skip toolname + [e nextObject]; // skip classname + + [self extractQuickInfoFromFiles:e usingExtractorClass:clazz]; + + return 0; +} + +@end /* TestQuickExtract */ + + +int main(int argc, char **argv, char **env) { + NSAutoreleasePool *pool; + TestQuickExtract *tool; + int rc; + + pool = [[NSAutoreleasePool alloc] init]; +#if LIB_FOUNDATION_LIBRARY + [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; +#endif + + tool = [[TestQuickExtract alloc] init]; + rc = [tool runWithArguments: + [[NSProcessInfo processInfo] argumentsWithoutDefaults]]; + [tool release]; + [pool release]; + return rc; +} -- 2.39.5