source: main/tags/2.40/gsdl/src/recpt/documentaction.cpp@ 25097

Last change on this file since 25097 was 4774, checked in by sjboddie, 21 years ago

No longer show search page (or search form on "about" page) if a collection
doesn't have at least one searchable index. Note that this change includes
the addition of an is_searchable() function to the protocol.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 33.4 KB
Line 
1/**********************************************************************
2 *
3 * documentaction.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 <string.h>
27#include "documentaction.h"
28#include "browsetools.h"
29#include "OIDtools.h"
30#include "querytools.h"
31#include "unitool.h"
32#include "gsdltools.h"
33#include "highlighttext.h"
34
35documentaction::documentaction () {
36 recpt = NULL;
37
38
39 // this action uses cgi variables "a", "d", "cl",
40 // "x", "gc", "gt", "gp", and "hl"
41 cgiarginfo arg_ainfo;
42 arg_ainfo.shortname = "a";
43 arg_ainfo.longname = "action";
44 arg_ainfo.multiplechar = true;
45 arg_ainfo.defaultstatus = cgiarginfo::weak;
46 arg_ainfo.argdefault = "p";
47 arg_ainfo.savedarginfo = cgiarginfo::must;
48 argsinfo.addarginfo (NULL, arg_ainfo);
49
50 arg_ainfo.shortname = "d";
51 arg_ainfo.longname = "document OID";
52 arg_ainfo.multiplechar = true;
53 arg_ainfo.defaultstatus = cgiarginfo::none;
54 arg_ainfo.argdefault = "";
55 arg_ainfo.savedarginfo = cgiarginfo::can;
56 argsinfo.addarginfo (NULL, arg_ainfo);
57
58 // whether or not a document should be retrieved from the
59 // library or the Web.
60 arg_ainfo.shortname = "il";
61 arg_ainfo.longname = "internal link preference";
62 arg_ainfo.multiplechar = false;
63 arg_ainfo.defaultstatus = cgiarginfo::weak;
64 arg_ainfo.argdefault = "l";
65 arg_ainfo.savedarginfo = cgiarginfo::must;
66 argsinfo.addarginfo (NULL, arg_ainfo);
67
68 arg_ainfo.shortname = "cl";
69 arg_ainfo.longname = "classification OID";
70 arg_ainfo.multiplechar = true;
71 arg_ainfo.defaultstatus = cgiarginfo::none;
72 arg_ainfo.argdefault = "";
73 arg_ainfo.savedarginfo = cgiarginfo::can;
74 argsinfo.addarginfo (NULL, arg_ainfo);
75
76 // in this action "gc" controls the expand/contract
77 // contents function
78 arg_ainfo.shortname = "gc";
79 arg_ainfo.longname = "expand contents";
80 arg_ainfo.multiplechar = false;
81 arg_ainfo.defaultstatus = cgiarginfo::weak;
82 arg_ainfo.argdefault = "0";
83 arg_ainfo.savedarginfo = cgiarginfo::can;
84 argsinfo.addarginfo (NULL, arg_ainfo);
85
86 // in this action "gt" controls the expand/contract
87 // text function 0 = not expanded, 1 = expand unless
88 // there are more than 10 sections containing text,
89 // 2 = expand all
90 arg_ainfo.shortname = "gt";
91 arg_ainfo.longname = "expand text";
92 arg_ainfo.multiplechar = false;
93 arg_ainfo.defaultstatus = cgiarginfo::weak;
94 arg_ainfo.argdefault = "0";
95 arg_ainfo.savedarginfo = cgiarginfo::can;
96 argsinfo.addarginfo (NULL, arg_ainfo);
97
98 // in this action "gp" is the "go to page" control
99 // used by the Book type of toc
100 arg_ainfo.shortname = "gp";
101 arg_ainfo.longname = "go to page";
102 arg_ainfo.multiplechar = true;
103 arg_ainfo.defaultstatus = cgiarginfo::none;
104 arg_ainfo.argdefault = "";
105 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
106 argsinfo.addarginfo (NULL, arg_ainfo);
107
108 // in this action "hl" is the "highlighting on/
109 // highlighting off control ("hl" == "2" is a
110 // special case that forces phrase highlighting
111 // to be used even if the query string doesn't
112 // appear to be a phrase)
113 arg_ainfo.shortname = "hl";
114 arg_ainfo.longname = "highlighting on/off";
115 arg_ainfo.multiplechar = false;
116 arg_ainfo.defaultstatus = cgiarginfo::weak;
117 arg_ainfo.argdefault = "1";
118 arg_ainfo.savedarginfo = cgiarginfo::must;
119 argsinfo.addarginfo (NULL, arg_ainfo);
120
121 // "x" is 0 normally or 1 if page
122 // has been "detached"
123 arg_ainfo.shortname = "x";
124 arg_ainfo.longname = "detached page";
125 arg_ainfo.multiplechar = false;
126 arg_ainfo.defaultstatus = cgiarginfo::weak;
127 arg_ainfo.argdefault = "0";
128 arg_ainfo.savedarginfo = cgiarginfo::must;
129 argsinfo.addarginfo (NULL, arg_ainfo);
130
131 // f arg is set to 1 if document is to
132 // be displayed in a frame
133 arg_ainfo.shortname = "f";
134 arg_ainfo.longname = "frame";
135 arg_ainfo.multiplechar = false;
136 arg_ainfo.defaultstatus = cgiarginfo::weak;
137 arg_ainfo.argdefault = "0";
138 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
139 argsinfo.addarginfo (NULL, arg_ainfo);
140
141 // fc arg is "1" if search bar is to be included (i.e. if "fc" == 1
142 // the httpdocument macro will include "&f=1"
143 arg_ainfo.shortname = "fc";
144 arg_ainfo.longname = "include search bar";
145 arg_ainfo.multiplechar = false;
146 arg_ainfo.defaultstatus = cgiarginfo::weak;
147 arg_ainfo.argdefault = "1";
148 arg_ainfo.savedarginfo = cgiarginfo::must;
149 argsinfo.addarginfo (NULL, arg_ainfo);
150
151 //rd is whether a document will be displayed
152 //with a relevant document list
153 arg_ainfo.shortname = "rd";
154 arg_ainfo.longname = "include relevant documents";
155 arg_ainfo.multiplechar = false;
156 arg_ainfo.defaultstatus = cgiarginfo::weak;
157 arg_ainfo.argdefault = "0";
158 arg_ainfo.savedarginfo = cgiarginfo::must;
159 argsinfo.addarginfo (NULL, arg_ainfo);
160
161}
162
163documentaction::~documentaction () {
164}
165
166bool documentaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
167 recptprotolistclass * /*protos*/, ostream &logout) {
168
169 // check gc argument
170 int arg_gc = args.getintarg("gc");
171 if (arg_gc < 0 || arg_gc > 2) {
172 logout << "Warning: \"gc\" argument out of range (" << arg_gc << ")\n";
173 cgiarginfo *gcinfo = argsinfo.getarginfo ("gc");
174 if (gcinfo != NULL) args["gc"] = gcinfo->argdefault;
175 }
176
177 // check gt argument (may be either 0, 1 or 2)
178 int arg_gt = args.getintarg("gt");
179 if (arg_gt != 0 && arg_gt != 1 && arg_gt != 2) {
180 logout << "Warning: \"gt\" argument out of range (" << arg_gt << ")\n";
181 cgiarginfo *gtinfo = argsinfo.getarginfo ("gt");
182 if (gtinfo != NULL) args["gt"] = gtinfo->argdefault;
183 }
184
185 // check hl argument
186 int arg_hl = args.getintarg("hl");
187 if (arg_hl < 0 || arg_hl > 2) {
188 logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n";
189 cgiarginfo *hlinfo = argsinfo.getarginfo ("hl");
190 if (hlinfo != NULL) args["hl"] = hlinfo->argdefault;
191 }
192
193 // check x argument
194 int arg_x = args.getintarg("x");
195 if (arg_x != 0 && arg_x != 1) {
196 logout << "Warning: \"x\" argument out of range (" << arg_x << ")\n";
197 cgiarginfo *xinfo = argsinfo.getarginfo ("x");
198 if (xinfo != NULL) args["x"] = xinfo->argdefault;
199 }
200
201 //checks whether rd arg is valid
202 int arg_rd = args.getintarg("rd");
203 if (arg_rd != 0 && arg_rd != 1) {
204 logout << "Warning: \"rd\" argument out of range (" << arg_rd << ")\n";
205 cgiarginfo *rdinfo = argsinfo.getarginfo ("rd");
206 if (rdinfo != NULL) args["rd"] = rdinfo->argdefault;
207 }
208
209
210 return true;
211}
212
213void documentaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
214 response_t &response,text_t &response_data,
215 ostream &logout) {
216
217 if ((args["il"] == "w") && (!args["d"].empty())) {
218
219 recptproto* collectproto = protos->getrecptproto (args["c"], logout);
220 if (collectproto != NULL) {
221
222 text_tset metadata;
223 FilterResponse_t filt_response;
224 text_t top;
225
226 metadata.insert ("URL");
227
228 // get metadata for parent document
229 get_top (args["d"], top);
230 if (get_info (top, args["c"], metadata, false, collectproto, filt_response, logout)) {
231 text_t url = filt_response.docInfo[0].metadata["URL"].values[0];
232
233 response = location;
234 response_data = url;
235 return;
236 } else {
237 // error, no URL
238 logout << "Error: documentaction::get_cgihead_info failed on get_info" << endl;
239 }
240 }
241 }
242 response = content;
243 response_data = "text/html";
244}
245
246// set_widthtspace calculates how wide the spaces in the nav bar should
247// be and sets the appropriate macro
248void documentaction::set_spacemacro (displayclass &disp, FilterResponse_t &response,
249 bool has_search_button) {
250
251 text_t width;
252 int twidth, swidth, iwidth = 0;
253
254 int numc = response.docInfo.size();
255 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
256 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
257
258 disp.expandstring ("Global", "_pagewidth_", width);
259 twidth = width.getint();
260
261 if (has_search_button) {
262 disp.expandstring ("query", "_searchwidth_", width);
263 iwidth += width.getint();
264 } else {
265 numc -= 1;
266 }
267
268 while (dochere != docend) {
269 const text_t &title = (*dochere).metadata["Title"].values[0];
270
271 disp.expandstring ("document", "_" + title + "width_", width);
272 if (width == ("_" + title + "width_"))
273 disp.expandstring ("document", "_defaultwidth_", width);
274 iwidth += width.getint();
275 dochere ++;
276 }
277 if ((twidth - iwidth) < numc) swidth = 2;
278 else {
279 swidth = twidth - iwidth;
280 if (numc > 0) swidth = swidth / numc;
281 }
282 disp.setmacro ("widthtspace", "Global", swidth);
283}
284
285// set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros
286// reponse contains 1 metadata field (Title)
287void documentaction::set_navbarmacros (displayclass &disp, FilterResponse_t &response,
288 bool has_search_button, cgiargsclass &args) {
289
290 text_t topparent;
291 text_t &arg_d = args["d"];
292 text_t navigationbar = "<!-- Navigation Bar -->\n";
293
294 get_top (args["cl"], topparent);
295 int numc = response.docInfo.size();
296 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
297 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
298
299 navigationbar += "<nobr>\n";
300 if (has_search_button) {
301 if (args["a"] == "q") {
302 navigationbar += "_icontabsearchgreen_";
303 } else {
304 navigationbar += "_imagesearch_";
305 }
306 }
307
308 if (has_search_button || numc == 0) navigationbar += "_imagespacer_";
309
310 bool first = true;
311 while (dochere != docend) {
312
313 if (!first) navigationbar += "_imagespacer_";
314
315 text_t title = (*dochere).metadata["Title"].values[0];
316
317 bool unknown = false;
318
319 // test the _XXXwidth_ macro to see if image macros are
320 // defined for this type of classification - if not we'll
321 // just display the text
322 text_t tmpwidth;
323 disp.expandstring ("document", "_" + title + "width_", tmpwidth);
324 if (tmpwidth == ("_" + title + "width_")) unknown = true;
325
326 // if we're inside a document all the classification buttons should be enabled
327 if (arg_d.empty() && ((*dochere).OID == topparent)) {
328 if (unknown) navigationbar += "&nbsp;" + title + "&nbsp;";
329 else navigationbar += "_icontab" + title + "green_";
330 } else {
331
332 // set the _httpbrowseXXX_ macro for this classification
333 if (unknown) navigationbar += "&nbsp;<a href=\"_httpdocument_&cl=" +
334 (*dochere).OID + "\">" + title + "</a>&nbsp;";
335 else {
336 navigationbar += "_image" + title + "_";
337 disp.setmacro ("httpbrowse" + title, "Global", "_httpdocument_&cl=" + (*dochere).OID);
338 }
339 }
340 dochere ++;
341 first = false;
342 }
343 navigationbar += "\n</nobr>\n";
344 navigationbar += "<!-- End of Navigation Bar -->\n";
345 disp.setmacro ("navigationbar", "Global", navigationbar);
346}
347
348// define all the macros which might be used by other actions
349// to produce pages.
350void documentaction::define_external_macros (displayclass &disp, cgiargsclass &args,
351 recptprotolistclass *protos, ostream &logout) {
352
353 // define_external_macros sets the following macros:
354
355 // _navigationbar_ this is the navigation bar containing the search button
356 // and any classification buttons - it goes at the top of
357 // most pages. for now we're assuming that there'll always
358 // be a search button - we should probably check that there
359 // is a query action before making this assumption
360
361 // _httpbrowseXXX_ the http macros for each classification (i.e. if there
362 // are Title and Creator classifications _httpbrowseTitle_
363 // and _httpbrowseCreator_ will be set
364
365 // _widthtspace_ the width of the spacers between buttons in navigation
366 // bar
367
368 // _httpdocument_ has '&f=1' added if displaying document inside a frame
369
370 // _gsdltop_ macro to replace _top targets with
371
372 // _httppagehome_ overridden home url if html collections have own homepage
373
374 // _usability_ - a macro for remote usability reporting
375
376 // must have a valid collection server to continue
377 text_t &collection = args["c"];
378 if (collection.empty()) return;
379 recptproto *collectproto = protos->getrecptproto (collection, logout);
380 if (collectproto == NULL) return;
381
382 if (recpt == NULL) {
383 logout << "ERROR (documentaction::define_external_macros): This action does not contain\n"
384 << " information about any receptionists. The method set_receptionist was\n"
385 << " probably not called from the module which instantiated this action.\n";
386 return;
387 }
388
389 outconvertclass text_t2ascii;
390 comerror_t err;
391 InfoFiltersResponse_t filterinfo;
392 FilterResponse_t response;
393 text_tset metadata;
394
395 // get info on current collection and load up formatinfo
396 // I'd prefer not to do this here as we're getting
397 // collection info every time (and probably also getting
398 // it in other places some of the time) - One day I'll
399 // fix it ... maybe - Stefan.
400 ColInfoResponse_t cinfo;
401
402 collectproto->get_collectinfo (collection, cinfo, err, logout);
403 load_formatinfo (cinfo.format, args.getintarg("gt"));
404 // ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
405 // if (cinfo == NULL) {
406 // logout << "ERROR (documentaction::define_external_macros): get_collectinfo_ptr returned NULL\n";
407 // return;
408 // }
409 //load_formatinfo (cinfo->format, args.getintarg("gt"));
410
411 if (formatinfo.DocumentUseHTML) {
412
413 // frame stuff
414 if (args["fc"] == "1") {
415 text_t httpdocument;
416 disp.expandstring ("Global", "_httpdocument_", httpdocument);
417 httpdocument += "&f=1";
418 disp.setmacro ("httpdocument", "Global", httpdocument);
419 disp.setmacro ("gsdltop", "Global", "documenttop");
420 formatinfo.DocumentText = "[Text]";
421 }
422 text_tmap::iterator it = cinfo.format.find ("homepage");
423 if (it != cinfo.format.end()) {
424 text_t httppagehome;
425 if (get_link (args, protos, (*it).second, httppagehome, logout))
426 disp.setmacro ("httppagehome", "Global", httppagehome);
427 }
428 }
429
430 // don't want navigation bar if page is 'detached'
431 if (!args.getintarg("x")) {
432
433 collectproto->get_filterinfo (collection, filterinfo, err, logout);
434 if (err == noError) {
435 // check that there's a browse filter
436 if (filterinfo.filterNames.find ("BrowseFilter") != filterinfo.filterNames.end()) {
437
438 metadata.insert ("Title");
439 bool getParents = false;
440 get_children ("", collection, metadata, getParents, collectproto, response, logout);
441
442 bool has_search_button = true;
443 collectproto->is_searchable(collection, has_search_button, err, logout);
444 if (err != noError) has_search_button = true;
445
446 // calculate width of spacers and set _widthtspace_ macro
447 if (args.getintarg("v") == 0) set_spacemacro (disp, response, has_search_button);
448
449 // set _navigationbar_ macro
450 set_navbarmacros (disp, response, has_search_button, args);
451
452 }
453 } else {
454 logout << text_t2ascii
455 << "Error (documentaction::define_external_macros()) in call to get_filterinfo() "
456 << get_comerror_string (err);
457 }
458 }
459 text_tmap::iterator usability = cinfo.format.find("Usability");
460 if(usability!=cinfo.format.end()){
461 disp.setmacro("usability","Global","_imageusab_");
462 disp.setmacro("usabinterface","Global",("_usab"+(*usability).second+"_"));
463 disp.setmacro("usabilityscript", "Global", "_usabshowscript_");
464 }
465}
466
467bool documentaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
468 const text_t &inlink, text_t &outlink, ostream &logout) {
469
470 FilterResponse_t response;
471 text_tset metadata;
472 metadata.insert ("section");
473
474 // check current collection first
475 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
476
477 if (get_info (inlink, args["c"], metadata, false, collectproto, response, logout)) {
478 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
479 outlink = "_httpdocument_&d=" + response.docInfo[0].metadata["section"].values[0];
480 return true;
481 }
482 }
483
484 // check all the other enabled collections
485
486 if (args["ccs"] == "1" && !args["cc"].empty()) {
487 text_tarray collections;
488 splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
489
490 text_tarray::const_iterator col_here = collections.begin();
491 text_tarray::const_iterator col_end = collections.end();
492
493 while (col_here != col_end) {
494
495 // don't need to check current collection again
496 if (*col_here == args["c"]) {col_here ++; continue;}
497
498 collectproto = protos->getrecptproto (*col_here, logout);
499
500 if (get_info (inlink, *col_here, metadata, false, collectproto, response, logout)) {
501 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
502 outlink = "_httpdocument_&c=" + *col_here + "&d=" +
503 response.docInfo[0].metadata["section"].values[0];
504 return true;
505 }
506 }
507 col_here ++;
508 }
509 }
510 return false;
511}
512
513void documentaction::load_formatinfo (const text_tmap &colformat, int gt) {
514
515 formatinfo.clear();
516 text_tmap::const_iterator format_here = colformat.begin();
517 text_tmap::const_iterator format_end = colformat.end();
518
519 while (format_here != format_end) {
520 if (((*format_here).first == "DocumentImages") &&
521 ((*format_here).second == "true"))
522 formatinfo.DocumentImages = true;
523 else if (((*format_here).first == "DocumentTitles") &&
524 ((*format_here).second == "false"))
525 formatinfo.DocumentTitles = false;
526 else if ((*format_here).first == "DocumentHeading")
527 formatinfo.DocumentHeading = (*format_here).second;
528 else if (((*format_here).first == "DocumentContents") &&
529 ((*format_here).second == "false"))
530 formatinfo.DocumentContents = false;
531 else if (((*format_here).first == "DocumentArrowsBottom") &&
532 ((*format_here).second == "false"))
533 formatinfo.DocumentArrowsBottom = false;
534 else if ((*format_here).first == "DocumentButtons")
535 splitchar ((*format_here).second.begin(), (*format_here).second.end(),
536 '|', formatinfo.DocumentButtons);
537 else if ((*format_here).first == "DocumentText")
538 formatinfo.DocumentText = (*format_here).second;
539 else if ((*format_here).first == "RelatedDocuments")
540 formatinfo.RelatedDocuments = (*format_here).second;
541 else if (((*format_here).first == "DocumentUseHTML") &&
542 ((*format_here).second == "true"))
543 formatinfo.DocumentUseHTML = true;
544 else
545 formatinfo.formatstrings[(*format_here).first] = (*format_here).second;
546
547 format_here ++;
548 }
549
550 // never want arrows when text is expanded
551 if (gt) formatinfo.DocumentArrowsBottom = false;
552}
553
554
555// define all the macros which are related to pages generated
556// by this action. we also load up the formatinfo structure
557// here (it's used in do_action as well as here)
558void documentaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
559 recptprotolistclass *protos, ostream &logout) {
560
561 // define_internal_macros sets the following macros:
562
563 // _pagetitle_ the title to be displayed at the top of the browser window
564
565 // _imagethispage_ the title image to be displayed at top right of page
566
567 // _navarrows_ this may be overridden to "" when format option
568 // DocumentArrowsBottom is false
569
570 // _header_ the header macro is overridden if we're not at a top level
571 // classification to remove the title block
572
573 // _thisOID_ the OID (directory) of the current document - this corresponds
574 // to the archivedir metadata element
575
576 // must have a valid collection server to continue
577 text_t &collection = args["c"];
578 if (collection.empty()) return;
579 recptproto *collectproto = protos->getrecptproto (collection, logout);
580 if (collectproto == NULL) return;
581
582 text_tset metadata;
583 FilterResponse_t response;
584 text_t &arg_d = args["d"];
585 text_t &arg_cl = args["cl"];
586
587 if (!formatinfo.DocumentArrowsBottom)
588 disp.setmacro("navarrows", "document", "");
589
590 metadata.insert ("Title");
591
592 bool fulltoc = false;
593
594 if (args["cl"] != "search") {
595 // see if there's a FullTOC string
596 text_t cl_top, full_toc;
597 get_top (arg_cl, cl_top);
598 if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
599 if (full_toc == "true") fulltoc = true;
600 }
601
602 if (!arg_d.empty() && !fulltoc) {
603 // we're at document level
604
605 metadata.insert ("archivedir");
606
607 comerror_t err;
608 OptionValue_tarray options;
609 // we need to do the query again for the z3950proto
610 if (collectproto->get_protocol_name(err)=="z3950proto") {
611 OptionValue_t opt;
612 opt.name="Term";opt.value=args["q"];options.push_back(opt);
613 opt.name="QueryType";
614 opt.value=(args.getintarg("t")) ? "ranked" : "boolean";
615 options.push_back(opt);
616 opt.name="Index";opt.value=args["h"];options.push_back(opt);
617 }
618
619 //do not display relation metadata
620 disp.setmacro ("relateddoc", "document", "");
621
622 //if preferences indicate relevant docs should be collected
623 //and there is no particular format specified then display
624 //this default format.
625 if(args["rd"] == "1" && formatinfo.RelatedDocuments.empty()){
626
627 text_t relation = ""; //string for displaying relation metadata
628
629 //call function in formattools.cpp which will return the text of the
630 //related documents in a vertical list. This is the default format.
631 if (get_info (arg_d, collection, metadata, options, false, collectproto, response, logout))
632 relation += get_related_docs(collection, collectproto, response.docInfo[0], logout);
633
634 //set macro to be the related document string
635 disp.setmacro ("relateddoc", "document", relation);
636 }
637
638
639 // get metadata for this document and it's parents
640 if (get_info (arg_d, collection, metadata, options,
641 true, collectproto, response, logout)) {
642
643 disp.setmacro ("header", "document", "_textheader_");
644
645 text_tarray pagetitlearray;
646 if (!response.docInfo[0].metadata["Title"].values[0].empty())
647 pagetitlearray.push_back (response.docInfo[0].metadata["Title"].values[0]);
648
649 if (args["gt"] != "1") {
650 MetadataInfo_t *parenttitle = response.docInfo[0].metadata["Title"].parent;
651 while (parenttitle != NULL) {
652 if (!parenttitle->values[0].empty())
653 pagetitlearray.push_back (parenttitle->values[0]);
654 parenttitle = parenttitle->parent;
655 }
656 }
657 reverse (pagetitlearray.begin(), pagetitlearray.end());
658 text_t pagetitle;
659 joinchar (pagetitlearray, ": ", pagetitle);
660 disp.setmacro ("pagetitle", "document", pagetitle);
661
662 if (is_top (arg_d))
663 disp.setmacro ("thisOID", "Global", dm_safe(response.docInfo[0].metadata["archivedir"].values[0]));
664 else {
665 MetadataInfo_t *parentad = response.docInfo[0].metadata["archivedir"].parent;
666 text_t thisOID;
667 while (parentad != NULL) {
668 thisOID = parentad->values[0];
669 parentad = parentad->parent;
670 }
671 disp.setmacro ("thisOID", "Global", dm_safe(thisOID));
672 }
673 }
674 } else {
675 if (!arg_cl.empty()) {
676
677 // get metadata for top level classification
678 text_t classtop;
679 get_top (arg_cl, classtop);
680 metadata.insert ("childtype");
681 metadata.insert ("parameters");
682
683 if (get_info (classtop, collection, metadata, false, collectproto, response, logout)) {
684
685 text_t &title = response.docInfo[0].metadata["Title"].values[0];
686 bool unknown = false;
687
688 // test the _XXXwidth_ macro to see if image macros are
689 // defined for this type of classification - if not we'll
690 // just display the text
691 text_t tmp;
692 disp.expandstring ("document", "_" + title + "width_", tmp);
693 if (tmp == ("_" + title + "width_")) unknown = true;
694
695 if (unknown) {
696 disp.setmacro ("pagetitle", "document", title);
697 disp.setmacro ("imagethispage", "document", "<h2>" + title + "</h2>");
698 } else {
699 disp.setmacro ("pagetitle", "document", "_text" + title + "page_");
700 disp.setmacro ("imagethispage", "document", "_icon" + title + "page_");
701 }
702
703 //if the document is not a document from a collection
704 //we must set the macro to be an empty string
705 disp.setmacro ("relateddoc", "document", "");
706
707 // Add macros specific to the Phind lassifier
708 text_t &childtype = response.docInfo[0].metadata["childtype"].values[0];
709 if (childtype == "Phind") {
710
711 // First, a macro to display the phind classifier
712 disp.setmacro ("phindclassifier", "document", "_phindapplet_");
713
714 // Next, macros that control the way the classifier is displayed
715 text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
716
717 // extract key=value pairs and set as macros
718 text_t::iterator here = parameters.begin();
719 text_t::iterator end = parameters.end();
720 text_t key, value;
721
722 while (here != end) {
723 // get the next key and value pair
724 here = getdelimitstr (here, end, '=', key);
725 here = getdelimitstr (here, end, ';', value);
726
727 // store this key=value pair
728 if (!key.empty() && !value.empty()) {
729 disp.setmacro (key, "document", value);
730 }
731 }
732 } // end if (childtype == "Phind")
733 }
734 } // end if (!arg_cl.empty()) {
735 }
736}
737
738
739bool documentaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
740 browsermapclass *browsers, displayclass &disp,
741 outconvertclass &outconvert, ostream &textout,
742 ostream &logout) {
743
744 // must have a valid collection server
745 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
746 if (collectproto == NULL) {
747 logout << "documentaction::do_action called with NULL collectproto\n";
748 textout << outconvert << disp << "_document:header_\n"
749 << "Error: Attempt to get document without setting collection\n"
750 << "_document:footer_\n";
751 } else {
752
753 text_t OID = args["d"];
754 if (OID.empty()) OID = args["cl"];
755 if (OID.empty()) {
756 textout << outconvert << disp << "Document contains no data_document:footer_\n";
757 return true;
758 }
759
760
761 if (formatinfo.DocumentUseHTML && !args["d"].empty()) {
762
763 if (args["f"] == "1") {
764 textout << outconvert << disp
765 << "<html><head></head>\n"
766 << "<frameset rows=\"68,*\" noresize border=0>\n"
767 << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
768 << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d="
769 << args["d"] << "\">"
770 << "<noframes>\n"
771 << "<p>You must have a frame enabled browser to view this.</p>\n"
772 << "</noframes>\n"
773 << "</frameset>\n"
774 << "</html>\n";
775 } else {
776 output_document (OID, args, collectproto, disp, outconvert, textout, logout);
777 }
778 return true;
779 }
780
781
782 textout << outconvert << disp << "_document:header_\n"
783 << "_document:content_\n";
784
785 // output the table of contents
786 output_toc (args, browsers, formatinfo, collectproto,
787 disp, outconvert, textout, logout);
788
789 //output the related documents (may be the empty string)
790 //will not output the docs if a format string is specified
791 textout << outconvert << disp << "_document:relateddoc_\n";
792
793 // output the document text
794 if (!args["d"].empty()) {
795 textout << outconvert << "<p>\n";
796 output_document (OID, args, collectproto, disp, outconvert, textout, logout);
797 }
798
799 textout << outconvert << disp << "_document:footer_\n";
800 }
801 return true;
802}
803
804void documentaction::output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
805 const TermInfo_tarray &terminfo, const text_t &OID,
806 bool highlight, int hastxt, int wanttext,
807 text_t &collection, recptproto *collectproto,
808 displayclass &disp, outconvertclass &outconvert,
809 ostream &textout, ostream &logout,
810 cgiargsclass &args) {
811
812 DocumentRequest_t docrequest;
813 DocumentResponse_t docresponse;
814 comerror_t err;
815
816 if (hastxt == 1) {
817
818 if (wanttext) {
819 // get the text
820 docrequest.OID = OID;
821 collectproto->get_document (collection, docrequest, docresponse, err, logout);
822
823 // cut down on overhead by not using formattools if we only want the text
824 // (wanttext will equal 2 if we want text and other stuff too)
825 if (wanttext == 1)
826 if (highlight) {
827 highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout);
828 } else {
829 textout << outconvert << disp << docresponse.doc;
830 }
831 }
832
833 if (wanttext != 1) {
834 text_t doctext
835 = get_formatted_string (collection, collectproto,
836 docinfo, disp, formatlistptr, docresponse.doc,
837 logout);
838
839 if (highlight) {
840 highlighttext(doctext, args, terminfo, disp, outconvert, textout);
841 } else {
842 textout << outconvert << disp << doctext;
843 }
844 }
845 }
846}
847
848
849void documentaction::output_document (const text_t &OID, cgiargsclass &args,
850 recptproto *collectproto, displayclass &disp,
851 outconvertclass &outconvert, ostream &textout,
852 ostream &logout) {
853 FilterResponse_t inforesponse;
854 FilterResponse_t queryresponse;
855 text_tset metadata;
856 bool getParents = false;
857 bool highlight = false;
858 int wanttext = 0;
859 int arg_gt = args.getintarg("gt");
860 text_t &collection = args["c"];
861
862 // if we have a query string and highlighting is turned on we need
863 // to redo the query to get the terms for highlighting
864 if (!args["q"].empty() && args.getintarg("hl")) {
865 FilterRequest_t request;
866 comerror_t err;
867 request.filterResultOptions = FRmatchTerms;
868 text_t formattedstring = args["q"];
869 format_querystring (formattedstring, args.getintarg("b"));
870 set_queryfilter_options (request, formattedstring, args);
871 collectproto->filter (args["c"], request, queryresponse, err, logout);
872 if (err != noError) {
873 outconvertclass text_t2ascii;
874 logout << text_t2ascii
875 << "documentaction::output_document: call to QueryFilter failed "
876 << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
877 highlight = false;
878 } else {
879 highlight = true;
880 }
881 }
882
883
884 format_t *formatlistptr = new format_t();
885 parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
886
887 metadata.insert ("hastxt");
888 metadata.insert ("haschildren");
889
890 if (formatinfo.DocumentText == "[Text]")
891 wanttext = 1;
892 else {
893 char *docformat = formatinfo.DocumentText.getcstr();
894 if (strstr (docformat, "[Text]") != NULL)
895 wanttext = 2;
896 delete docformat;
897 }
898
899 if (get_info (OID, collection, metadata, getParents, collectproto, inforesponse, logout)) {
900 int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
901 int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
902
903 if (arg_gt == 0) {
904 output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
905 OID, highlight, hastxt, wanttext, collection, collectproto,
906 disp, outconvert, textout, logout, args);
907
908
909 } else {
910
911 ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
912
913 // text is to be expanded
914 text_t exOID = OID;
915 if (haschildren != 1) exOID = get_parent (OID);
916 if (exOID.empty()) exOID = OID;
917
918 // if we're not in a document (i.e. we're in a top level classification)
919 // we need to pass "is_classify = true" to get_contents so that it
920 // doesn't recurse all the way through each document in the classification
921 bool is_classify = false;
922 if (args["d"].empty()) is_classify = true;
923
924 get_contents (exOID, is_classify, metadata, collection,
925 collectproto, inforesponse, logout);
926
927 ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
928 ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
929
930 if (arg_gt == 1) {
931 // check if there are more than 10 sections containing text to be expanded -
932 // if there are output warning message - this isn't a great way to do this
933 // since the sections may be very large or very small - one day I'll fix it
934 // -- Stefan.
935 int seccount = 0;
936 while (sechere != secend) {
937 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
938 if (shastxt == 1) seccount ++;
939 if (seccount > 10) break;
940 sechere ++;
941 }
942 if (seccount > 10) {
943 // more than 10 sections so output warning message and text
944 // for current section only
945 textout << outconvert << disp << "_document:textltwarning_";
946
947 output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
948 OID, highlight, hastxt, wanttext, collection,
949 collectproto, disp, outconvert, textout, logout, args);
950
951 }
952 else arg_gt = 2;
953 }
954
955 if (arg_gt == 2) {
956 // get the text for each section
957 sechere = inforesponse.docInfo.begin();
958 int count = 0;
959 while (sechere != secend) {
960 textout << outconvert << disp << "\n<p><a name=" << (*sechere).OID << "></a>\n";
961
962 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
963
964 output_text (*sechere, formatlistptr, queryresponse.termInfo,
965 (*sechere).OID, highlight, shastxt, wanttext, collection,
966 collectproto, disp, outconvert, textout, logout, args);
967 count ++;
968 sechere ++;
969 }
970 }
971 }
972 }
973 delete formatlistptr;
974}
Note: See TracBrowser for help on using the repository browser.