source: main/trunk/greenstone2/runtime-src/src/recpt/vlistbrowserclass.cpp@ 21758

Last change on this file since 21758 was 21758, checked in by kjdon, 13 years ago

now we dynamically generate srclink (and /srclink, and new srchref which is the link without the a tag), using srclink_file metadata. This is to get gs2 receptionist stuff out of metadata and into the source code where it belongs

  • Property svn:keywords set to Author Date Id Revision
File size: 14.0 KB
Line 
1/**********************************************************************
2 *
3 * vlistbrowserclass.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#include "vlistbrowserclass.h"
27#include "OIDtools.h"
28#include "browsetoolsclass.h"
29#include "cgiutils.h"
30
31
32vlistbrowserclass::vlistbrowserclass () {
33}
34
35vlistbrowserclass::~vlistbrowserclass () {
36}
37
38// returns the name that specifies the browserclass type
39text_t vlistbrowserclass::get_browser_name () {
40 return "VList";
41}
42
43browserclass* vlistbrowserclass::clone()
44{
45 vlistbrowserclass* browser = new vlistbrowserclass();
46 if (browser != NULL) {
47#ifdef GSDL_USE_BY_BOOK_MACROS
48 browser->m_oByBookMacros.Copy(m_oByBookMacros);
49#endif
50 }
51 return browser;
52}
53
54void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
55 metadata.insert ("haschildren");
56 metadata.insert ("doctype");
57}
58
59text_t vlistbrowserclass::get_default_formatstring () {
60 return "<td valign=\"top\">[link][icon][/link]</td>"
61 "<td valign=\"top\">[srclink]{Or}{[thumbicon],[srcicon]}[/srclink]</td>"
62 "<td valign=\"top\">[highlight]{Or}{[dls.Title],[dc.Title],[Title],Untitled}[/highlight]"
63 "{If}{[Source],<br><i>([Source])</i>}</td>";
64}
65
66bool vlistbrowserclass::show_search_result_links(recptproto * collectproto,const text_t &collection,ostream& logout){
67 ColInfoResponse_t cinfo;
68 comerror_t err;
69 collectproto->get_collectinfo (collection, cinfo, err, logout);
70 bool show_links = false;
71
72 text_tmap::const_iterator format_here = cinfo.format.begin();
73 text_tmap::const_iterator format_end = cinfo.format.end();
74
75 while (format_here != format_end) {
76 if (((*format_here).first == "DocumentSearchResultLinks") &&
77 ((*format_here).second == "true")){
78 show_links = true;
79 break;
80 }
81 ++format_here;
82 }
83
84 return show_links;
85}
86
87int vlistbrowserclass::output_section_group(ResultDocInfo_t &section, cgiargsclass &args,
88 const text_t &collection, int colnumber,
89 format_t *formatlistptr, bool use_table,
90 text_tset &metadata, bool &getParents,
91 recptproto * collectproto, displayclass &disp,
92 outconvertclass &outconvert, ostream &textout,
93 ostream& logout)
94{
95 browsetoolsclass btools;
96 text_t link, icon;
97 text_t collink = collection;
98 bool show_links = show_search_result_links(collectproto,collection,logout);
99
100
101#ifndef DOCHANDLE
102 if (!collink.empty()) collink = "&amp;c=" + collink;
103#endif
104
105 get_link_icon (section, args, collink, link, icon, show_links);
106
107 //get_link_icon (section, args, collink, link, icon);
108
109 bool highlight = false;
110 if (!args["d"].empty()) {
111 if (args["d"] == section.OID) highlight = true;
112 } else
113 if (args["cl"] == section.OID) highlight = true;
114
115
116 /* use_table is set to true if the format string starts with <td> */
117 if (use_table || colnumber > 0) {
118 if (colnumber > 0 ){
119 textout << outconvert << "<table id=\"toc_top\" class=\"v_list\"><tr valign=\"top\">";
120 }
121 else{
122 textout << outconvert << "<table id=\"toc_top\" class=\"v_list\"><tr valign=\"top\">";
123 }
124
125 // get tab size
126 text_t tab; int itab;
127 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
128 itab = tab.getint();
129 if (colnumber > 0) textout << outconvert << disp
130 << "<td><img alt=\"\" src=\"_httpiconspace_\" width=\""
131 << (itab*colnumber) << "\"/></td>";
132 } else {
133 textout << outconvert << "<div class=\"v_list\">\n";
134 }
135
136 text_tmap options;
137 options["link"] = link;
138 options["icon"] = icon;
139 if (highlight) options["highlight"] = "1";
140 else options["highlight"] = "0";
141 options["DocImage"] = btools.get_cover_image();
142 options["assocfilepath"] = btools.get_assocfile_path();
143 textout << outconvert << disp
144 << get_formatted_string (collection, collectproto,
145 section, disp, formatlistptr,
146 options, logout);
147
148 if (use_table || colnumber > 0) {
149 textout << outconvert << "</tr></table>\n";
150 } else {
151 textout << outconvert << "</div>\n";
152 }
153
154 return 1;
155}
156
157int vlistbrowserclass::output_section_group(FilterResponse_t &sections, cgiargsclass &args,
158 const text_t &collection, int colnumber,
159 format_t *formatlistptr, bool use_table,
160 text_tset &/*metadata*/, bool &/*getParents*/,
161 recptproto * collectproto, displayclass &disp,
162 outconvertclass &outconvert, ostream &textout,
163 ostream& logout)
164{
165 browsetoolsclass btools;
166 text_t link, icon;
167 text_t &arg_d = args["d"];
168 text_t &arg_cl = args["cl"];
169
170 text_t collink = collection;
171 bool show_links = show_search_result_links(collectproto,collection,logout);
172
173#ifndef DOCHANDLE
174 if (!collink.empty()) collink = "&amp;c=" + collink;
175#endif
176
177 if (colnumber > 0) {
178 textout << outconvert << "<table id=\"tabwidth\"><tr valign=\"top\">";
179 // get tab size
180 text_t tab; int itab;
181 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
182 itab = tab.getint();
183 if (colnumber > 0) textout << outconvert << disp
184 << "<td><img alt=\"\" src=\"_httpiconspace_\" width=\""
185 << (itab*colnumber) << "\"/></td>";
186 textout << outconvert << "<td>";
187 }
188
189 /* use table set to true if format string starts with <td> */
190 if (use_table) {
191 textout << outconvert << "<table id=\"group_top\" class=\"v_list\">\n";
192 } else {
193 textout << outconvert << "<div id=\"group_top\" class=\"v_list\">\n";
194 }
195
196 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
197 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
198
199 // ** here lies Alan's hack to get 4 results per table row
200 int item = 0, perline; // set perline to 1 normally
201 text_t fstring;
202
203 text_tmap options;
204 options["link"] = link;
205 options["icon"] = icon;
206 options["highlight"] = "0";
207 options["DocImage"] = btools.get_cover_image();
208 options["assocfilepath"] = btools.get_assocfile_path();
209
210 if ( thissection != endsection ) { // only if there are results (else corrupts display)
211 fstring = get_formatted_string (collection, collectproto, *thissection,
212 disp, formatlistptr, options, logout);
213 // if format string
214 // has <td><t (e.g. <td><table>) then
215 // we assume it is an image and put it in 4 columns
216 if (fstring[5] == 't')
217 perline = 4;
218 else
219 perline = 1;
220 }
221
222 int count = 0;
223
224 while (thissection != endsection) {
225 ++item;
226 get_link_icon (*thissection, args, collink, link, icon,show_links);
227 //get_link_icon (*thissection, args, collink, link, icon);
228 bool highlight = false;
229 if (!arg_d.empty()) {
230 if (arg_d == (*thissection).OID) highlight = true;
231 } else
232 if (arg_cl == (*thissection).OID) highlight = true;
233
234 if ((item == 1 && use_table) || colnumber > 0 )
235 textout << outconvert << "<tr valign=top>\n";
236
237 options["link"] = link;
238 options["icon"] = icon;
239 if (highlight) options["highlight"] = "1";
240 else options["highlight"] = "0";
241 options["DocImage"] = btools.get_cover_image();
242 options["assocfilepath"] = btools.get_assocfile_path();
243
244 textout << outconvert << disp
245 << " " << get_formatted_string (collection, collectproto, *thissection, disp,
246 formatlistptr, options, logout);
247
248 if ((item >= perline && use_table) || colnumber > 0) {
249 textout << outconvert << "\n</tr>";
250 item = 0;
251 }
252 textout << outconvert << "\n";
253 ++thissection;
254 }
255
256 if (use_table)
257 textout << outconvert << "</table>\n";
258 else
259 textout << outconvert << "</div>\n";
260 if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
261
262 return 1;
263}
264
265
266// get_link_icon attempts to work out what type of icon should be displayed for
267// the given section and what it should link to.
268// [modification to allow default document detach settings -- kjdon]
269void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
270 const text_t &collink, text_t &link, text_t &icon, bool showresultlinks) {
271
272
273
274#ifndef DOCHANDLE
275 link = "<a href=\"_httpdocument_" + collink;
276#else
277 link = "<a href=\"_httpdocumenthandle_(" + collink;
278#endif
279
280 text_t link_end = "\">";
281
282#ifndef DOCHANDLE
283 text_t detach_link_end = "&amp;x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
284#else
285 text_t detach_link_end = "\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
286#endif
287
288 icon = "_document:icontext_";
289
290 text_t doctype;
291 int haschildren = 0;
292
293 if (section.metadata.count("haschildren")>0)
294 haschildren = section.metadata["haschildren"].values[0].getint();
295 if (section.metadata.count("doctype")>0)
296 doctype = section.metadata["doctype"].values[0];
297
298 text_t &arg_d = args["d"];
299 text_t &arg_cl = args["cl"];
300
301 if (args["a"] == "q")
302 {
303 // query results list
304#ifndef DOCHANDLE
305 int result_num = section.result_num;
306 int num_docs = args["nmd"].getint();
307 int srn = 0;
308 int srp = 0;
309 if (showresultlinks && result_num < num_docs) {
310 srn = result_num + 1;
311 }
312 if (showresultlinks && result_num > 1 ) {
313 srp = result_num - 1;
314 }
315
316 text_t srp_t = srp;
317 text_t srn_t = srn;
318 link +="&amp;srp="+srp_t;
319 link +="&amp;srn="+srn_t;
320 link +="&amp;cl=search&amp;d=" + section.OID;
321#else
322 link += "," + section.OID+")";
323#endif
324
325 if (args["xx"] == "1") {
326 link += detach_link_end;
327 }
328 else {
329 link += link_end;
330 }
331 if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
332 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
333 }
334 else if (!arg_d.empty()) {
335 // we are in a document - none of the links should be detach links
336 if (is_top(section.OID)) {
337 // we link back to the originating page eg search page or classifier page
338 icon = "_document:iconopenbook_";
339 if (arg_cl == "search") {
340 link = "<a href=\"_httpquery_\">";
341 }
342 else {
343#ifndef DOCHANDLE
344 link += "&amp;cl=" + arg_cl + "\">";
345#else
346 link += ","+arg_cl + ")\">";
347#endif
348 }
349 }
350 else if (haschildren == 1) {
351 if ((args["gc"] == "1") ||
352 (is_child_of (section.OID, arg_d)) ||
353 (section.OID == arg_d)) {
354 icon = "_document:iconopenfolder_";
355#ifndef DOCHANDLE
356 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + ".pr\">";
357#else
358 link += ","+section.OID + ".pr)\">";
359#endif
360 }
361 else {
362 icon = "_document:iconclosedfolder_";
363#ifndef DOCHANDLE
364 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
365#else
366 link += ","+section.OID + ")\">";
367#endif
368 }
369 }
370 else {
371 if (args["gt"] == "0") {
372#ifndef DOCHANDLE
373 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
374#else
375 link += ","+section.OID + ")\">";
376#endif
377 }
378 else {
379#ifndef DOCHANDLE
380 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "#" + section.OID + "\">";
381#else
382 link += ","+section.OID + "#" + section.OID + ")\">";
383#endif
384 }
385 }
386 }
387 else {
388 // classification level - links to docs may be detaching
389 if (haschildren == 1) {
390 if (doctype == "classify") {
391 // Dynamic classifier nodes
392 if (args["a"] == "dc")
393 {
394 // Parent node or current node
395 text_t classifier_node_dcn = "";
396 if (!starts_with (section.OID, args["dcn"]) || section.OID == args["dcn"])
397 {
398 icon = "_document:iconopenbookshelf_";
399 classifier_node_dcn = section.OID + ".pr";
400 }
401 // Child node
402 else
403 {
404 icon = "_document:iconclosedbookshelf_";
405 classifier_node_dcn = section.OID;
406 }
407
408 // The node label is going into the URL, so make it CGI-safe
409 text_t classifier_node_dcn_cgi_safe = cgi_safe_utf8(classifier_node_dcn);
410 link = "<a href=\"_gwcgi_?c=" + args["c"] + "&amp;a=dc&amp;dcl=" + args["dcl"] + "&amp;dcn=" + classifier_node_dcn_cgi_safe + "\">";
411 }
412 // Static classifier nodes
413 else if ((args["gc"] == "1") ||
414 (is_child_of (section.OID, arg_cl)) ||
415 (section.OID == arg_cl)) {
416 icon = "_document:iconopenbookshelf_";
417
418#ifndef DOCHANDLE
419 link += "&amp;cl=" + section.OID + ".pr\">";
420#else
421 link += ","+section.OID + ".pr)\">";
422#endif
423 }
424 else {
425 icon = "_document:iconclosedbookshelf_";
426
427#ifndef DOCHANDLE
428 link += "&amp;cl=" + section.OID + "\">";
429#else
430 link += ","+section.OID + ")\">";
431#endif
432 }
433 }
434 else {
435 icon = "_document:iconclosedbook_";
436#ifndef DOCHANDLE
437 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
438#else
439 link += ","+section.OID+")";
440#endif
441 if (args["xx"] == "1") {
442 link += detach_link_end;
443 }
444 else {
445 link += link_end;
446 }
447 }
448 }
449 else {
450 if (doctype == "classify") link = "";
451 else {
452#ifndef DOCHANDLE
453 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
454#else
455 link += "," + section.OID +")";
456#endif
457 if (args["xx"] == "1") {
458 link += detach_link_end;
459 }
460 else {
461 link += link_end;
462 }
463 }
464 }
465 }
466}
Note: See TracBrowser for help on using the repository browser.