2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OGo
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
38 if ((self = [super init])) {
39 self->queryParameters = [[NSMutableDictionary alloc] init];
45 [self->queryParameters release];
57 req = [[self context] request];
59 r = [uri rangeOfString:@"?"];
63 qs = [uri substringFromIndex:(r.location + r.length)];
64 [self->queryParameters removeAllObjects];
65 [self _parseQueryString:qs];
69 - (void)_parseQueryString:(NSString *)_s {
73 e = [[_s componentsSeparatedByString:@"&"] objectEnumerator];
74 while ((part = [e nextObject])) {
76 NSString *key, *value;
78 r = [part rangeOfString:@"="];
80 /* missing value of query parameter */
81 key = [part stringByUnescapingURL];
85 key = [[part substringToIndex:r.location] stringByUnescapingURL];
86 value = [[part substringFromIndex:(r.location + r.length)]
87 stringByUnescapingURL];
89 [self->queryParameters setObject:value forKey:key];
93 - (NSString *)queryParameterForKey:(NSString *)_key {
94 return [self->queryParameters objectForKey:_key];
97 - (void)setQueryParameter:(NSString *)_param forKey:(NSString *)_key {
102 [self->queryParameters setObject:_param forKey:_key];
104 [self->queryParameters removeObjectForKey:_key];
107 - (NSDictionary *)queryParameters {
108 return self->queryParameters;
111 - (NSString *)completeHrefForMethod:(NSString *)_method {
115 qp = [self queryParameters];
119 qs = [[self context] queryStringFromDictionary:qp];
120 return [_method stringByAppendingFormat:@"?%@", qs];
123 - (NSString *)ownMethodName {
127 uri = [[[self context] request] uri];
129 /* first: cut off query parameters */
131 r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
133 uri = [uri substringToIndex:r.location];
135 /* next: strip trailing slash */
137 if ([uri hasSuffix:@"/"]) uri = [uri substringToIndex:([uri length] - 1)];
138 r = [uri rangeOfString:@"/" options:NSBackwardsSearch];
140 /* then: cut of last path component */
142 if (r.length == 0) // no slash? are we at root?
145 return [uri substringFromIndex:(r.location + 1)];
150 - (NSCalendarDate *)selectedDate {
153 s = [self queryParameterForKey:@"day"];
155 return [self dateForDateString:s];
157 return [NSCalendarDate date];
160 - (NSString *)dateStringForDate:(NSCalendarDate *)_date {
161 return [_date descriptionWithCalendarFormat:@"%Y%m%d"];
164 - (NSCalendarDate *)dateForDateString:(NSString *)_dateString {
165 return [NSCalendarDate dateWithString:_dateString calendarFormat:@"%Y%m%d"];