]> err.no Git - sope/blob - sope-ical/NGiCal/IcalResponse.m
fixed b0rked Xcode project files
[sope] / sope-ical / NGiCal / 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 #include "IcalResponse.h"
23 #import <Foundation/Foundation.h>
24
25 @implementation IcalResponse
26
27 - (void)_initContent {
28   [self appendLine:@"BEGIN:VCALENDAR"];
29   [self appendLine:@"VERSION:2.0"];
30   [self appendLine:@"PRODID:-//skyrix42/scheduler/skyaptd v.1.0//"];
31 }
32
33 - (id)init {
34   if ((self = [super init])) {
35     self->content    = [[NSMutableString alloc] initWithCapacity:0xFFFF];
36     self->isFinished = NO;
37     [self _initContent];
38   }
39   return self;
40 }
41 - (id)initWithCapacity:(unsigned)_capacity {
42   if ((self = [super init])) {
43     self->content    = [[NSMutableString alloc] initWithCapacity:_capacity];
44     self->isFinished = NO;
45     [self _initContent];
46   }
47   return self;
48 }
49
50 - (void)dealloc {
51   [self->content release];
52   [super dealloc];
53 }
54
55
56 - (BOOL)appendLine:(NSString *)_line {
57   if (self->isFinished) {
58     NSLog(@"WARNING[%s]: already finished!", __PRETTY_FUNCTION__);
59     return NO;
60   }
61   // limit length to 75 chars
62   while ([_line length] > 75) {
63     [self appendLine:[_line substringToIndex:75]];
64     _line = [@" " stringByAppendingString:[_line substringFromIndex:75]];
65   }
66
67   [self->content appendString:_line];
68   [self->content appendString:@"\r\n"];
69   
70   return YES;
71 }
72
73 - (BOOL)appendLine:(NSString *)_line forAttribute:(NSString *)_attr {
74   _line = [NSString stringWithFormat:@"%@:%@", _attr, _line];
75   return [self appendLine:_line];
76 }
77
78
79 - (void)finish {
80   if (self->isFinished) return;
81   [self appendLine:@"END:VCALENDAR"];
82   self->isFinished = YES;
83 }
84
85 - (NSString *)asString {
86   [self finish];
87   return [[self->content copy] autorelease];
88 }
89
90 @end /* IcalResponse */