2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo 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.
|
|
|
|
|
|
|
|
OGo 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
|
2007-06-12 17:33:08 +02:00
|
|
|
License along with SOGo; see the file COPYING. If not, write to the
|
2006-06-15 21:34:10 +02:00
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
2007-07-10 16:15:07 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-07-10 16:15:07 +02:00
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
2007-07-10 16:15:07 +02:00
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.h>
|
2007-07-10 16:15:07 +02:00
|
|
|
|
|
|
|
#import "OCSiCalFieldExtractor.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation OCSiCalFieldExtractor
|
|
|
|
|
2006-09-28 19:19:19 +02:00
|
|
|
+ (id) sharedICalFieldExtractor
|
|
|
|
{
|
2007-06-12 17:33:08 +02:00
|
|
|
static OCSiCalFieldExtractor *extractor = nil;
|
|
|
|
|
|
|
|
if (!extractor)
|
2006-09-28 19:19:19 +02:00
|
|
|
extractor = [self new];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-28 19:19:19 +02:00
|
|
|
return extractor;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* operations */
|
|
|
|
|
2006-10-11 20:21:49 +02:00
|
|
|
- (CardGroup *) firstElementFromCalendar: (iCalCalendar *) ical
|
|
|
|
{
|
|
|
|
NSArray *elements;
|
|
|
|
CardGroup *element;
|
|
|
|
unsigned int count;
|
2007-06-12 17:33:08 +02:00
|
|
|
|
2006-10-11 20:21:49 +02:00
|
|
|
elements = [ical allObjects];
|
|
|
|
count = [elements count];
|
|
|
|
if (count)
|
2008-07-12 00:28:12 +02:00
|
|
|
element = [elements objectAtIndex: 0];
|
2006-10-11 20:21:49 +02:00
|
|
|
else
|
|
|
|
{
|
2007-06-12 17:33:08 +02:00
|
|
|
[self logWithFormat: @"ERROR: given calendar contains no elements: %@", ical];
|
2006-10-11 20:21:49 +02:00
|
|
|
element = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
- (NSMutableDictionary *) extractQuickFieldsFromContent: (NSString *) _content
|
|
|
|
{
|
|
|
|
NSMutableDictionary *fields;
|
2006-06-15 21:34:10 +02:00
|
|
|
id cal;
|
|
|
|
|
2006-09-29 20:31:20 +02:00
|
|
|
fields = nil;
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
if ([_content length])
|
2006-09-29 20:31:20 +02:00
|
|
|
{
|
2008-07-12 00:28:12 +02:00
|
|
|
cal = [iCalCalendar parseSingleFromSource: _content];
|
|
|
|
if (cal)
|
|
|
|
{
|
|
|
|
if ([cal isKindOfClass: [iCalCalendar class]])
|
|
|
|
cal = [self firstElementFromCalendar: cal];
|
|
|
|
|
|
|
|
if ([cal isKindOfClass: [iCalRepeatableEntityObject class]])
|
|
|
|
fields = [cal quickRecord];
|
|
|
|
else if ([cal isNotNull])
|
|
|
|
[self logWithFormat: @"ERROR: unexpected iCalendar parse result: %@",
|
|
|
|
cal];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self logWithFormat: @"ERROR: parsing source didn't return anything"];
|
2006-09-28 19:19:19 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
return fields;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end /* OCSiCalFieldExtractor */
|