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