]> err.no Git - sope/blob - sope-appserver/WOExtensions/WORedirect.m
updated framework version
[sope] / sope-appserver / WOExtensions / WORedirect.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "WORedirect.h"
23 #include "common.h"
24
25 @implementation WORedirect
26
27 - (void)dealloc {
28   [self->url release];
29   [super dealloc];
30 }
31
32 /* accessors */
33
34 - (void)setURL:(id)_url {
35   [self setUrl:_url];
36 }
37
38 - (void)setUrl:(id)_url {
39   ASSIGNCOPY(self->url, _url);
40 }
41 - (id)url {
42   return self->url;
43 }
44
45 /* handling requests (do nothing, avoid loading of template) */
46
47 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
48 }
49 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
50   [self logWithFormat:@"WARNING: called %s on WORedirect!", 
51           __PRETTY_FUNCTION__];
52   return nil;
53 }
54
55 /* generating the response */
56
57 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
58   NSString *loc;
59   
60   if (![self->url isNotNull]) {
61     [self logWithFormat:@"ERROR: missing URL for redirect!"];
62     return;
63   }
64   
65   if ([self->url isKindOfClass:[NSURL class]])
66     loc = [self->url absoluteString];
67   else
68     loc = [self->url stringValue];
69
70   if ([loc length] == 0) {
71     [self logWithFormat:@"ERROR: got invalid URL for redirect: '%@'(%@)", 
72             self->url, NSStringFromClass([self->url class])];
73     return;
74   }
75   
76   [_response setStatus:302 /* temporarily moved */];
77   [_response setHeader:loc forKey:@"location"];
78 }
79
80 @end /* WORedirect */