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

Last change on this file since 21808 was 21758, checked in by kjdon, 14 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
RevLine 
[649]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"
[12044]28#include "browsetoolsclass.h"
[15810]29#include "cgiutils.h"
[649]30
[15810]31
[649]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
[7392]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
[649]54void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
55 metadata.insert ("haschildren");
56 metadata.insert ("doctype");
57}
58
[668]59text_t vlistbrowserclass::get_default_formatstring () {
[10947]60 return "<td valign=\"top\">[link][icon][/link]</td>"
[11503]61 "<td valign=\"top\">[srclink]{Or}{[thumbicon],[srcicon]}[/srclink]</td>"
62 "<td valign=\"top\">[highlight]{Or}{[dls.Title],[dc.Title],[Title],Untitled}[/highlight]"
[2751]63 "{If}{[Source],<br><i>([Source])</i>}</td>";
[668]64}
65
[13366]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
[12044]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;
[649]96 text_t link, icon;
[747]97 text_t collink = collection;
[13366]98 bool show_links = show_search_result_links(collectproto,collection,logout);
[12001]99
[13366]100
[12001]101#ifndef DOCHANDLE
[10873]102 if (!collink.empty()) collink = "&amp;c=" + collink;
[12001]103#endif
[747]104
[13366]105 get_link_icon (section, args, collink, link, icon, show_links);
106
107 //get_link_icon (section, args, collink, link, icon);
108
[668]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;
[649]114
[668]115
[10947]116 /* use_table is set to true if the format string starts with <td> */
[668]117 if (use_table || colnumber > 0) {
[13451]118 if (colnumber > 0 ){
[18570]119 textout << outconvert << "<table id=\"toc_top\" class=\"v_list\"><tr valign=\"top\">";
[13451]120 }
121 else{
122 textout << outconvert << "<table id=\"toc_top\" class=\"v_list\"><tr valign=\"top\">";
123 }
124
[668]125 // get tab size
126 text_t tab; int itab;
[7433]127 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
[668]128 itab = tab.getint();
129 if (colnumber > 0) textout << outconvert << disp
[17860]130 << "<td><img alt=\"\" src=\"_httpiconspace_\" width=\""
[12488]131 << (itab*colnumber) << "\"/></td>";
[10947]132 } else {
133 textout << outconvert << "<div class=\"v_list\">\n";
[668]134 }
135
[4906]136 text_tmap options;
137 options["link"] = link;
138 options["icon"] = icon;
139 if (highlight) options["highlight"] = "1";
140 else options["highlight"] = "0";
[12044]141 options["DocImage"] = btools.get_cover_image();
[21758]142 options["assocfilepath"] = btools.get_assocfile_path();
[1443]143 textout << outconvert << disp
144 << get_formatted_string (collection, collectproto,
[1610]145 section, disp, formatlistptr,
[4906]146 options, logout);
[649]147
[10947]148 if (use_table || colnumber > 0) {
149 textout << outconvert << "</tr></table>\n";
150 } else {
151 textout << outconvert << "</div>\n";
152 }
[668]153
[649]154 return 1;
155}
156
[12044]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;
[668]166 text_t link, icon;
167 text_t &arg_d = args["d"];
168 text_t &arg_cl = args["cl"];
[13366]169
170 text_t collink = collection;
171 bool show_links = show_search_result_links(collectproto,collection,logout);
[668]172
[12001]173#ifndef DOCHANDLE
[10873]174 if (!collink.empty()) collink = "&amp;c=" + collink;
[12001]175#endif
[747]176
[668]177 if (colnumber > 0) {
[18562]178 textout << outconvert << "<table id=\"tabwidth\"><tr valign=\"top\">";
[649]179 // get tab size
180 text_t tab; int itab;
[7433]181 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
[649]182 itab = tab.getint();
183 if (colnumber > 0) textout << outconvert << disp
[17860]184 << "<td><img alt=\"\" src=\"_httpiconspace_\" width=\""
[12488]185 << (itab*colnumber) << "\"/></td>";
[3666]186 textout << outconvert << "<td>";
[649]187 }
188
[10947]189 /* use table set to true if format string starts with <td> */
190 if (use_table) {
[18562]191 textout << outconvert << "<table id=\"group_top\" class=\"v_list\">\n";
[10947]192 } else {
[18562]193 textout << outconvert << "<div id=\"group_top\" class=\"v_list\">\n";
[10947]194 }
195
[668]196 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
197 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
[649]198
[2899]199 // ** here lies Alan's hack to get 4 results per table row
[10947]200 int item = 0, perline; // set perline to 1 normally
[2899]201 text_t fstring;
[4906]202
203 text_tmap options;
204 options["link"] = link;
205 options["icon"] = icon;
206 options["highlight"] = "0";
[12044]207 options["DocImage"] = btools.get_cover_image();
[21758]208 options["assocfilepath"] = btools.get_assocfile_path();
209
[2899]210 if ( thissection != endsection ) { // only if there are results (else corrupts display)
[4906]211 fstring = get_formatted_string (collection, collectproto, *thissection,
212 disp, formatlistptr, options, logout);
[2899]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
[13366]222 int count = 0;
223
[668]224 while (thissection != endsection) {
[9620]225 ++item;
[13366]226 get_link_icon (*thissection, args, collink, link, icon,show_links);
227 //get_link_icon (*thissection, args, collink, link, icon);
[668]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
[2899]234 if ((item == 1 && use_table) || colnumber > 0 )
[3666]235 textout << outconvert << "<tr valign=top>\n";
[2899]236
[4906]237 options["link"] = link;
238 options["icon"] = icon;
239 if (highlight) options["highlight"] = "1";
240 else options["highlight"] = "0";
[12044]241 options["DocImage"] = btools.get_cover_image();
[21758]242 options["assocfilepath"] = btools.get_assocfile_path();
243
[1443]244 textout << outconvert << disp
[3543]245 << " " << get_formatted_string (collection, collectproto, *thissection, disp,
[4906]246 formatlistptr, options, logout);
[1443]247
[2899]248 if ((item >= perline && use_table) || colnumber > 0) {
[3666]249 textout << outconvert << "\n</tr>";
[2899]250 item = 0;
251 }
[3666]252 textout << outconvert << "\n";
[9620]253 ++thissection;
[668]254 }
255
[10947]256 if (use_table)
257 textout << outconvert << "</table>\n";
258 else
259 textout << outconvert << "</div>\n";
[4829]260 if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
[668]261
262 return 1;
[649]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.
[5124]268// [modification to allow default document detach settings -- kjdon]
[649]269void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
[13366]270 const text_t &collink, text_t &link, text_t &icon, bool showresultlinks) {
[649]271
[13366]272
273
[12001]274#ifndef DOCHANDLE
[747]275 link = "<a href=\"_httpdocument_" + collink;
[12001]276#else
277 link = "<a href=\"_httpdocumenthandle_(" + collink;
278#endif
279
[5124]280 text_t link_end = "\">";
[13366]281
[12001]282#ifndef DOCHANDLE
[10873]283 text_t detach_link_end = "&amp;x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
[12001]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
[649]288 icon = "_document:icontext_";
[5124]289
290 text_t doctype;
[824]291 int haschildren = 0;
[649]292
[824]293 if (section.metadata.count("haschildren")>0)
[934]294 haschildren = section.metadata["haschildren"].values[0].getint();
[824]295 if (section.metadata.count("doctype")>0)
[934]296 doctype = section.metadata["doctype"].values[0];
[824]297
[668]298 text_t &arg_d = args["d"];
299 text_t &arg_cl = args["cl"];
[15808]300
301 if (args["a"] == "q")
302 {
[5124]303 // query results list
[12001]304#ifndef DOCHANDLE
[13366]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;
[12001]321#else
322 link += "," + section.OID+")";
323#endif
[13366]324
[5124]325 if (args["xx"] == "1") {
326 link += detach_link_end;
[15808]327 }
328 else {
[5124]329 link += link_end;
330 }
[3065]331 if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
[15808]332 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
333 }
334 else if (!arg_d.empty()) {
[5124]335 // we are in a document - none of the links should be detach links
[649]336 if (is_top(section.OID)) {
[5124]337 // we link back to the originating page eg search page or classifier page
[649]338 icon = "_document:iconopenbook_";
[5124]339 if (arg_cl == "search") {
340 link = "<a href=\"_httpquery_\">";
341 }
[12001]342 else {
343#ifndef DOCHANDLE
344 link += "&amp;cl=" + arg_cl + "\">";
345#else
346 link += ","+arg_cl + ")\">";
347#endif
[15808]348 }
349 }
350 else if (haschildren == 1) {
[668]351 if ((args["gc"] == "1") ||
352 (is_child_of (section.OID, arg_d)) ||
353 (section.OID == arg_d)) {
[649]354 icon = "_document:iconopenfolder_";
[12001]355#ifndef DOCHANDLE
[10873]356 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + ".pr\">";
[12001]357#else
358 link += ","+section.OID + ".pr)\">";
359#endif
[15808]360 }
361 else {
[649]362 icon = "_document:iconclosedfolder_";
[12001]363#ifndef DOCHANDLE
[10873]364 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
[12001]365#else
366 link += ","+section.OID + ")\">";
367#endif
[649]368 }
[15808]369 }
370 else {
[3087]371 if (args["gt"] == "0") {
[12001]372#ifndef DOCHANDLE
[10873]373 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
[12001]374#else
375 link += ","+section.OID + ")\">";
376#endif
[15808]377 }
378 else {
[12001]379#ifndef DOCHANDLE
[10873]380 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "#" + section.OID + "\">";
[12001]381#else
382 link += ","+section.OID + "#" + section.OID + ")\">";
383#endif
[3087]384 }
385 }
[15808]386 }
387 else {
[5124]388 // classification level - links to docs may be detaching
[649]389 if (haschildren == 1) {
390 if (doctype == "classify") {
[15835]391 // Dynamic classifier nodes
392 if (args["a"] == "dc")
393 {
[15950]394 // Parent node or current node
395 text_t classifier_node_dcn = "";
396 if (!starts_with (section.OID, args["dcn"]) || section.OID == args["dcn"])
[15835]397 {
398 icon = "_document:iconopenbookshelf_";
[16065]399 classifier_node_dcn = section.OID + ".pr";
[15835]400 }
[15950]401 // Child node
[15835]402 else
403 {
404 icon = "_document:iconclosedbookshelf_";
[15950]405 classifier_node_dcn = section.OID;
406 }
[15835]407
[15950]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 + "\">";
[15835]411 }
412 // Static classifier nodes
413 else if ((args["gc"] == "1") ||
[668]414 (is_child_of (section.OID, arg_cl)) ||
415 (section.OID == arg_cl)) {
[649]416 icon = "_document:iconopenbookshelf_";
[12001]417
418#ifndef DOCHANDLE
[10873]419 link += "&amp;cl=" + section.OID + ".pr\">";
[12001]420#else
421 link += ","+section.OID + ".pr)\">";
422#endif
[15808]423 }
424 else {
[649]425 icon = "_document:iconclosedbookshelf_";
[12001]426
427#ifndef DOCHANDLE
[15835]428 link += "&amp;cl=" + section.OID + "\">";
[12001]429#else
430 link += ","+section.OID + ")\">";
431#endif
[649]432 }
[15808]433 }
434 else {
[649]435 icon = "_document:iconclosedbook_";
[12001]436#ifndef DOCHANDLE
[10873]437 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
[12001]438#else
439 link += ","+section.OID+")";
440#endif
[5124]441 if (args["xx"] == "1") {
442 link += detach_link_end;
[15808]443 }
444 else {
[5124]445 link += link_end;
446 }
[649]447 }
[15808]448 }
449 else {
[649]450 if (doctype == "classify") link = "";
[5124]451 else {
[12001]452#ifndef DOCHANDLE
[10873]453 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
[12001]454#else
455 link += "," + section.OID +")";
456#endif
[5124]457 if (args["xx"] == "1") {
458 link += detach_link_end;
[15808]459 }
460 else {
[5124]461 link += link_end;
462 }
463 }
[649]464 }
465 }
466}
Note: See TracBrowser for help on using the repository browser.