source: trunk/gsdl/src/recpt/extlinkaction.cpp@ 919

Last change on this file since 919 was 869, checked in by sjboddie, 24 years ago

lots of stuff

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/**********************************************************************
2 *
3 * extlinkaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26
27#include <string.h>
28#include "extlinkaction.h"
29#include "OIDtools.h"
30#include "cgiutils.h"
31
32extlinkaction::extlinkaction () {
33
34 // this action uses cgi variables "a", "d", and "href"
35
36 cgiarginfo arg_ainfo;
37 arg_ainfo.shortname = "a";
38 arg_ainfo.longname = "action";
39 arg_ainfo.multiplechar = true;
40 arg_ainfo.defaultstatus = cgiarginfo::weak;
41 arg_ainfo.argdefault = "extlink";
42 arg_ainfo.savedarginfo = cgiarginfo::must;
43 argsinfo.addarginfo (NULL, arg_ainfo);
44
45 arg_ainfo.shortname = "el";
46 arg_ainfo.longname = "external link preference";
47 arg_ainfo.multiplechar = true;
48 arg_ainfo.defaultstatus = cgiarginfo::weak;
49 arg_ainfo.argdefault = "prompt";
50 arg_ainfo.savedarginfo = cgiarginfo::must;
51 argsinfo.addarginfo (NULL, arg_ainfo);
52
53 arg_ainfo.shortname = "d";
54 arg_ainfo.longname = "document OID";
55 arg_ainfo.multiplechar = true;
56 arg_ainfo.defaultstatus = cgiarginfo::none;
57 arg_ainfo.argdefault = "";
58 arg_ainfo.savedarginfo = cgiarginfo::can;
59 argsinfo.addarginfo (NULL, arg_ainfo);
60
61 arg_ainfo.shortname = "href";
62 arg_ainfo.longname = "URL of external link";
63 arg_ainfo.multiplechar = true;
64 arg_ainfo.defaultstatus = cgiarginfo::none;
65 arg_ainfo.argdefault = "";
66 arg_ainfo.savedarginfo = cgiarginfo::can;
67 argsinfo.addarginfo (NULL, arg_ainfo);
68
69 arg_ainfo.shortname = "rl";
70 arg_ainfo.longname = "is relative link";
71 arg_ainfo.multiplechar = false;
72 arg_ainfo.defaultstatus = cgiarginfo::none;
73 arg_ainfo.argdefault = "0";
74 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
75 argsinfo.addarginfo (NULL, arg_ainfo);
76
77}
78
79extlinkaction::~extlinkaction () {
80}
81
82
83void extlinkaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
84 response_t &response, text_t &response_data,
85 ostream &logout) {
86
87 text_t link;
88 if (get_link (args, protos, link, logout)) {
89 response = location;
90 response_data = link;
91 return;
92 }
93
94 // external link
95 if (!link.empty()) {
96 if (args["el"] == "direct") {
97 response = location;
98 response_data = link;
99 return;
100 }
101 }
102
103 response = content;
104 response_data = "text/html";
105}
106
107void extlinkaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
108 recptprotolistclass * /*protos*/,
109 ostream &/*logout*/) {
110
111 // define_internal_macros sets the following macros:
112
113 // _nexturl_ link to external page
114 // _prevdoc_ link to previous document
115
116 disp.setmacro("nexturl", "extlink", args["href"]);
117 disp.setmacro("prevdoc", "extlink", args["d"]);
118}
119
120
121// if link is found returns true and url in link, otherwise returns
122// false
123bool extlinkaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
124 text_t &link, ostream &logout) {
125
126 text_t &arg_href = args["href"];
127 text_t &thiscollection = args["c"];
128 if (arg_href.empty()) return false;
129
130 if (args["rl"] == "1") {
131
132 FilterResponse_t response;
133 text_tset metadata;
134 metadata.insert ("section");
135
136 recptproto *collectproto = protos->getrecptproto (thiscollection, logout);
137
138 if (get_info (arg_href, thiscollection, metadata, false, collectproto, response, logout)) {
139 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
140 link = "_httpdoc_&d=" + response.docInfo[0].metadata["section"].values[0];
141 return true;
142 }
143 }
144
145 // need to see if link exists in any other collection
146 // if cross-collection searching/browsing is turned on
147 if (args["ccs"] == "1" && !args["cc"].empty()) {
148 text_tarray collections;
149 splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
150
151 text_tarray::const_iterator col_here = collections.begin();
152 text_tarray::const_iterator col_end = collections.end();
153
154 while (col_here != col_end) {
155
156 // don't need to check current collection again
157 if (*col_here == thiscollection) {col_here ++; continue;}
158
159 recptproto *collectproto = protos->getrecptproto (*col_here, logout);
160 if (collectproto == NULL) {col_here ++; continue;}
161
162 if (get_info (arg_href, *col_here, metadata, false, collectproto, response, logout)) {
163 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
164 link = "_httpdoc_&c=" + *col_here + "&d=" +
165 response.docInfo[0].metadata["section"].values[0];
166 return true;
167 }
168 }
169 col_here ++;
170 }
171 }
172 return false;
173
174 } else {
175 // link is external
176 link = arg_href;
177 return false;
178 }
179}
180
181
182bool extlinkaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
183 browsermapclass * /*browsers*/, displayclass &disp,
184 outconvertclass &outconvert, ostream &textout,
185 ostream &logout) {
186
187 if (args["href"].empty()) {
188 // oops, this shouldn't happen
189 textout << outconvert << disp << ("_extlink:header_\n")
190 << ("_extlink:notfoundcontent_\n")
191 << ("_extlink:footer_\n");
192 return true;
193 }
194
195 if (args["rl"] == "1") {
196 // need to see if link exists in any other collection
197 // if cross-collection searching/browsing is turned on
198 if (args["ccs"] == "1" && !args["cc"].empty()) {
199
200 FilterResponse_t response;
201 text_tset metadata;
202 metadata.insert ("section");
203 text_tarray collections;
204 splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
205
206 text_tarray::const_iterator col_here = collections.begin();
207 text_tarray::const_iterator col_end = collections.end();
208
209 while (col_here != col_end) {
210
211 // don't need to check current collection
212 if (*col_here == args["c"]) {col_here ++; continue;}
213
214 recptproto *collectproto = protos->getrecptproto (*col_here, logout);
215
216 if (get_info (args["href"], *col_here, metadata, false, collectproto, response, logout)) {
217 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
218 text_t collectionname = *col_here;
219 metadata.erase (metadata.begin(), metadata.end());
220 metadata.insert ("collectionname");
221 FilterResponse_t nresponse;
222 if (get_info ("collection", *col_here, metadata, false, collectproto, nresponse, logout)) {
223 if (!nresponse.docInfo[0].metadata["collectionname"].values[0].empty())
224 collectionname = nresponse.docInfo[0].metadata["collectionname"].values[0];
225 }
226 textout << outconvert << disp << ("_extlink:header_\n")
227 << ("_extlink:foundintcontent_(" + *col_here + ", " + collectionname +
228 ", " + response.docInfo[0].metadata["section"].values[0] + "\n")
229 << ("_extlink:footer_\n");
230 return true;
231 }
232 }
233 col_here ++;
234 }
235 }
236 textout << outconvert << disp << ("_extlink:header_\n")
237 << ("_extlink:notfoundcontent_\n")
238 << ("_extlink:footer_\n");
239
240
241 } else {
242 // link is external
243 textout << outconvert << disp << ("_extlink:header_\n")
244 << ("_extlink:foundcontent_\n")
245 << ("_extlink:footer_\n");
246 }
247
248 return true;
249}
250
251
Note: See TracBrowser for help on using the repository browser.