2 Copyright (C) 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
24 #include "UIxComponent.h"
25 #include <Foundation/Foundation.h>
26 #include <NGObjWeb/NGObjWeb.h>
27 #include <NGExtensions/NGExtensions.h>
30 @interface UIxComponent (PrivateAPI)
31 - (void)_parseQueryString:(NSString *)_s;
35 @implementation UIxComponent
37 static NSTimeZone *MET = nil;
40 if (MET == nil) MET = [[NSTimeZone timeZoneWithAbbreviation:@"MET"] retain];
44 if ((self = [super init])) {
45 self->queryParameters = [[NSMutableDictionary alloc] init];
51 [self->queryParameters release];
63 req = [[self context] request];
65 r = [uri rangeOfString:@"?"];
69 qs = [uri substringFromIndex:(r.location + r.length)];
70 [self->queryParameters removeAllObjects];
71 [self _parseQueryString:qs];
75 - (void)_parseQueryString:(NSString *)_s {
79 e = [[_s componentsSeparatedByString:@"&"] objectEnumerator];
80 while ((part = [e nextObject])) {
82 NSString *key, *value;
84 r = [part rangeOfString:@"="];
86 /* missing value of query parameter */
87 key = [part stringByUnescapingURL];
91 key = [[part substringToIndex:r.location] stringByUnescapingURL];
92 value = [[part substringFromIndex:(r.location + r.length)]
93 stringByUnescapingURL];
95 [self->queryParameters setObject:value forKey:key];
99 - (NSString *)queryParameterForKey:(NSString *)_key {
100 return [self->queryParameters objectForKey:_key];
103 - (void)setQueryParameter:(NSString *)_param forKey:(NSString *)_key {
108 [self->queryParameters setObject:_param forKey:_key];
110 [self->queryParameters removeObjectForKey:_key];
113 - (NSDictionary *)queryParameters {
114 return self->queryParameters;
117 - (NSString *)completeHrefForMethod:(NSString *)_method {
121 qp = [self queryParameters];
125 qs = [[self context] queryStringFromDictionary:qp];
126 return [_method stringByAppendingFormat:@"?%@", qs];
129 - (NSString *)ownMethodName {
133 uri = [[[self context] request] uri];
135 /* first: cut off query parameters */
137 r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
139 uri = [uri substringToIndex:r.location];
141 /* next: strip trailing slash */
143 if ([uri hasSuffix:@"/"]) uri = [uri substringToIndex:([uri length] - 1)];
144 r = [uri rangeOfString:@"/" options:NSBackwardsSearch];
146 /* then: cut of last path component */
148 if (r.length == 0) // no slash? are we at root?
151 return [uri substringFromIndex:(r.location + 1)];
156 - (NSTimeZone *)viewTimeZone {
157 // Note: also in the folder, should be based on a cookie?
161 - (NSCalendarDate *)selectedDate {
163 NSCalendarDate *cdate;
165 s = [self queryParameterForKey:@"day"];
166 cdate = ([s length] > 0)
167 ? [self dateForDateString:s]
168 : [NSCalendarDate date];
169 [cdate setTimeZone:[self viewTimeZone]];
173 - (NSString *)dateStringForDate:(NSCalendarDate *)_date {
174 [_date setTimeZone:[self viewTimeZone]];
175 return [_date descriptionWithCalendarFormat:@"%Y%m%d"];
178 - (NSCalendarDate *)dateForDateString:(NSString *)_dateString {
181 tz = [self viewTimeZone];
182 /* Note: we should give a time, best is noon to avoid edge conditions */
183 _dateString = [_dateString stringByAppendingFormat:@"12:00:00 %@",
185 return [NSCalendarDate dateWithString:_dateString
186 calendarFormat:@"%Y%m%d %H:%M:%S %Z"];
189 @end /* UIxComponent */