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

Last change on this file since 13451 was 13451, checked in by shaoqun, 17 years ago

added id=toc_top to the toppest level table of the table of contents

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