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 "WOHTMLDynamicElement.h"
23 #include "WOElement+private.h"
24 #include <NGObjWeb/WOAssociation.h>
25 #include <NGObjWeb/WOContext.h>
26 #include <NGObjWeb/WOApplication.h>
27 #include <NGObjWeb/WOSession.h>
28 #include <NGObjWeb/WORequest.h>
29 #include <NGObjWeb/WOResponse.h>
33 WOMetaRefresh associations:
35 href | pageName | action | (directActionName & actionClass)
41 @interface WOMetaRefresh : WOHTMLDynamicElement
43 // WODynamicElement: extraAttributes
44 // WODynamicElement: otherTagString
46 WOAssociation *action;
48 WOAssociation *pageName;
49 WOAssociation *directActionName;
50 WOAssociation *actionClass;
51 WOAssociation *disabled;
52 WOAssociation *fragmentIdentifier;
53 WOAssociation *timeout;
55 WOAssociation *queryDictionary;
56 NSDictionary *queryParameters; /* associations beginning with ? */
62 @implementation WOMetaRefresh
64 - (id)initWithName:(NSString *)_name
65 associations:(NSDictionary *)_config
66 template:(WOElement *)_t
68 if ((self = [super initWithName:_name associations:_config template:_t])) {
69 WOAssociation *sidInUrlAssoc;
71 sidInUrlAssoc = OWGetProperty(_config, @"?wosid");
72 self->action = OWGetProperty(_config, @"action");
73 self->href = OWGetProperty(_config, @"href");
74 self->pageName = OWGetProperty(_config, @"pageName");
75 self->fragmentIdentifier = OWGetProperty(_config, @"fragmentIdentifier");
76 self->disabled = OWGetProperty(_config, @"disabled");
77 self->timeout = OWGetProperty(_config, @"timeout");
78 self->directActionName = OWGetProperty(_config, @"directActionName");
79 self->actionClass = OWGetProperty(_config, @"actionClass");
81 self->sidInUrl = (sidInUrlAssoc)
82 ? [sidInUrlAssoc boolValueInComponent:nil]
85 if (self->timeout == nil)
86 self->timeout = OWGetProperty(_config, @"seconds");
87 else if ([OWGetProperty(_config, @"seconds") autorelease] != nil) {
89 @"WARNING: got both, 'timeout' and 'seconds' bindings!"];
92 self->queryDictionary = OWGetProperty(_config, @"queryDictionary");
93 self->queryParameters = OWExtractQueryParameters(_config);
99 [self->queryParameters release];
100 [self->queryDictionary release];
101 [self->directActionName release];
102 [self->actionClass release];
103 [self->action release];
104 [self->href release];
105 [self->pageName release];
106 [self->fragmentIdentifier release];
107 [self->disabled release];
108 [self->timeout release];
112 /* handling requests */
114 - (id)invokeActionForRequest:(WORequest *)_request
115 inContext:(WOContext *)_ctx
117 if ([self->disabled boolValueInComponent:[_ctx component]])
121 return [self executeAction:self->action inContext:_ctx];
123 if (self->pageName) {
127 name = [self->pageName stringValueInComponent:[_ctx component]];
128 page = [[_ctx application] pageWithName:name inContext:_ctx];
131 [[_ctx component] logWithFormat:
132 @"%@[0x%08X]: did not find page with name %@ !",
133 NSStringFromClass([self class]), self, name];
135 [self debugWithFormat:@"showing page %@", page];
140 logWithFormat:@"%@[0x%08X]: no action/page set !",
141 NSStringFromClass([self class]), self];
145 /* generating response */
147 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
148 WOComponent *sComponent;
151 NSString *queryString = nil;
154 if ([[_ctx request] isFromClientComponent])
157 sComponent = [_ctx component];
158 to = [self->timeout intValueInComponent:sComponent];
159 WOResponse_AddCString(_response, "<meta http-equiv=\"refresh\" content=\"");
160 WOResponse_AddInt(_response, to);
161 WOResponse_AddCString(_response, "; url=");
164 /* a href was explicitly assigned */
165 url = [self->href stringValueInComponent:sComponent];
166 addSID = self->sidInUrl;
168 else if (self->directActionName) {
169 /* a direct action */
173 daClass = [self->actionClass stringValueInComponent:sComponent];
174 daName = [self->directActionName stringValueInComponent:sComponent];
178 if (![daClass isEqualToString:@"DirectAction"])
179 daName = [NSString stringWithFormat:@"%@/%@", daClass, daName];
185 url = [_ctx directActionURLForActionNamed:daName queryDictionary:nil];
186 addSID = self->sidInUrl;
189 url = [_ctx componentActionURL];
192 WOResponse_AddString(_response, url);
194 queryString = [self queryStringForQueryDictionary:
195 [self->queryDictionary valueInComponent:sComponent]
196 andQueryParameters:self->queryParameters
198 if (addSID && [sComponent hasSession]) {
199 WOSession *sn = [sComponent session];
201 if ([queryString length] == 0) {
202 queryString = [NSString stringWithFormat:@"%@=%@",
203 WORequestValueSessionID, [sn sessionID]];
206 queryString = [queryString stringByAppendingFormat:@"&%@=%@",
207 WORequestValueSessionID, [sn sessionID]];
211 if (self->fragmentIdentifier) {
212 [_response appendContentCharacter:'#'];
213 WOResponse_AddString(_response,
214 [self->fragmentIdentifier stringValueInComponent:
219 [_response appendContentCharacter:'?'];
220 WOResponse_AddString(_response, queryString);
223 [_response appendContentCharacter:'"']; // close CONTENT attribute
225 [self appendExtraAttributesToResponse:_response inContext:_ctx];
226 if (self->otherTagString) {
227 WOResponse_AddChar(_response, ' ');
228 WOResponse_AddString(_response,
229 [self->otherTagString stringValueInComponent:
232 WOResponse_AddEmptyCloseParens(_response, _ctx);
237 - (NSString *)associationDescription {
238 NSMutableString *str = [NSMutableString stringWithCapacity:256];
240 if (self->action) [str appendFormat:@" action=%@", self->action];
241 if (self->href) [str appendFormat:@" href=%@", self->href];
242 if (self->pageName) [str appendFormat:@" pageName=%@", self->pageName];
243 if (self->fragmentIdentifier)
244 [str appendFormat:@" fragment=%@", self->fragmentIdentifier];
245 if (self->disabled) [str appendFormat:@" disabled=%@", self->disabled];
250 @end /* WOMetaRefresh */