2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
23 #include <NGObjWeb/WODynamicElement.h>
25 @interface IcalComponent : WODynamicElement
32 @interface IcalProperty : WODynamicElement
36 NSDictionary *parameters;
38 WOAssociation *valueType;
44 static inline NSDictionary *ExtractParameters(NSDictionary *_set) {
45 /* extracts ? parameters */
46 NSMutableDictionary *paras = nil;
47 NSMutableArray *paraKeys = nil;
51 // locate query parameters
52 keys = [_set keyEnumerator];
53 while ((key = [keys nextObject])) {
54 if ([key hasPrefix:@"?"]) {
57 if ([key isEqualToString:@"?wosid"])
60 value = [_set objectForKey:key];
63 paraKeys = [NSMutableArray arrayWithCapacity:8];
65 paras = [NSMutableDictionary dictionaryWithCapacity:8];
67 [paraKeys addObject:key];
68 [paras setObject:value forKey:[key substringFromIndex:1]];
72 // remove query parameters
75 for (cnt = 0, count = [paraKeys count]; cnt < count; cnt++) {
76 [(NSMutableDictionary *)_set removeObjectForKey:
77 [paraKeys objectAtIndex:cnt]];
85 static inline id GetProperty(NSDictionary *_set, NSString *_name) {
86 id propValue = [_set objectForKey:_name];
89 propValue = RETAIN(propValue);
90 [(id)_set removeObjectForKey:_name];
95 @implementation IcalComponent
97 - (id)initWithName:(NSString *)_name
98 associations:(NSDictionary *)_config
99 template:(WOElement *)_t
101 if ((self = [super initWithName:_name associations:_config template:_t])) {
102 self->cname = GetProperty(_config, @"name");
103 self->template = RETAIN(_t);
109 RELEASE(self->template);
110 RELEASE(self->cname);
114 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
117 n = [self->cname stringValueInComponent:[_ctx component]];
119 [_response appendContentString:@"BEGIN:"];
120 [_response appendContentString:n];
121 [self->template appendToResponse:_response inContext:_ctx];
122 [_response appendContentString:@"END:"];
123 [_response appendContentString:n];
126 @end /* IcalComponent */
128 @implementation IcalProperty
130 - (id)initWithName:(NSString *)_name
131 associations:(NSDictionary *)_config
132 template:(WOElement *)_t
134 if ((self = [super initWithName:_name associations:_config template:_t])) {
135 self->pname = GetProperty(_config, @"name");
136 self->value = GetProperty(_config, @"value");
137 self->valueType = GetProperty(_config, @"valueType");
138 self->template = RETAIN(_t);
139 self->parameters = ExtractParameters(_config);
145 RELEASE(self->value);
146 RELEASE(self->valueType);
147 RELEASE(self->parameters);
148 RELEASE(self->template);
149 RELEASE(self->pname);
153 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
154 WOComponent *sComponent;
161 sComponent = [_ctx component];
162 n = [self->pname stringValueInComponent:sComponent];
163 val = [self->value valueInComponent:sComponent];
164 valType = [self->valueType stringValueInComponent:sComponent];
167 [_response appendContentString:n];
170 keys = [self->parameters keyEnumerator];
171 while ((key = [keys nextObject])) {
175 val = [self->parameters objectForKey:key];
176 s = [val stringValueInComponent:sComponent];
178 if ([s length] > 0) {
179 [_response appendContentString:@";"];
180 [_response appendContentString:key];
181 [_response appendContentString:@"="];
182 [_response appendContentString:s];
187 [_response appendContentString:@":"];
189 if ([valType length] == 0) {
190 val = [val stringValue];
192 else if ([valType isEqualToString:@"datetime"]) {
193 static NSString *calfmt = @"%Y%m%dT%H%M00Z";
195 if ([val respondsToSelector:@selector(descriptionWithCalendarFormat:)]) {
196 static NSTimeZone *gmt = nil;
197 if (gmt == nil) gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
198 [val setTimeZone:gmt];
199 val = [val descriptionWithCalendarFormat:calfmt];
202 val = [val stringValue];
205 val = [val stringValue];
207 [_response appendContentString:val];
208 [self->template appendToResponse:_response inContext:_ctx];
211 @end /* IcalProperty */