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 #import <Foundation/NSArray.h>
23 #import <Foundation/NSDictionary.h>
24 #import <Foundation/NSEnumerator.h>
25 #import <Foundation/NSString.h>
27 #import <NGObjWeb/WOContext.h>
28 #import <NGObjWeb/WODynamicElement.h>
29 #import <NGObjWeb/WOResponse.h>
31 @interface IcalComponent : WODynamicElement
38 @interface IcalProperty : WODynamicElement
42 NSDictionary *parameters;
44 WOAssociation *valueType;
49 static inline NSDictionary *ExtractParameters(NSDictionary *_set) {
50 /* extracts ? parameters */
51 NSMutableDictionary *paras = nil;
52 NSMutableArray *paraKeys = nil;
56 // locate query parameters
57 keys = [_set keyEnumerator];
58 while ((key = [keys nextObject])) {
59 if ([key hasPrefix:@"?"]) {
62 if ([key isEqualToString:@"?wosid"])
65 value = [_set objectForKey:key];
68 paraKeys = [NSMutableArray arrayWithCapacity:8];
70 paras = [NSMutableDictionary dictionaryWithCapacity:8];
72 [paraKeys addObject:key];
73 [paras setObject:value forKey:[key substringFromIndex:1]];
77 // remove query parameters
80 for (cnt = 0, count = [paraKeys count]; cnt < count; cnt++) {
81 [(NSMutableDictionary *)_set removeObjectForKey:
82 [paraKeys objectAtIndex:cnt]];
90 static inline id GetProperty(NSDictionary *_set, NSString *_name) {
91 id propValue = [_set objectForKey:_name];
94 propValue = RETAIN(propValue);
95 [(id)_set removeObjectForKey:_name];
100 @implementation IcalComponent
102 - (id)initWithName:(NSString *)_name
103 associations:(NSDictionary *)_config
104 template:(WOElement *)_t
106 if ((self = [super initWithName:_name associations:_config template:_t])) {
107 self->cname = GetProperty(_config, @"name");
108 self->template = RETAIN(_t);
114 RELEASE(self->template);
115 RELEASE(self->cname);
119 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
122 n = [self->cname stringValueInComponent:[_ctx component]];
124 [_response appendContentString:@"BEGIN:"];
125 [_response appendContentString:n];
126 [self->template appendToResponse:_response inContext:_ctx];
127 [_response appendContentString:@"END:"];
128 [_response appendContentString:n];
131 @end /* IcalComponent */
133 @implementation IcalProperty
135 - (id)initWithName:(NSString *)_name
136 associations:(NSDictionary *)_config
137 template:(WOElement *)_t
139 if ((self = [super initWithName:_name associations:_config template:_t])) {
140 self->pname = GetProperty(_config, @"name");
141 self->value = GetProperty(_config, @"value");
142 self->valueType = GetProperty(_config, @"valueType");
143 self->template = RETAIN(_t);
144 self->parameters = ExtractParameters(_config);
150 RELEASE(self->value);
151 RELEASE(self->valueType);
152 RELEASE(self->parameters);
153 RELEASE(self->template);
154 RELEASE(self->pname);
158 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
159 WOComponent *sComponent;
166 sComponent = [_ctx component];
167 n = [self->pname stringValueInComponent:sComponent];
168 val = [self->value valueInComponent:sComponent];
169 valType = [self->valueType stringValueInComponent:sComponent];
172 [_response appendContentString:n];
175 keys = [self->parameters keyEnumerator];
176 while ((key = [keys nextObject])) {
180 val = [self->parameters objectForKey:key];
181 s = [val stringValueInComponent:sComponent];
183 if ([s length] > 0) {
184 [_response appendContentString:@";"];
185 [_response appendContentString:key];
186 [_response appendContentString:@"="];
187 [_response appendContentString:s];
192 [_response appendContentString:@":"];
194 if ([valType length] == 0) {
195 val = [val stringValue];
197 else if ([valType isEqualToString:@"datetime"]) {
198 static NSString *calfmt = @"%Y%m%dT%H%M00Z";
200 if ([val respondsToSelector:@selector(descriptionWithCalendarFormat:)]) {
201 static NSTimeZone *gmt = nil;
202 if (gmt == nil) gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
203 [val setTimeZone:gmt];
204 val = [val descriptionWithCalendarFormat:calfmt];
207 val = [val stringValue];
210 val = [val stringValue];
212 [_response appendContentString:val];
213 [self->template appendToResponse:_response inContext:_ctx];
216 @end /* IcalProperty */