]> err.no Git - scalable-opengroupware.org/blob - SOPE/NGCards/IcalResponse.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1205 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SOPE / NGCards / IcalResponse.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import "IcalResponse.h"
23
24 @implementation IcalResponse
25
26 - (void)_initContent {
27   [self appendLine:@"BEGIN:VCALENDAR"];
28   [self appendLine:@"VERSION:2.0"];
29   [self appendLine:@"PRODID:-//skyrix42/scheduler/skyaptd v.1.0//"];
30 }
31
32 - (id)init {
33   if ((self = [super init])) {
34     self->content    = [[NSMutableString alloc] initWithCapacity:0xFFFF];
35     self->isFinished = NO;
36     [self _initContent];
37   }
38   return self;
39 }
40 - (id)initWithCapacity:(unsigned)_capacity {
41   if ((self = [super init])) {
42     self->content    = [[NSMutableString alloc] initWithCapacity:_capacity];
43     self->isFinished = NO;
44     [self _initContent];
45   }
46   return self;
47 }
48
49 - (void)dealloc {
50   [self->content release];
51   [super dealloc];
52 }
53
54
55 - (BOOL)appendLine:(NSString *)_line {
56   if (self->isFinished) {
57     NSLog(@"WARNING[%s]: already finished!", __PRETTY_FUNCTION__);
58     return NO;
59   }
60   // limit length to 75 chars
61   while ([_line length] > 75) {
62     [self appendLine:[_line substringToIndex:75]];
63     _line = [@" " stringByAppendingString:[_line substringFromIndex:75]];
64   }
65
66   [self->content appendString:_line];
67   [self->content appendString:@"\r\n"];
68   
69   return YES;
70 }
71
72 - (BOOL)appendLine:(NSString *)_line forAttribute:(NSString *)_attr {
73   _line = [NSString stringWithFormat:@"%@:%@", _attr, _line];
74   return [self appendLine:_line];
75 }
76
77
78 - (void)finish {
79   if (self->isFinished) return;
80   [self appendLine:@"END:VCALENDAR"];
81   self->isFinished = YES;
82 }
83
84 - (NSString *)asString {
85   [self finish];
86   return [[self->content copy] autorelease];
87 }
88
89 @end /* IcalResponse */