source: gsdl/trunk/src/recpt/vlistbrowserclass.cpp@ 16065

Last change on this file since 16065 was 16065, checked in by mdewsnip, 16 years ago

(Adding dynamic classifiers) Changed the links generated for parent/current classifier nodes in vlistbrowserclass to use ".pr" instead of trying to work out the parent OID, to avoid this code needing to know about hierarchy separators.

Added code in dynamicclassifieraction for resolving the ".pr" bits.

  • Property svn:keywords set to Author Date Id Revision
File size: 13.7 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 ){
119 textout << outconvert << "<table class=\"v_list\"><tr valign=\"top\">";
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
[12488]130 << "<td><img alt=\"\" src=\"_httpimg_/space.gif\" width=\""
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();
[1443]142 textout << outconvert << disp
143 << get_formatted_string (collection, collectproto,
[1610]144 section, disp, formatlistptr,
[4906]145 options, logout);
[649]146
[10947]147 if (use_table || colnumber > 0) {
148 textout << outconvert << "</tr></table>\n";
149 } else {
150 textout << outconvert << "</div>\n";
151 }
[668]152
[649]153 return 1;
154}
155
[12044]156int vlistbrowserclass::output_section_group(FilterResponse_t &sections, cgiargsclass &args,
157 const text_t &collection, int colnumber,
158 format_t *formatlistptr, bool use_table,
159 text_tset &/*metadata*/, bool &/*getParents*/,
160 recptproto * collectproto, displayclass &disp,
161 outconvertclass &outconvert, ostream &textout,
162 ostream& logout)
163{
164 browsetoolsclass btools;
[668]165 text_t link, icon;
166 text_t &arg_d = args["d"];
167 text_t &arg_cl = args["cl"];
[13366]168
169 text_t collink = collection;
170 bool show_links = show_search_result_links(collectproto,collection,logout);
[668]171
[12001]172#ifndef DOCHANDLE
[10873]173 if (!collink.empty()) collink = "&amp;c=" + collink;
[12001]174#endif
[747]175
[668]176 if (colnumber > 0) {
[10947]177 textout << outconvert << "<table><tr valign=\"top\">";
[649]178 // get tab size
179 text_t tab; int itab;
[7433]180 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
[649]181 itab = tab.getint();
182 if (colnumber > 0) textout << outconvert << disp
[12488]183 << "<td><img alt=\"\" src=\"_httpimg_/space.gif\" width=\""
184 << (itab*colnumber) << "\"/></td>";
[3666]185 textout << outconvert << "<td>";
[649]186 }
187
[10947]188 /* use table set to true if format string starts with <td> */
189 if (use_table) {
190 textout << outconvert << "<table class=\"v_list\">\n";
191 } else {
192 textout << outconvert << "<div class=\"v_list\">\n";
193 }
194
[668]195 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
196 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
[649]197
[2899]198 // ** here lies Alan's hack to get 4 results per table row
[10947]199 int item = 0, perline; // set perline to 1 normally
[2899]200 text_t fstring;
[4906]201
202 text_tmap options;
203 options["link"] = link;
204 options["icon"] = icon;
205 options["highlight"] = "0";
[12044]206 options["DocImage"] = btools.get_cover_image();
[4936]207
[2899]208 if ( thissection != endsection ) { // only if there are results (else corrupts display)
[4906]209 fstring = get_formatted_string (collection, collectproto, *thissection,
210 disp, formatlistptr, options, logout);
[2899]211 // if format string
212 // has <td><t (e.g. <td><table>) then
213 // we assume it is an image and put it in 4 columns
214 if (fstring[5] == 't')
215 perline = 4;
216 else
217 perline = 1;
218 }
219
[13366]220 int count = 0;
221
[668]222 while (thissection != endsection) {
[9620]223 ++item;
[13366]224 get_link_icon (*thissection, args, collink, link, icon,show_links);
225 //get_link_icon (*thissection, args, collink, link, icon);
[668]226 bool highlight = false;
227 if (!arg_d.empty()) {
228 if (arg_d == (*thissection).OID) highlight = true;
229 } else
230 if (arg_cl == (*thissection).OID) highlight = true;
231
[2899]232 if ((item == 1 && use_table) || colnumber > 0 )
[3666]233 textout << outconvert << "<tr valign=top>\n";
[2899]234
[4906]235 options["link"] = link;
236 options["icon"] = icon;
237 if (highlight) options["highlight"] = "1";
238 else options["highlight"] = "0";
[12044]239 options["DocImage"] = btools.get_cover_image();
[4906]240
[1443]241 textout << outconvert << disp
[3543]242 << " " << get_formatted_string (collection, collectproto, *thissection, disp,
[4906]243 formatlistptr, options, logout);
[1443]244
[2899]245 if ((item >= perline && use_table) || colnumber > 0) {
[3666]246 textout << outconvert << "\n</tr>";
[2899]247 item = 0;
248 }
[3666]249 textout << outconvert << "\n";
[9620]250 ++thissection;
[668]251 }
252
[10947]253 if (use_table)
254 textout << outconvert << "</table>\n";
255 else
256 textout << outconvert << "</div>\n";
[4829]257 if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
[668]258
259 return 1;
[649]260}
261
262
263// get_link_icon attempts to work out what type of icon should be displayed for
264// the given section and what it should link to.
[5124]265// [modification to allow default document detach settings -- kjdon]
[649]266void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
[13366]267 const text_t &collink, text_t &link, text_t &icon, bool showresultlinks) {
[649]268
[13366]269
270
[12001]271#ifndef DOCHANDLE
[747]272 link = "<a href=\"_httpdocument_" + collink;
[12001]273#else
274 link = "<a href=\"_httpdocumenthandle_(" + collink;
275#endif
276
[5124]277 text_t link_end = "\">";
[13366]278
[12001]279#ifndef DOCHANDLE
[10873]280 text_t detach_link_end = "&amp;x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
[12001]281#else
282 text_t detach_link_end = "\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
283#endif
284
[649]285 icon = "_document:icontext_";
[5124]286
287 text_t doctype;
[824]288 int haschildren = 0;
[649]289
[824]290 if (section.metadata.count("haschildren")>0)
[934]291 haschildren = section.metadata["haschildren"].values[0].getint();
[824]292 if (section.metadata.count("doctype")>0)
[934]293 doctype = section.metadata["doctype"].values[0];
[824]294
[668]295 text_t &arg_d = args["d"];
296 text_t &arg_cl = args["cl"];
[15808]297
298 if (args["a"] == "q")
299 {
[5124]300 // query results list
[12001]301#ifndef DOCHANDLE
[13366]302 int result_num = section.result_num;
303 int num_docs = args["nmd"].getint();
304 int srn = 0;
305 int srp = 0;
306 if (showresultlinks && result_num < num_docs) {
307 srn = result_num + 1;
308 }
309 if (showresultlinks && result_num > 1 ) {
310 srp = result_num - 1;
311 }
312
313 text_t srp_t = srp;
314 text_t srn_t = srn;
315 link +="&amp;srp="+srp_t;
316 link +="&amp;srn="+srn_t;
317 link +="&amp;cl=search&amp;d=" + section.OID;
[12001]318#else
319 link += "," + section.OID+")";
320#endif
[13366]321
[5124]322 if (args["xx"] == "1") {
323 link += detach_link_end;
[15808]324 }
325 else {
[5124]326 link += link_end;
327 }
[3065]328 if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
[15808]329 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
330 }
331 else if (!arg_d.empty()) {
[5124]332 // we are in a document - none of the links should be detach links
[649]333 if (is_top(section.OID)) {
[5124]334 // we link back to the originating page eg search page or classifier page
[649]335 icon = "_document:iconopenbook_";
[5124]336 if (arg_cl == "search") {
337 link = "<a href=\"_httpquery_\">";
338 }
[12001]339 else {
340#ifndef DOCHANDLE
341 link += "&amp;cl=" + arg_cl + "\">";
342#else
343 link += ","+arg_cl + ")\">";
344#endif
[15808]345 }
346 }
347 else if (haschildren == 1) {
[668]348 if ((args["gc"] == "1") ||
349 (is_child_of (section.OID, arg_d)) ||
350 (section.OID == arg_d)) {
[649]351 icon = "_document:iconopenfolder_";
[12001]352#ifndef DOCHANDLE
[10873]353 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + ".pr\">";
[12001]354#else
355 link += ","+section.OID + ".pr)\">";
356#endif
[15808]357 }
358 else {
[649]359 icon = "_document:iconclosedfolder_";
[12001]360#ifndef DOCHANDLE
[10873]361 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
[12001]362#else
363 link += ","+section.OID + ")\">";
364#endif
[649]365 }
[15808]366 }
367 else {
[3087]368 if (args["gt"] == "0") {
[12001]369#ifndef DOCHANDLE
[10873]370 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
[12001]371#else
372 link += ","+section.OID + ")\">";
373#endif
[15808]374 }
375 else {
[12001]376#ifndef DOCHANDLE
[10873]377 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "#" + section.OID + "\">";
[12001]378#else
379 link += ","+section.OID + "#" + section.OID + ")\">";
380#endif
[3087]381 }
382 }
[15808]383 }
384 else {
[5124]385 // classification level - links to docs may be detaching
[649]386 if (haschildren == 1) {
387 if (doctype == "classify") {
[15835]388 // Dynamic classifier nodes
389 if (args["a"] == "dc")
390 {
[15950]391 // Parent node or current node
392 text_t classifier_node_dcn = "";
393 if (!starts_with (section.OID, args["dcn"]) || section.OID == args["dcn"])
[15835]394 {
395 icon = "_document:iconopenbookshelf_";
[16065]396 classifier_node_dcn = section.OID + ".pr";
[15835]397 }
[15950]398 // Child node
[15835]399 else
400 {
401 icon = "_document:iconclosedbookshelf_";
[15950]402 classifier_node_dcn = section.OID;
403 }
[15835]404
[15950]405 // The node label is going into the URL, so make it CGI-safe
406 text_t classifier_node_dcn_cgi_safe = cgi_safe_utf8(classifier_node_dcn);
407 link = "<a href=\"_gwcgi_?c=" + args["c"] + "&amp;a=dc&amp;dcl=" + args["dcl"] + "&amp;dcn=" + classifier_node_dcn_cgi_safe + "\">";
[15835]408 }
409 // Static classifier nodes
410 else if ((args["gc"] == "1") ||
[668]411 (is_child_of (section.OID, arg_cl)) ||
412 (section.OID == arg_cl)) {
[649]413 icon = "_document:iconopenbookshelf_";
[12001]414
415#ifndef DOCHANDLE
[10873]416 link += "&amp;cl=" + section.OID + ".pr\">";
[12001]417#else
418 link += ","+section.OID + ".pr)\">";
419#endif
[15808]420 }
421 else {
[649]422 icon = "_document:iconclosedbookshelf_";
[12001]423
424#ifndef DOCHANDLE
[15835]425 link += "&amp;cl=" + section.OID + "\">";
[12001]426#else
427 link += ","+section.OID + ")\">";
428#endif
[649]429 }
[15808]430 }
431 else {
[649]432 icon = "_document:iconclosedbook_";
[12001]433#ifndef DOCHANDLE
[10873]434 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
[12001]435#else
436 link += ","+section.OID+")";
437#endif
[5124]438 if (args["xx"] == "1") {
439 link += detach_link_end;
[15808]440 }
441 else {
[5124]442 link += link_end;
443 }
[649]444 }
[15808]445 }
446 else {
[649]447 if (doctype == "classify") link = "";
[5124]448 else {
[12001]449#ifndef DOCHANDLE
[10873]450 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
[12001]451#else
452 link += "," + section.OID +")";
453#endif
[5124]454 if (args["xx"] == "1") {
455 link += detach_link_end;
[15808]456 }
457 else {
[5124]458 link += link_end;
459 }
460 }
[649]461 }
462 }
463}
Note: See TracBrowser for help on using the repository browser.