]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/_WOCommonStaticDAHyperlink.m
added svn:keywords and svn:ignore where appropriate. removed CVS artifacts.
[sope] / sope-appserver / NGObjWeb / DynamicElements / _WOCommonStaticDAHyperlink.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "WOHyperlink.h"
24
25 @class NSString, NSDictionary;
26 @class WOElement, WOAssociation;
27
28 /*
29   Class Hierachy
30     [WOHTMLDynamicElement]
31       [WOHyperlink]
32         _WOCommonStaticDAHyperlink
33 */
34
35 @interface _WOCommonStaticDAHyperlink : WOHyperlink
36 {
37   NSString      *daName;
38   WOElement     *template;
39   WOAssociation *string;
40   NSDictionary  *queryParameters;  /* associations beginning with ? */
41   BOOL          sidInUrl;          /* include session-id in wa URL ? */
42 }
43 @end /* _WOCommonStaticDAHyperlink */
44
45 #include "WOHyperlinkInfo.h"
46 #include "WOElement+private.h"
47 #include <NGObjWeb/WOApplication.h>
48 #include <NGObjWeb/WOAssociation.h>
49 #include "common.h"
50
51 @implementation _WOCommonStaticDAHyperlink
52
53 - (id)initWithName:(NSString *)_name
54   hyperlinkInfo:(WOHyperlinkInfo *)_info
55   template:(WOElement *)_t
56 {
57   if ((self = [super initWithName:_name hyperlinkInfo:_info template:_t])) {
58     NSString *dc, *dn;
59     
60     self->template        = [_t retain];
61     self->string          = _info->string;
62     self->queryParameters = _info->queryParameters;
63     
64     dc = [_info->actionClass       stringValueInComponent:nil];
65     dn = [ _info->directActionName stringValueInComponent:nil];
66     
67     if (![dc isEqualToString:@"DirectAction"] && ([dc length] != 0))
68       self->daName = [[NSString alloc] initWithFormat:@"%@/%@", dc, dn];
69     else
70       self->daName = [dn copy];
71     
72     self->containsForm = NO;
73     self->sidInUrl     = _info->sidInUrl;
74   }
75   return self;
76 }
77
78 - (void)dealloc {
79   [self->daName   release];
80   [self->template release];
81   [self->string   release];
82   [self->queryParameters release];
83   [super dealloc];
84 }
85
86 /* responder */
87
88 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
89   WOComponent *sComponent;
90   NSMutableDictionary *qd;
91   
92   if ([[_ctx request] isFromClientComponent])
93     return;
94
95   sComponent = [_ctx component];
96   WOResponse_AddCString(_response, "<a href=\"");
97   
98   /* href */
99   if (self->queryParameters) {
100     NSEnumerator *keys;
101     NSString     *key;
102
103     qd = [NSMutableDictionary dictionaryWithCapacity:
104                                 [self->queryParameters count]];
105     keys = [self->queryParameters keyEnumerator];
106     while ((key = [keys nextObject])) {
107       id assoc, value;
108       
109       assoc = [self->queryParameters objectForKey:key];
110       value = [assoc stringValueInComponent:sComponent];
111           
112       [qd setObject:(value ? value : @"") forKey:key];
113     }
114   }
115   else
116     qd = nil;
117
118   /* add session ID */
119
120   if (self->sidInUrl) {
121     if ([_ctx hasSession]) {
122       WOSession *sn;
123       
124       if (qd == nil)
125         qd = [NSMutableDictionary dictionaryWithCapacity:2];
126       
127       sn = [_ctx session];
128       [qd setObject:[sn sessionID] forKey:WORequestValueSessionID];
129       
130       if (![sn isDistributionEnabled]) {
131         [qd setObject:[[WOApplication application] number]
132             forKey:WORequestValueInstance];
133       }
134     }
135   }
136   
137   WOResponse_AddString(_response,
138                        [_ctx directActionURLForActionNamed:self->daName
139                              queryDictionary:qd]);
140   
141   WOResponse_AddCString(_response, "\"");
142
143   [self appendExtraAttributesToResponse:_response inContext:_ctx];
144     
145   if (self->otherTagString) {
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 */