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 <NGObjWeb/WODynamicElement.h>
27 This element is pretty similiar to WOHyperlink with the "pageName" binding,
28 but in addition allows for parameters being passed to the page.
30 WEPageLink associations:
33 sync (either array of names or a string with names seperated by ',')
36 @class WOAssociation, WOElement;
39 @interface WEPageLink : WODynamicElement
41 // WODynamicElement: otherTagString
43 WOAssociation *pageName;
44 WOAssociation *syncBindings;
55 @implementation WEPageLink
58 return [super version] + 0 /* v2 */;
61 NSAssert2([super version] == 2,
62 @"invalid superclass (%@) version %i !",
63 NSStringFromClass([self superclass]), [super version]);
66 - (id)initWithName:(NSString *)_name
67 associations:(NSDictionary *)_config
68 template:(WOElement *)_t
70 if ((self = [super initWithName:_name associations:_config template:_t])) {
71 NSMutableArray *mkeys, *massocs;
75 self->pageName = WOExtGetProperty(_config, @"pageName");
76 self->syncBindings = WOExtGetProperty(_config, @"sync");
77 self->template = [_t retain];
79 self->keyCount = [_config count];
80 mkeys = [[NSMutableArray alloc] initWithCapacity:self->keyCount];
81 massocs = [[NSMutableArray alloc] initWithCapacity:self->keyCount];
83 e = [_config keyEnumerator];
84 while ((k = [e nextObject])) {
86 [massocs addObject:[_config objectForKey:k]];
88 self->keys = [mkeys copy]; [mkeys release];
89 self->assocs = [massocs copy]; [massocs release];
91 [(NSMutableDictionary *)_config removeAllObjects];
97 [self->syncBindings release];
98 [self->template release];
99 [self->pageName release];
100 [self->keys release];
101 [self->assocs release];
105 /* handling requests */
107 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
108 WOComponent *page, *sComponent;
113 if (![[_ctx elementID] isEqualToString:[_ctx senderID]])
114 /* link is not the active element */
115 return [self->template invokeActionForRequest:_rq inContext:_ctx];
117 /* link is the active element */
119 sComponent = [_ctx component];
120 name = [self->pageName stringValueInComponent:sComponent];
121 page = [[_ctx application] pageWithName:name inContext:_ctx];
124 [self logWithFormat:@"did not find page with name '%@'.", name];
128 /* apply sync bindings */
130 if ((sync = [self->syncBindings valueInComponent:sComponent])) {
133 if (![sync isKindOfClass:[NSArray class]])
134 sync = [[sync stringValue] componentsSeparatedByString:@","];
136 // Note: we cannot use keypathes in a useful way here because we reuse
137 // the key for assignment
138 for (i = 0, count = [sync count]; i < count; i++) {
142 key = [sync objectAtIndex:i];
143 value = [sComponent valueForKey:key];
144 [page takeValue:value forKey:key];
150 for (i = 0; i < self->keyCount; i++) {
153 value = [[self->assocs objectAtIndex:i] valueInComponent:sComponent];
154 [page takeValue:value forKey:[self->keys objectAtIndex:i]];
160 /* response generation */
162 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
165 href = [_ctx componentActionURL];
166 [_response appendContentCString:(unsigned char *)"<a href=\""];
167 [_response appendContentString:href];
168 [_response appendContentCharacter:'"'];
170 if (self->otherTagString) {
171 [_response appendContentCharacter:' '];
172 [_response appendContentString:
173 [self->otherTagString stringValueInComponent:[_ctx component]]];
175 [_response appendContentCharacter:'>'];
177 [self->template appendToResponse:_response inContext:_ctx];
178 [_response appendContentCString:(unsigned char *)"</a>"];
181 @end /* WEPageLink */