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 |
|
---|
32 | vlistbrowserclass::vlistbrowserclass () {
|
---|
33 | }
|
---|
34 |
|
---|
35 | vlistbrowserclass::~vlistbrowserclass () {
|
---|
36 | }
|
---|
37 |
|
---|
38 | // returns the name that specifies the browserclass type
|
---|
39 | text_t vlistbrowserclass::get_browser_name () {
|
---|
40 | return "VList";
|
---|
41 | }
|
---|
42 |
|
---|
43 | browserclass* 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 |
|
---|
54 | void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
|
---|
55 | metadata.insert ("haschildren");
|
---|
56 | metadata.insert ("doctype");
|
---|
57 | }
|
---|
58 |
|
---|
59 | text_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 |
|
---|
66 | bool 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 |
|
---|
87 | int vlistbrowserclass::output_section_group(ResultDocInfo_t §ion, 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 = "&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 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=\"_httpimg_/space.gif\" 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 | textout << outconvert << disp
|
---|
143 | << get_formatted_string (collection, collectproto,
|
---|
144 | section, disp, formatlistptr,
|
---|
145 | options, logout);
|
---|
146 |
|
---|
147 | if (use_table || colnumber > 0) {
|
---|
148 | textout << outconvert << "</tr></table>\n";
|
---|
149 | } else {
|
---|
150 | textout << outconvert << "</div>\n";
|
---|
151 | }
|
---|
152 |
|
---|
153 | return 1;
|
---|
154 | }
|
---|
155 |
|
---|
156 | int vlistbrowserclass::output_section_group(FilterResponse_t §ions, 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;
|
---|
165 | text_t link, icon;
|
---|
166 | text_t &arg_d = args["d"];
|
---|
167 | text_t &arg_cl = args["cl"];
|
---|
168 |
|
---|
169 | text_t collink = collection;
|
---|
170 | bool show_links = show_search_result_links(collectproto,collection,logout);
|
---|
171 |
|
---|
172 | #ifndef DOCHANDLE
|
---|
173 | if (!collink.empty()) collink = "&c=" + collink;
|
---|
174 | #endif
|
---|
175 |
|
---|
176 | if (colnumber > 0) {
|
---|
177 | textout << outconvert << "<table><tr valign=\"top\">";
|
---|
178 | // get tab size
|
---|
179 | text_t tab; int itab;
|
---|
180 | disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
|
---|
181 | itab = tab.getint();
|
---|
182 | if (colnumber > 0) textout << outconvert << disp
|
---|
183 | << "<td><img alt=\"\" src=\"_httpimg_/space.gif\" width=\""
|
---|
184 | << (itab*colnumber) << "\"/></td>";
|
---|
185 | textout << outconvert << "<td>";
|
---|
186 | }
|
---|
187 |
|
---|
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 |
|
---|
195 | ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
|
---|
196 | ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
|
---|
197 |
|
---|
198 | // ** here lies Alan's hack to get 4 results per table row
|
---|
199 | int item = 0, perline; // set perline to 1 normally
|
---|
200 | text_t fstring;
|
---|
201 |
|
---|
202 | text_tmap options;
|
---|
203 | options["link"] = link;
|
---|
204 | options["icon"] = icon;
|
---|
205 | options["highlight"] = "0";
|
---|
206 | options["DocImage"] = btools.get_cover_image();
|
---|
207 |
|
---|
208 | if ( thissection != endsection ) { // only if there are results (else corrupts display)
|
---|
209 | fstring = get_formatted_string (collection, collectproto, *thissection,
|
---|
210 | disp, formatlistptr, options, logout);
|
---|
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 |
|
---|
220 | int count = 0;
|
---|
221 |
|
---|
222 | while (thissection != endsection) {
|
---|
223 | ++item;
|
---|
224 | get_link_icon (*thissection, args, collink, link, icon,show_links);
|
---|
225 | //get_link_icon (*thissection, args, collink, link, icon);
|
---|
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 |
|
---|
232 | if ((item == 1 && use_table) || colnumber > 0 )
|
---|
233 | textout << outconvert << "<tr valign=top>\n";
|
---|
234 |
|
---|
235 | options["link"] = link;
|
---|
236 | options["icon"] = icon;
|
---|
237 | if (highlight) options["highlight"] = "1";
|
---|
238 | else options["highlight"] = "0";
|
---|
239 | options["DocImage"] = btools.get_cover_image();
|
---|
240 |
|
---|
241 | textout << outconvert << disp
|
---|
242 | << " " << get_formatted_string (collection, collectproto, *thissection, disp,
|
---|
243 | formatlistptr, options, logout);
|
---|
244 |
|
---|
245 | if ((item >= perline && use_table) || colnumber > 0) {
|
---|
246 | textout << outconvert << "\n</tr>";
|
---|
247 | item = 0;
|
---|
248 | }
|
---|
249 | textout << outconvert << "\n";
|
---|
250 | ++thissection;
|
---|
251 | }
|
---|
252 |
|
---|
253 | if (use_table)
|
---|
254 | textout << outconvert << "</table>\n";
|
---|
255 | else
|
---|
256 | textout << outconvert << "</div>\n";
|
---|
257 | if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
|
---|
258 |
|
---|
259 | return 1;
|
---|
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.
|
---|
265 | // [modification to allow default document detach settings -- kjdon]
|
---|
266 | void vlistbrowserclass::get_link_icon (ResultDocInfo_t §ion, cgiargsclass &args,
|
---|
267 | const text_t &collink, text_t &link, text_t &icon, bool showresultlinks) {
|
---|
268 |
|
---|
269 |
|
---|
270 |
|
---|
271 | #ifndef DOCHANDLE
|
---|
272 | link = "<a href=\"_httpdocument_" + collink;
|
---|
273 | #else
|
---|
274 | link = "<a href=\"_httpdocumenthandle_(" + collink;
|
---|
275 | #endif
|
---|
276 |
|
---|
277 | text_t link_end = "\">";
|
---|
278 |
|
---|
279 | #ifndef DOCHANDLE
|
---|
280 | text_t detach_link_end = "&x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
|
---|
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 |
|
---|
285 | icon = "_document:icontext_";
|
---|
286 |
|
---|
287 | text_t doctype;
|
---|
288 | int haschildren = 0;
|
---|
289 |
|
---|
290 | if (section.metadata.count("haschildren")>0)
|
---|
291 | haschildren = section.metadata["haschildren"].values[0].getint();
|
---|
292 | if (section.metadata.count("doctype")>0)
|
---|
293 | doctype = section.metadata["doctype"].values[0];
|
---|
294 |
|
---|
295 | text_t &arg_d = args["d"];
|
---|
296 | text_t &arg_cl = args["cl"];
|
---|
297 |
|
---|
298 | if (args["a"] == "q")
|
---|
299 | {
|
---|
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 +="&srp="+srp_t;
|
---|
316 | link +="&srn="+srn_t;
|
---|
317 | link +="&cl=search&d=" + section.OID;
|
---|
318 | #else
|
---|
319 | link += "," + section.OID+")";
|
---|
320 | #endif
|
---|
321 |
|
---|
322 | if (args["xx"] == "1") {
|
---|
323 | link += detach_link_end;
|
---|
324 | }
|
---|
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 += "&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 += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
|
---|
354 | #else
|
---|
355 | link += ","+section.OID + ".pr)\">";
|
---|
356 | #endif
|
---|
357 | }
|
---|
358 | else {
|
---|
359 | icon = "_document:iconclosedfolder_";
|
---|
360 | #ifndef DOCHANDLE
|
---|
361 | link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
362 | #else
|
---|
363 | link += ","+section.OID + ")\">";
|
---|
364 | #endif
|
---|
365 | }
|
---|
366 | }
|
---|
367 | else {
|
---|
368 | if (args["gt"] == "0") {
|
---|
369 | #ifndef DOCHANDLE
|
---|
370 | link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
371 | #else
|
---|
372 | link += ","+section.OID + ")\">";
|
---|
373 | #endif
|
---|
374 | }
|
---|
375 | else {
|
---|
376 | #ifndef DOCHANDLE
|
---|
377 | link += "&cl=" + arg_cl + "&d=" + section.OID + "#" + section.OID + "\">";
|
---|
378 | #else
|
---|
379 | link += ","+section.OID + "#" + section.OID + ")\">";
|
---|
380 | #endif
|
---|
381 | }
|
---|
382 | }
|
---|
383 | }
|
---|
384 | else {
|
---|
385 | // classification level - links to docs may be detaching
|
---|
386 | if (haschildren == 1) {
|
---|
387 | if (doctype == "classify") {
|
---|
388 | // Dynamic classifier nodes
|
---|
389 | if (args["a"] == "dc")
|
---|
390 | {
|
---|
391 | // Parent node or current node
|
---|
392 | text_t classifier_node_dcn = "";
|
---|
393 | if (!starts_with (section.OID, args["dcn"]) || section.OID == args["dcn"])
|
---|
394 | {
|
---|
395 | icon = "_document:iconopenbookshelf_";
|
---|
396 |
|
---|
397 | // dcn value is the OID of this node's parent
|
---|
398 | text_t::iterator hierarchy_split_position = findchar(section.OID.begin(), section.OID.end(), '|');
|
---|
399 | if (hierarchy_split_position != section.OID.end())
|
---|
400 | {
|
---|
401 | classifier_node_dcn = substr (section.OID.begin(), hierarchy_split_position);
|
---|
402 | }
|
---|
403 | }
|
---|
404 | // Child node
|
---|
405 | else
|
---|
406 | {
|
---|
407 | icon = "_document:iconclosedbookshelf_";
|
---|
408 | classifier_node_dcn = section.OID;
|
---|
409 | }
|
---|
410 |
|
---|
411 | // The node label is going into the URL, so make it CGI-safe
|
---|
412 | text_t classifier_node_dcn_cgi_safe = cgi_safe_utf8(classifier_node_dcn);
|
---|
413 | link = "<a href=\"_gwcgi_?c=" + args["c"] + "&a=dc&dcl=" + args["dcl"] + "&dcn=" + classifier_node_dcn_cgi_safe + "\">";
|
---|
414 | }
|
---|
415 | // Static classifier nodes
|
---|
416 | else if ((args["gc"] == "1") ||
|
---|
417 | (is_child_of (section.OID, arg_cl)) ||
|
---|
418 | (section.OID == arg_cl)) {
|
---|
419 | icon = "_document:iconopenbookshelf_";
|
---|
420 |
|
---|
421 | #ifndef DOCHANDLE
|
---|
422 | link += "&cl=" + section.OID + ".pr\">";
|
---|
423 | #else
|
---|
424 | link += ","+section.OID + ".pr)\">";
|
---|
425 | #endif
|
---|
426 | }
|
---|
427 | else {
|
---|
428 | icon = "_document:iconclosedbookshelf_";
|
---|
429 |
|
---|
430 | #ifndef DOCHANDLE
|
---|
431 | link += "&cl=" + section.OID + "\">";
|
---|
432 | #else
|
---|
433 | link += ","+section.OID + ")\">";
|
---|
434 | #endif
|
---|
435 | }
|
---|
436 | }
|
---|
437 | else {
|
---|
438 | icon = "_document:iconclosedbook_";
|
---|
439 | #ifndef DOCHANDLE
|
---|
440 | link += "&cl=" + arg_cl + "&d=" + section.OID;
|
---|
441 | #else
|
---|
442 | link += ","+section.OID+")";
|
---|
443 | #endif
|
---|
444 | if (args["xx"] == "1") {
|
---|
445 | link += detach_link_end;
|
---|
446 | }
|
---|
447 | else {
|
---|
448 | link += link_end;
|
---|
449 | }
|
---|
450 | }
|
---|
451 | }
|
---|
452 | else {
|
---|
453 | if (doctype == "classify") link = "";
|
---|
454 | else {
|
---|
455 | #ifndef DOCHANDLE
|
---|
456 | link += "&cl=" + arg_cl + "&d=" + section.OID;
|
---|
457 | #else
|
---|
458 | link += "," + section.OID +")";
|
---|
459 | #endif
|
---|
460 | if (args["xx"] == "1") {
|
---|
461 | link += detach_link_end;
|
---|
462 | }
|
---|
463 | else {
|
---|
464 | link += link_end;
|
---|
465 | }
|
---|
466 | }
|
---|
467 | }
|
---|
468 | }
|
---|
469 | }
|
---|