]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/_WOCommonStaticDAHyperlink.m
started TAL element builder
[sope] / sope-appserver / NGObjWeb / DynamicElements / _WOCommonStaticDAHyperlink.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 "WOHyperlink.h"
23
24 @class NSString, NSDictionary;
25 @class WOElement, WOAssociation;
26
27 /*
28   Class Hierachy
29     [WOHTMLDynamicElement]
30       [WOHyperlink]
31         _WOCommonStaticDAHyperlink
32 */
33
34 @interface _WOCommonStaticDAHyperlink : WOHyperlink
35 {
36   NSString      *daName;
37   WOElement     *template;
38   WOAssociation *string;
39   NSDictionary  *queryParameters;  /* associations beginning with ? */
40   BOOL          sidInUrl;          /* include session-id in wa URL ? */
41 }
42 @end /* _WOCommonStaticDAHyperlink */
43
44 #include "WOHyperlinkInfo.h"
45 #include "WOElement+private.h"
46 #include <NGObjWeb/WOApplication.h>
47 #include <NGObjWeb/WOAssociation.h>
48 #include "decommon.h"
49
50 @implementation _WOCommonStaticDAHyperlink
51
52 - (id)initWithName:(NSString *)_name
53   hyperlinkInfo:(WOHyperlinkInfo *)_info
54   template:(WOElement *)_t
55 {
56   if ((self = [super initWithName:_name hyperlinkInfo:_info template:_t])) {
57     NSString *dc, *dn;
58     
59     self->template        = [_t retain];
60     self->string          = _info->string;
61     self->queryParameters = _info->queryParameters;
62     
63     dc = [_info->actionClass       stringValueInComponent:nil];
64     dn = [ _info->directActionName stringValueInComponent:nil];
65     
66     if (![dc isEqualToString:@"DirectAction"] && ([dc length] != 0))
67       self->daName = [[NSString alloc] initWithFormat:@"%@/%@", dc, dn];
68     else
69       self->daName = [dn copy];
70     
71     self->containsForm = NO;
72     self->sidInUrl     = _info->sidInUrl;
73   }
74   return self;
75 }
76
77 - (void)dealloc {
78   [self->daName   release];
79   [self->template release];
80   [self->string   release];
81   [self->queryParameters release];
82   [super dealloc];
83 }
84
85 /* responder */
86
87 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
88   WOComponent *sComponent;
89   NSMutableDictionary *qd;
90   
91   if ([[_ctx request] isFromClientComponent])
92     return;
93
94   sComponent = [_ctx component];
95   WOResponse_AddCString(_response, "<a href=\"");
96   
97   /* href */
98   if (self->queryParameters) {
99     NSEnumerator *keys;
100     NSString     *key;
101
102     qd = [NSMutableDictionary dictionaryWithCapacity:
103                                 [self->queryParameters count]];
104     keys = [self->queryParameters keyEnumerator];
105     while ((key = [keys nextObject])) {
106       id assoc, value;
107       
108       assoc = [self->queryParameters objectForKey:key];
109       value = [assoc stringValueInComponent:sComponent];
110           
111       [qd setObject:(value ? value : @"") forKey:key];
112     }
113   }
114   else
115     qd = nil;
116
117   /* add session ID */
118
119   if (self->sidInUrl) {
120     if ([_ctx hasSession]) {
121       WOSession *sn;
122       
123       if (qd == nil)
124         qd = [NSMutableDictionary dictionaryWithCapacity:2];
125       
126       sn = [_ctx session];
127       [qd setObject:[sn sessionID] forKey:WORequestValueSessionID];
128       
129       if (![sn isDistributionEnabled]) {
130         [qd setObject:[[WOApplication application] number]
131             forKey:WORequestValueInstance];
132       }
133     }
134   }
135   
136   WOResponse_AddString(_response,
137                        [_ctx directActionURLForActionNamed:self->daName
138                              queryDictionary:qd]);
139   
140   WOResponse_AddCString(_response, "\"");
141
142   [self appendExtraAttributesToResponse:_response inContext:_ctx];
143     
144   if (self->otherTagString) {
145     WOResponse_AddChar(_response, ' ');
146     WOResponse_AddString(_response,
147                          [self->otherTagString stringValueInComponent:
148                               [_ctx component]]);
149   }
150   [_response appendContentCharacter:'>'];
151
152   /* content */
153   
154   [self->template appendToResponse:_response inContext:_ctx];
155   
156   if (self->string) {
157     [_response appendContentHTMLString:
158                  [self->string stringValueInComponent:sComponent]];
159   }
160   
161   /* closing tag */
162   WOResponse_AddCString(_response, "</a>");
163 }
164
165 @end /* _WOCommonStaticDAHyperlink */