2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
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
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.
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
22 #include <NGObjWeb/WODynamicElement.h>
24 @interface IcalComponent : WODynamicElement
31 @interface IcalProperty : WODynamicElement
35 NSDictionary *parameters;
37 WOAssociation *valueType;
43 static inline NSDictionary *ExtractParameters(NSDictionary *_set) {
44 /* extracts ? parameters */
45 NSMutableDictionary *paras = nil;
46 NSMutableArray *paraKeys = nil;
50 // locate query parameters
51 keys = [_set keyEnumerator];
52 while ((key = [keys nextObject])) {
53 if ([key hasPrefix:@"?"]) {
56 if ([key isEqualToString:@"?wosid"])
59 value = [_set objectForKey:key];
62 paraKeys = [NSMutableArray arrayWithCapacity:8];
64 paras = [NSMutableDictionary dictionaryWithCapacity:8];
66 [paraKeys addObject:key];
67 [paras setObject:value forKey:[key substringFromIndex:1]];
71 // remove query parameters
74 for (cnt = 0, count = [paraKeys count]; cnt < count; cnt++) {
75 [(NSMutableDictionary *)_set removeObjectForKey:
76 [paraKeys objectAtIndex:cnt]];
84 static inline id GetProperty(NSDictionary *_set, NSString *_name) {
85 id propValue = [_set objectForKey:_name];
88 propValue = RETAIN(propValue);
89 [(id)_set removeObjectForKey:_name];
94 @implementation IcalComponent
96 - (id)initWithName:(NSString *)_name
97 associations:(NSDictionary *)_config
98 template:(WOElement *)_t
100 if ((self = [super initWithName:_name associations:_config template:_t])) {
101 self->cname = GetProperty(_config, @"name");
102 self->template = RETAIN(_t);
108 RELEASE(self->template);
109 RELEASE(self->cname);
113 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
116 n = [self->cname stringValueInComponent:[_ctx component]];
118 [_response appendContentString:@"BEGIN:"];
119 [_response appendContentString:n];
120 [self->template appendToResponse:_response inContext:_ctx];
121 [_response appendContentString:@"END:"];
122 [_response appendContentString:n];
125 @end /* IcalComponent */
127 @implementation IcalProperty
129 - (id)initWithName:(NSString *)_name
130 associations:(NSDictionary *)_config
131 template:(WOElement *)_t
133 if ((self = [super initWithName:_name associations:_config template:_t])) {
134 self->pname = GetProperty(_config, @"name");
135 self->value = GetProperty(_config, @"value");
136 self->valueType = GetProperty(_config, @"valueType");
137 self->template = RETAIN(_t);
138 self->parameters = ExtractParameters(_config);
144 RELEASE(self->value);
145 RELEASE(self->valueType);
146 RELEASE(self->parameters);
147 RELEASE(self->template);
148 RELEASE(self->pname);
152 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
153 WOComponent *sComponent;
160 sComponent = [_ctx component];
161 n = [self->pname stringValueInComponent:sComponent];
162 val = [self->value valueInComponent:sComponent];
163 valType = [self->valueType stringValueInComponent:sComponent];
166 [_response appendContentString:n];
169 keys = [self->parameters keyEnumerator];
170 while ((key = [keys nextObject])) {
174 val = [self->parameters objectForKey:key];
175 s = [val stringValueInComponent:sComponent];
177 if ([s length] > 0) {
178 [_response appendContentString:@";"];
179 [_response appendContentString:key];
180 [_response appendContentString:@"="];
181 [_response appendContentString:s];
186 [_response appendContentString:@":"];
188 if ([valType length] == 0) {
189 val = [val stringValue];
191 else if ([valType isEqualToString:@"datetime"]) {
192 static NSString *calfmt = @"%Y%m%dT%H%M00Z";
194 if ([val respondsToSelector:@selector(descriptionWithCalendarFormat:)]) {
195 static NSTimeZone *gmt = nil;
196 if (gmt == nil) gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
197 [val setTimeZone:gmt];
198 val = [val descriptionWithCalendarFormat:calfmt];
201 val = [val stringValue];
204 val = [val stringValue];
206 [_response appendContentString:val];
207 [self->template appendToResponse:_response inContext:_ctx];
210 @end /* IcalProperty */