2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/Foundation.h>
23 #include <SaxObjC/SaxObjC.h>
25 @interface iCal2Tool : NSObject
27 id<NSObject,SaxXMLReader> parser;
28 SaxObjectDecoder *sax;
31 - (int)runWithArguments:(NSArray *)_args;
35 @implementation iCal2Tool
38 if ((self = [super init])) {
40 [[[SaxXMLReaderFactory standardXMLReaderFactory]
41 createXMLReaderForMimeType:@"text/calendar"]
43 if (self->parser == nil) {
44 NSLog(@"%s: did not find a parser for text/calendar !",
50 /* ensure that NGiCal.xmap can be found ! (Library/SaxMappings) */
51 self->sax = [[SaxObjectDecoder alloc] initWithMappingNamed:@"NGiCal"];
52 if (self->sax == nil) {
53 NSLog(@"could not create the iCal SAX handler !");
58 [self->parser setContentHandler:self->sax];
59 [self->parser setErrorHandler:self->sax];
65 [self->parser release];
71 - (id)parseFile:(NSString *)_path {
72 if ([_path length] == 0) return nil;
74 _path = [@"file://" stringByAppendingString:_path];
76 [self->parser parseFromSystemId:_path];
78 return [self->sax rootObject];
81 - (void)printParsedObject:(id)_object {
82 NSLog(@"component: %@", _object);
84 NSLog(@" subcomponents: %@", [_object subComponents]);
86 printf("%s", [[_object icalString] cString]);
92 - (int)runWithArguments:(NSArray *)_args {
96 args = [_args objectEnumerator];
97 [args nextObject]; // process name ...
99 while ((arg = [args nextObject])) {
100 NSAutoreleasePool *pool2;
102 if ([arg hasPrefix:@"-"]) { /* consume defaults */
107 pool2 = [[NSAutoreleasePool alloc] init];
112 component = [self parseFile:arg];
117 if (component == nil)
118 NSLog(@"could not parse file: '%@'", arg);
120 [self printParsedObject:component];
129 int main(int argc, char **argv, char **env) {
130 NSAutoreleasePool *pool;
134 #if LIB_FOUNDATION_LIBRARY
135 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
138 pool = [[NSAutoreleasePool alloc] init];
140 if ((tool = [[iCal2Tool alloc] init])) {
142 rc = [tool runWithArguments:[[NSProcessInfo processInfo] arguments]];