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 "WOHyperlink.h"
26 [WOHTMLDynamicElement]
28 _WOSimpleActionHyperlink
29 _WOSimpleStringActionHyperlink
32 @interface _WOSimpleActionHyperlink : WOHyperlink
34 WOAssociation *action;
37 @end /* _WOSimpleActionHyperlink */
39 @interface _WOSimpleStringActionHyperlink : _WOSimpleActionHyperlink
41 WOAssociation *string;
43 @end /* _WOSimpleStringActionHyperlink */
45 #include "WOHyperlinkInfo.h"
46 #include "WOElement+private.h"
47 #include <NGObjWeb/WOAssociation.h>
50 @implementation _WOSimpleActionHyperlink
53 return [super version] + 0 /* v4 */;
56 NSAssert2([super version] == 4,
57 @"invalid superclass (%@) version %i !",
58 NSStringFromClass([self superclass]), [super version]);
61 - (id)initWithName:(NSString *)_name
62 hyperlinkInfo:(WOHyperlinkInfo *)_info
63 template:(WOElement *)_t
65 if ((self = [super initWithName:_name hyperlinkInfo:_info template:_t])) {
66 self->template = RETAIN(_t);
67 self->containsForm = NO;
68 self->action = _info->action;
70 NSAssert(self->action, @"missing action ?!");
77 [self->template release];
78 [self->action release];
82 /* dynamic invocation */
84 - (id)invokeActionForRequest:(WORequest *)_request
85 inContext:(WOContext *)_ctx
87 if (![[_ctx elementID] isEqualToString:[_ctx senderID]]) {
88 /* link is not the active element */
90 NSLog(@"HYPERLINK is not active (%@ vs %@) !",
91 [_ctx elementID], [_ctx senderID]);
93 return [self->template invokeActionForRequest:_request inContext:_ctx];
96 //NSLog(@"%s: invoke called ...", __PRETTY_FUNCTION__);
99 return [self executeAction:self->action inContext:_ctx];
102 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
103 if ([[_ctx request] isFromClientComponent])
106 WOResponse_AddCString(_response, "<a href=\"");
107 WOResponse_AddString(_response, [_ctx componentActionURL]);
109 [_response appendContentCharacter:'"'];
111 [self appendExtraAttributesToResponse:_response inContext:_ctx];
112 if (self->otherTagString) {
113 WOResponse_AddChar(_response, ' ');
114 WOResponse_AddString(_response,
115 [self->otherTagString stringValueInComponent:
118 [_response appendContentCharacter:'>'];
121 [self->template appendToResponse:_response inContext:_ctx];
124 WOResponse_AddCString(_response, "</a>");
129 - (NSString *)associationDescription {
130 return [NSString stringWithFormat:@"action=%@", self->action];
133 @end /* _WOSimpleActionHyperlink */
135 @implementation _WOSimpleStringActionHyperlink
137 - (id)initWithName:(NSString *)_name
138 hyperlinkInfo:(WOHyperlinkInfo *)_info
139 template:(WOElement *)_t
141 if ((self = [super initWithName:_name hyperlinkInfo:_info template:_t])) {
142 self->string = _info->string;
148 [self->string release];
152 /* HTML generation */
154 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
155 WOComponent *sComponent;
158 if ([[_ctx request] isFromClientComponent])
161 sComponent = [_ctx component];
162 content = [self->string stringValueInComponent:sComponent];
164 WOResponse_AddCString(_response, "<a href=\"");
165 WOResponse_AddString(_response, [_ctx componentActionURL]);
167 [_response appendContentCharacter:'"'];
169 [self appendExtraAttributesToResponse:_response inContext:_ctx];
171 if (self->otherTagString) {
172 WOResponse_AddChar(_response, ' ');
173 WOResponse_AddString(_response,
174 [self->otherTagString stringValueInComponent:
177 [_response appendContentCharacter:'>'];
180 [self->template appendToResponse:_response inContext:_ctx];
181 if (content) [_response appendContentHTMLString:content];
184 WOResponse_AddCString(_response, "</a>");
189 - (NSString *)associationDescription {
190 return [NSString stringWithFormat:@"action=%@, string=%@",
191 self->action, self->string];
194 @end /* _WOSimpleStringActionHyperlink */