2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
23 #include <NGObjWeb/WODynamicElement.h>
28 This element is pretty similiar to WOHyperlink with the "pageName" binding,
29 but in addition allows for parameters being passed to the page.
31 WEPageLink associations:
34 sync (either array of names or a string with names seperated by ',')
37 @class WOAssociation, WOElement;
40 @interface WEPageLink : WODynamicElement
42 // WODynamicElement: otherTagString
44 WOAssociation *pageName;
45 WOAssociation *syncBindings;
56 @implementation WEPageLink
59 return [super version] + 0 /* v2 */;
62 NSAssert2([super version] == 2,
63 @"invalid superclass (%@) version %i !",
64 NSStringFromClass([self superclass]), [super version]);
67 - (id)initWithName:(NSString *)_name
68 associations:(NSDictionary *)_config
69 template:(WOElement *)_t
71 if ((self = [super initWithName:_name associations:_config template:_t])) {
72 NSMutableArray *mkeys, *massocs;
76 self->pageName = WOExtGetProperty(_config, @"pageName");
77 self->syncBindings = WOExtGetProperty(_config, @"sync");
78 self->template = [_t retain];
80 self->keyCount = [_config count];
81 mkeys = [[NSMutableArray alloc] initWithCapacity:self->keyCount];
82 massocs = [[NSMutableArray alloc] initWithCapacity:self->keyCount];
84 e = [_config keyEnumerator];
85 while ((k = [e nextObject])) {
87 [massocs addObject:[_config objectForKey:k]];
89 self->keys = [mkeys copy]; [mkeys release];
90 self->assocs = [massocs copy]; [massocs release];
92 [(NSMutableDictionary *)_config removeAllObjects];
98 [self->syncBindings release];
99 [self->template release];
100 [self->pageName release];
101 [self->keys release];
102 [self->assocs release];
106 /* handling requests */
108 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
109 WOComponent *page, *sComponent;
114 if (![[_ctx elementID] isEqualToString:[_ctx senderID]])
115 /* link is not the active element */
116 return [self->template invokeActionForRequest:_rq inContext:_ctx];
118 /* link is the active element */
120 sComponent = [_ctx component];
121 name = [self->pageName stringValueInComponent:sComponent];
122 page = [[_ctx application] pageWithName:name inContext:_ctx];
125 [self logWithFormat:@"did not find page with name '%@'.", name];
129 /* apply sync bindings */
131 if ((sync = [self->syncBindings valueInComponent:sComponent])) {
134 if (![sync isKindOfClass:[NSArray class]])
135 sync = [[sync stringValue] componentsSeparatedByString:@","];
137 // Note: we cannot use keypathes in a useful way here because we reuse
138 // the key for assignment
139 for (i = 0, count = [sync count]; i < count; i++) {
143 key = [sync objectAtIndex:i];
144 value = [sComponent valueForKey:key];
145 [page takeValue:value forKey:key];
151 for (i = 0; i < self->keyCount; i++) {
154 value = [[self->assocs objectAtIndex:i] valueInComponent:sComponent];
155 [page takeValue:value forKey:[self->keys objectAtIndex:i]];
161 /* response generation */
163 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
166 href = [_ctx componentActionURL];
167 [_response appendContentCString:"<a href=\""];
168 [_response appendContentString:href];
169 [_response appendContentCharacter:'"'];
171 if (self->otherTagString) {
174 s = [self->otherTagString stringValueInComponent:[_ctx component]];
175 [_response appendContentString:s];
177 [_response appendContentCharacter:'>'];
179 [self->template appendToResponse:_response inContext:_ctx];
180 [_response appendContentCString:"</a>"];
183 @end /* WEPageLink */