source: gsdl/trunk/src/recpt/documentaction.cpp@ 15418

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

(Untangling colservr/recpt) Split recpt/OIDtools into two: lib/OIDtools.cpp/h contains the purely string-based functions (may be used by the colservr), and recpt/recptprototools.cpp/h contains the functions requiring a call to the colservr (get_info() etc.).

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 55.0 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
28#include "documentaction.h"
29#include "recptprototools.h"
30#include "OIDtools.h"
31#include "querytools.h"
32#include "unitool.h"
33#include "gsdltools.h"
34#include "highlighttext.h"
35#include "browsetoolsclass.h"
36
37documentaction::documentaction () {
38 recpt = NULL;
39
40 // this action uses cgi variables "a", "d", "cl",
41 // "x", "gc", "gt", "gp", and "hl"
42 cgiarginfo arg_ainfo;
43 arg_ainfo.shortname = "a";
44 arg_ainfo.longname = "action";
45 arg_ainfo.multiplechar = true;
46 arg_ainfo.defaultstatus = cgiarginfo::weak;
47 arg_ainfo.argdefault = "p";
48 arg_ainfo.savedarginfo = cgiarginfo::must;
49 argsinfo.addarginfo (NULL, arg_ainfo);
50
51 arg_ainfo.shortname = "d";
52 arg_ainfo.longname = "document OID";
53 arg_ainfo.multiplechar = true;
54 arg_ainfo.defaultstatus = cgiarginfo::none;
55 arg_ainfo.argdefault = g_EmptyText;
56 arg_ainfo.savedarginfo = cgiarginfo::can;
57 argsinfo.addarginfo (NULL, arg_ainfo);
58
59 // whether or not a document should be retrieved from the
60 // library or the Web.
61 arg_ainfo.shortname = "il";
62 arg_ainfo.longname = "internal link preference";
63 arg_ainfo.multiplechar = false;
64 arg_ainfo.defaultstatus = cgiarginfo::weak;
65 arg_ainfo.argdefault = "l";
66 arg_ainfo.savedarginfo = cgiarginfo::must;
67 argsinfo.addarginfo (NULL, arg_ainfo);
68
69 arg_ainfo.shortname = "cl";
70 arg_ainfo.longname = "classification OID";
71 arg_ainfo.multiplechar = true;
72 arg_ainfo.defaultstatus = cgiarginfo::none;
73 arg_ainfo.argdefault = g_EmptyText;
74 arg_ainfo.savedarginfo = cgiarginfo::can;
75 argsinfo.addarginfo (NULL, arg_ainfo);
76
77 // in this action "gc" controls the expand/contract
78 // contents function
79 arg_ainfo.shortname = "gc";
80 arg_ainfo.longname = "expand contents";
81 arg_ainfo.multiplechar = false;
82 arg_ainfo.defaultstatus = cgiarginfo::weak;
83 arg_ainfo.argdefault = "0";
84 arg_ainfo.savedarginfo = cgiarginfo::can;
85 argsinfo.addarginfo (NULL, arg_ainfo);
86
87 // in this action "gt" controls the expand/contract
88 // text function 0 = not expanded, 1 = expand unless
89 // there are more than 10 sections containing text,
90 // 2 = expand all
91 arg_ainfo.shortname = "gt";
92 arg_ainfo.longname = "expand text";
93 arg_ainfo.multiplechar = false;
94 arg_ainfo.defaultstatus = cgiarginfo::weak;
95 arg_ainfo.argdefault = "0";
96 arg_ainfo.savedarginfo = cgiarginfo::can;
97 argsinfo.addarginfo (NULL, arg_ainfo);
98
99 // in this action "gp" is the "go to page" control
100 // used by the Book type of toc
101 arg_ainfo.shortname = "gp";
102 arg_ainfo.longname = "go to page";
103 arg_ainfo.multiplechar = true;
104 arg_ainfo.defaultstatus = cgiarginfo::none;
105 arg_ainfo.argdefault = g_EmptyText;
106 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
107 argsinfo.addarginfo (NULL, arg_ainfo);
108
109 // in this action "hl" is the "highlighting on/
110 // highlighting off control ("hl" == "2" is a
111 // special case that forces phrase highlighting
112 // to be used even if the query string doesn't
113 // appear to be a phrase)
114 arg_ainfo.shortname = "hl";
115 arg_ainfo.longname = "highlighting on/off";
116 arg_ainfo.multiplechar = false;
117 arg_ainfo.defaultstatus = cgiarginfo::weak;
118 arg_ainfo.argdefault = "1";
119 arg_ainfo.savedarginfo = cgiarginfo::must;
120 argsinfo.addarginfo (NULL, arg_ainfo);
121
122 // "x" is 0 normally or 1 if page
123 // has been "detached"
124 arg_ainfo.shortname = "x";
125 arg_ainfo.longname = "detached page";
126 arg_ainfo.multiplechar = false;
127 arg_ainfo.defaultstatus = cgiarginfo::weak;
128 arg_ainfo.argdefault = "0";
129 arg_ainfo.savedarginfo = cgiarginfo::must;
130 argsinfo.addarginfo (NULL, arg_ainfo);
131
132 // "xx" is 0 normally or 1 if documents should be detached by default
133 arg_ainfo.shortname = "xx";
134 arg_ainfo.longname = "detach all doc pages";
135 arg_ainfo.multiplechar = false;
136 arg_ainfo.defaultstatus = cgiarginfo::weak;
137 arg_ainfo.argdefault = "0";
138 arg_ainfo.savedarginfo = cgiarginfo::must;
139 argsinfo.addarginfo (NULL, arg_ainfo);
140
141
142 // f arg is set to 1 if document is to
143 // be displayed in a frame
144 arg_ainfo.shortname = "f";
145 arg_ainfo.longname = "frame";
146 arg_ainfo.multiplechar = false;
147 arg_ainfo.defaultstatus = cgiarginfo::weak;
148 arg_ainfo.argdefault = "0";
149 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
150 argsinfo.addarginfo (NULL, arg_ainfo);
151
152 // fc arg is "1" if search bar is to be included (i.e. if "fc" == 1
153 // the httpdocument macro will include "&f=1"
154 arg_ainfo.shortname = "fc";
155 arg_ainfo.longname = "include search bar";
156 arg_ainfo.multiplechar = false;
157 arg_ainfo.defaultstatus = cgiarginfo::weak;
158 arg_ainfo.argdefault = "1";
159 arg_ainfo.savedarginfo = cgiarginfo::must;
160 argsinfo.addarginfo (NULL, arg_ainfo);
161
162 //rd is whether a document will be displayed
163 //with a relevant document list
164 arg_ainfo.shortname = "rd";
165 arg_ainfo.longname = "include relevant documents";
166 arg_ainfo.multiplechar = false;
167 arg_ainfo.defaultstatus = cgiarginfo::weak;
168 arg_ainfo.argdefault = "0";
169 arg_ainfo.savedarginfo = cgiarginfo::must;
170 argsinfo.addarginfo (NULL, arg_ainfo);
171
172 //dm is the metadata that has been used for the datelist
173 arg_ainfo.shortname = "dm";
174 arg_ainfo.longname = "date metadata";
175 arg_ainfo.multiplechar = true;
176 arg_ainfo.defaultstatus = cgiarginfo::weak;
177 arg_ainfo.argdefault = g_EmptyText;
178 arg_ainfo.savedarginfo = cgiarginfo::must;
179 argsinfo.addarginfo (NULL, arg_ainfo);
180
181}
182
183documentaction::~documentaction()
184{
185}
186
187bool documentaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
188 recptprotolistclass *protos, ostream &logout) {
189
190 if(!args["d"].empty())
191 {
192 text_t docTop;
193 get_top(args["d"],docTop);
194
195 recptproto* collectproto = protos->getrecptproto (args["c"], logout);
196 if (collectproto != NULL)
197 {
198 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
199
200 if(cinfo->authenticate == "document")
201 {
202 // both are either commented out or uncomment and are empty
203 if (cinfo->public_documents.empty() && cinfo->private_documents.empty())
204 {
205 //deny everything
206 args["uan"] = "1";
207 args["ug"] = cinfo->auth_group;
208 }
209
210 // both public_documents and private_documents are turned on !
211 else if (!cinfo->public_documents.empty() && !cinfo->private_documents.empty())
212 {
213 //deny everything
214 args["uan"] = "1";
215 args["ug"] = cinfo->auth_group;
216 }
217
218 // if public_documents is set but this document isn't
219 // listed in it we need to authenticate
220 else if ((!cinfo->public_documents.empty()) &&
221 (cinfo->public_documents.find(docTop) == cinfo->public_documents.end()))
222 {
223 args["uan"] = "1";
224 args["ug"] = cinfo->auth_group;
225 }
226
227 // if private_documents is set and this document is
228 // listed in it we need to authenticate
229 else if ((!cinfo->private_documents.empty()) &&
230 (cinfo->private_documents.find(docTop) != cinfo->private_documents.end()))
231 {
232 args["uan"] = "1";
233 args["ug"] = cinfo->auth_group;
234 }
235
236 }
237 }
238 }
239 // check gc argument
240 int arg_gc = args.getintarg("gc");
241 if (arg_gc < 0 || arg_gc > 2) {
242 logout << "Warning: \"gc\" argument out of range (" << arg_gc << ")\n";
243 cgiarginfo *gcinfo = argsinfo.getarginfo ("gc");
244 if (gcinfo != NULL) args["gc"] = gcinfo->argdefault;
245 }
246
247 // check gt argument (may be either 0, 1 or 2)
248 int arg_gt = args.getintarg("gt");
249 if (arg_gt != 0 && arg_gt != 1 && arg_gt != 2) {
250 logout << "Warning: \"gt\" argument out of range (" << arg_gt << ")\n";
251 cgiarginfo *gtinfo = argsinfo.getarginfo ("gt");
252 if (gtinfo != NULL) args["gt"] = gtinfo->argdefault;
253 }
254
255 // check hl argument
256 int arg_hl = args.getintarg("hl");
257 if (arg_hl < 0 || arg_hl > 2) {
258 logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n";
259 cgiarginfo *hlinfo = argsinfo.getarginfo ("hl");
260 if (hlinfo != NULL) args["hl"] = hlinfo->argdefault;
261 }
262
263 // check x argument
264 int arg_x = args.getintarg("x");
265 if (arg_x != 0 && arg_x != 1) {
266 logout << "Warning: \"x\" argument out of range (" << arg_x << ")\n";
267 cgiarginfo *xinfo = argsinfo.getarginfo ("x");
268 if (xinfo != NULL) args["x"] = xinfo->argdefault;
269 }
270
271 //checks whether rd arg is valid
272 int arg_rd = args.getintarg("rd");
273 if (arg_rd != 0 && arg_rd != 1) {
274 logout << "Warning: \"rd\" argument out of range (" << arg_rd << ")\n";
275 cgiarginfo *rdinfo = argsinfo.getarginfo ("rd");
276 if (rdinfo != NULL) args["rd"] = rdinfo->argdefault;
277 }
278
279
280 return true;
281}
282
283void documentaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
284 response_t &response,text_t &response_data,
285 ostream &logout) {
286
287 if ((args["il"] == "w") && (!args["d"].empty())) {
288
289 recptproto* collectproto = protos->getrecptproto (args["c"], logout);
290 if (collectproto != NULL) {
291
292 text_tset metadata;
293 FilterResponse_t filt_response;
294 text_t top;
295
296 metadata.insert ("URL");
297
298 // get metadata for parent document
299 get_top (args["d"], top);
300 if (get_info (top, args["c"], args["l"], metadata, false, collectproto, filt_response, logout)) {
301 text_t url = filt_response.docInfo[0].metadata["URL"].values[0];
302
303 response = location;
304 response_data = url;
305 return;
306 } else {
307 // error, no URL
308 logout << "Error: documentaction::get_cgihead_info failed on get_info" << endl;
309 }
310 }
311 }
312 response = content;
313 response_data = "text/html";
314}
315
316// set_widthtspace calculates how wide the spaces in the nav bar should
317// be and sets the appropriate macro
318void documentaction::set_spacemacro (displayclass &disp, FilterResponse_t &response,
319 bool has_search_button) {
320
321 text_t width;
322 int twidth, swidth, iwidth = 0;
323
324 int numc = response.docInfo.size();
325 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
326 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
327
328 disp.expandstring (displayclass::defaultpackage, "_pagewidth_", width);
329 twidth = width.getint();
330
331 if (has_search_button) {
332 disp.expandstring ("query", "_searchwidth_", width);
333 iwidth += width.getint();
334 } else {
335 numc -= 1;
336 }
337
338 while (dochere != docend) {
339 const text_t &title = (*dochere).metadata["Title"].values[0];
340
341 disp.expandstring ("document", "_" + title + "width_", width);
342 if (width == ("_" + title + "width_")) {
343 disp.expandstring ("document", "_defaultwidth_", width);
344 }
345 iwidth += width.getint();
346 ++dochere;
347 }
348
349 if ((twidth - iwidth) < numc) swidth = 2;
350 else {
351 swidth = twidth - iwidth;
352 if (numc > 0) swidth = swidth / numc;
353 }
354 disp.setmacro ("widthtspace", displayclass::defaultpackage, swidth);
355}
356
357// set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros
358// reponse contains 1 metadata field (Title)
359void documentaction::set_navbarmacros (displayclass &disp, FilterResponse_t &response,
360 bool has_search_button, cgiargsclass &args,
361 ColInfoResponse_t &cinfo) {
362
363
364 bool use_pulldown = false;
365 text_tmap::iterator it = cinfo.format.find("NavigationBar");
366 if (it != cinfo.format.end()) {
367 if (it->second == "pulldown") {
368 use_pulldown = true;
369 }
370 }
371
372 text_t topparent;
373 text_t &arg_d = args["d"];
374 text_t navigationbar = "<!-- Navigation Bar -->\n";
375
376 get_top (args["cl"], topparent);
377 int numc = response.docInfo.size();
378 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
379 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
380
381 if (!use_pulldown) {
382 if (has_search_button) {
383 // search uses its own navtab, as it may be suppressed based on other args
384 navigationbar += "_navtabsearch_";
385 if (args["a"] == "q") {
386 navigationbar += "(selected)";
387 }
388 }
389
390 if (has_search_button || numc == 0) navigationbar += "_navbarspacer_";
391
392 bool first = true;
393 while (dochere != docend) {
394 if (!first) navigationbar += "_navbarspacer_";
395
396 text_t title = (*dochere).metadata["Title"].values[0];
397
398 navigationbar += "_navtab_(_httpbrowse"+(*dochere).OID+"_,"+title;
399 // if we are at this classifier
400 if (arg_d.empty() && ((*dochere).OID == topparent)) {
401 // don't link to this classifier as it is the current one
402 navigationbar += ",selected";
403 }
404 navigationbar += ")";
405
406 // set the _httpbrowseCLX_ macro for this classification
407 disp.setmacro ("httpbrowse" + (*dochere).OID, displayclass::defaultpackage, "_httpdocument_&amp;cl=" + (*dochere).OID);
408 ++dochere;
409 first = false;
410 }
411
412 navigationbar += "\n<!-- End of Navigation Bar -->\n";
413
414 } else {
415
416 navigationbar = "<form method=\"get\" name=\"navform\">\n";
417 navigationbar += "<select name=\"navbar\" onChange=\"location.href=";
418 navigationbar += "document.navform.navbar.options[document.navform.navbar.selectedIndex].value\">\n";
419
420 if (args["a"] != "q" && args["cl"].empty()) {
421 navigationbar += "<option value=\"\" selected>_textselectpage_</option>\n";
422 }
423
424 if (has_search_button) {
425 navigationbar += "<option value=\"_httpquery_\"";
426 if (args["a"] == "q") {
427 navigationbar += " selected";
428 }
429 navigationbar += ">_labelSearch_</option>\n";
430 }
431
432 while (dochere != docend) {
433 text_t title = dochere->metadata["Title"].values[0];
434
435 navigationbar += "<option value=\"_httpdocument_&amp;cl=" + dochere->OID + "\"";
436 if (topparent == dochere->OID) {
437 navigationbar += " selected";
438 }
439 navigationbar += ">_navlinktitle_(" + title + ")</option>\n";
440 ++dochere;
441 }
442
443 navigationbar += "</select>\n";
444 navigationbar += "</form>\n";
445 }
446
447 disp.setmacro ("navigationbar", displayclass::defaultpackage, navigationbar);
448}
449
450// define all the macros which might be used by other actions
451// to produce pages.
452void documentaction::define_external_macros (displayclass &disp, cgiargsclass &args,
453 recptprotolistclass *protos, ostream &logout) {
454
455 // define_external_macros sets the following macros:
456
457 // _navigationbar_ this is the navigation bar containing the search button
458 // and any classification buttons - it goes at the top of
459 // most pages. for now we're assuming that there'll always
460 // be a search button - we should probably check that there
461 // is a query action before making this assumption
462
463 // _httpbrowseXXX_ the http macros for each classification (i.e. if there
464 // are Title and Creator classifications _httpbrowseTitle_
465 // and _httpbrowseCreator_ will be set
466
467 // _widthtspace_ the width of the spacers between buttons in navigation
468 // bar
469
470 // _httpdocument_ has '&f=1' added if displaying document inside a frame
471
472 // _gsdltop_ macro to replace _top targets with
473
474 // _httppagehome_ overridden home url if html collections have own homepage
475
476 // _usability_ macros for remote usability reporting: if
477 // _usabinterface_ "format Usability [multi|textonly|stepwise]" is in
478 // _usabilityscript_ collect.cfg
479
480 // _versionnnum_ greenstone version number (hard-coded)
481 // must have a valid collection server to continue
482
483 text_t &collection = args["c"];
484 if (collection.empty()) return;
485 recptproto *collectproto = protos->getrecptproto (collection, logout);
486 if (collectproto == NULL) return;
487
488 if (recpt == NULL) {
489 logout << "ERROR (documentaction::define_external_macros): This action does not contain\n"
490 << " information about any receptionists. The method set_receptionist was\n"
491 << " probably not called from the module which instantiated this action.\n";
492 return;
493 }
494
495 outconvertclass text_t2ascii;
496 comerror_t err;
497 InfoFiltersResponse_t filterinfo;
498 FilterResponse_t response;
499 text_tset metadata;
500
501 // get info on current collection and load up formatinfo
502 // I'd prefer not to do this here as we're getting
503 // collection info every time (and probably also getting
504 // it in other places some of the time) - One day I'll
505 // fix it ... maybe - Stefan.
506 ColInfoResponse_t cinfo;
507
508 collectproto->get_collectinfo (collection, cinfo, err, logout);
509 load_formatinfo (cinfo.format, args.getintarg("gt"));
510 // ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
511 // if (cinfo == NULL) {
512 // logout << "ERROR (documentaction::define_external_macros): get_collectinfo_ptr returned NULL\n";
513 // return;
514 // }
515 //load_formatinfo (cinfo->format, args.getintarg("gt"));
516
517 if (formatinfo.DocumentUseHTML) {
518
519 // frame stuff
520 if (args["fc"] == "1") {
521 text_t httpdocument;
522 disp.expandstring (displayclass::defaultpackage, "_httpdocument_", httpdocument);
523 httpdocument += "&amp;f=1";
524 disp.setmacro ("httpdocument", displayclass::defaultpackage, httpdocument);
525 disp.setmacro ("gsdltop", displayclass::defaultpackage, "documenttop");
526 formatinfo.DocumentText = "[Text]";
527 }
528 text_tmap::iterator it = cinfo.format.find ("homepage");
529 if (it != cinfo.format.end()) {
530 text_t httppagehome;
531 if (get_link (args, protos, (*it).second, httppagehome, logout))
532 disp.setmacro ("httppagehome", displayclass::defaultpackage, httppagehome);
533 }
534 }
535
536 // don't want navigation bar if page is 'detached'
537 if (!args.getintarg("x")) {
538
539 collectproto->get_filterinfo (collection, filterinfo, err, logout);
540 if (err == noError) {
541 // check that there's a browse filter
542 if (filterinfo.filterNames.find ("BrowseFilter") != filterinfo.filterNames.end()) {
543
544 metadata.insert ("Title");
545 bool getParents = false;
546 get_children ("", collection, args["l"], metadata, getParents, collectproto, response, logout);
547
548 bool has_search_button = true;
549 collectproto->is_searchable(collection, has_search_button, err, logout);
550 if (err != noError) has_search_button = false;
551
552 // calculate width of spacers and set _widthtspace_ macro
553 if (args.getintarg("v") == 0) set_spacemacro (disp, response, has_search_button);
554
555 // set _navigationbar_ macro
556 set_navbarmacros (disp, response, has_search_button, args, cinfo);
557
558 }
559 } else {
560 logout << text_t2ascii
561 << "Error (documentaction::define_external_macros()) in call to get_filterinfo() "
562 << get_comerror_string (err);
563 }
564 }
565
566 // send feedback button and pages
567 text_tmap::iterator usability = cinfo.format.find("Usability");
568 if(usability!=cinfo.format.end()){
569 disp.setmacro("usability",displayclass::defaultpackage,"_usablink_");
570 disp.setmacro("usabinterface",displayclass::defaultpackage,("_usab"+(*usability).second+"_"));
571 disp.setmacro("usabilityscript", displayclass::defaultpackage, "_usabshowscript_");
572 }
573
574 // version num
575 disp.setmacro("versionnum", displayclass::defaultpackage, GSDL_VERSION);
576
577}
578
579bool documentaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
580 const text_t &inlink, text_t &outlink, ostream &logout) {
581
582 FilterResponse_t response;
583 text_tset metadata;
584 metadata.insert ("section");
585
586 // check current collection first
587 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
588
589 if (get_info (inlink, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
590 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
591#ifndef DOCHANDLE
592 outlink = "_httpdocument_&amp;d=" + response.docInfo[0].metadata["section"].values[0];
593#else
594 outlink = "_httpdocumenthandle_("+args["c"]+","+response.docInfo[0].metadata["section"].values[0]+")";
595#endif
596
597 return true;
598 }
599 }
600
601 // check all the other enabled collections
602
603 if (args["ccs"] == "1" && !args["cc"].empty()) {
604 text_tarray collections;
605 splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
606
607 text_tarray::const_iterator col_here = collections.begin();
608 text_tarray::const_iterator col_end = collections.end();
609
610 while (col_here != col_end) {
611
612 // don't need to check current collection again
613 if (*col_here == args["c"]) {++col_here; continue;}
614
615 collectproto = protos->getrecptproto (*col_here, logout);
616
617 if (get_info (inlink, *col_here, args["l"], metadata, false, collectproto, response, logout)) {
618 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
619#ifndef DOCHANDLE
620 outlink = "_httpdocument_&amp;c=" + *col_here + "&amp;d=" +
621 response.docInfo[0].metadata["section"].values[0];
622#else
623 outlink = "_httpdocumenthandle_("+*col_here+","+response.docInfo[0].metadata["section"].values[0]+")";
624#endif
625
626 return true;
627 }
628 }
629 ++col_here;
630 }
631 }
632 return false;
633}
634
635void documentaction::load_formatinfo (const text_tmap &colformat, int gt) {
636
637 formatinfo.clear();
638 text_tmap::const_iterator format_here = colformat.begin();
639 text_tmap::const_iterator format_end = colformat.end();
640
641 while (format_here != format_end) {
642 if (((*format_here).first == "DocumentImages") &&
643 ((*format_here).second == "true"))
644 formatinfo.DocumentImages = true;
645 else if (((*format_here).first == "DocumentTitles") &&
646 ((*format_here).second == "false"))
647 formatinfo.DocumentTitles = false;
648 else if ((*format_here).first == "DocumentHeading")
649 formatinfo.DocumentHeading = (*format_here).second;
650 else if (((*format_here).first == "DocumentContents") &&
651 ((*format_here).second == "false"))
652 formatinfo.DocumentContents = false;
653 else if (((*format_here).first == "DocumentArrowsBottom") &&
654 ((*format_here).second == "false"))
655 formatinfo.DocumentArrowsBottom = false;
656 else if (((*format_here).first == "DocumentArrowsTop") &&
657 ((*format_here).second == "true"))
658 formatinfo.DocumentArrowsTop = true;
659 else if ((*format_here).first == "DocumentButtons")
660 splitchar ((*format_here).second.begin(), (*format_here).second.end(),
661 '|', formatinfo.DocumentButtons);
662 else if ((*format_here).first == "DocumentText")
663 formatinfo.DocumentText = (*format_here).second;
664 else if ((*format_here).first == "RelatedDocuments")
665 formatinfo.RelatedDocuments = (*format_here).second;
666 else if (((*format_here).first == "DocumentUseHTML") &&
667 ((*format_here).second == "true"))
668 formatinfo.DocumentUseHTML = true;
669 else if (((*format_here).first == "AllowExtendedOptions") &&
670 ((*format_here).second == "true"))
671 formatinfo.AllowExtendedOptions = true;
672 else
673 formatinfo.formatstrings[(*format_here).first] = (*format_here).second;
674
675 ++format_here;
676 }
677
678 // never want arrows when text is expanded
679 if (gt) {
680 formatinfo.DocumentArrowsBottom = false;
681 formatinfo.DocumentArrowsTop = false;
682 }
683}
684
685
686// define all the macros which are related to pages generated
687// by this action. we also load up the formatinfo structure
688// here (it's used in do_action as well as here)
689void documentaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
690 recptprotolistclass *protos, ostream &logout) {
691
692 // define_internal_macros sets the following macros:
693
694 // _pagetitle_ the title to be displayed at the top of the browser window
695
696 // _imagethispage_ the title image to be displayed at top right of page
697
698 // _navarrowsbottom_ this may be overridden to "" when format option
699 // DocumentArrowsBottom is false
700
701 // _navarrowstop_ likewise for DocumentArrowsTop
702
703 // _httpprevarrow_ links to next and previous sections of document - used
704 // _httpnextarrow_ by DocumentArrowsBottom
705
706 // _header_ the header macro is overridden if we're not at a top level
707 // classification to remove the title block
708
709 // _thisOID_ the OID (directory) of the current document - this corresponds
710 // to the archivedir metadata element
711
712 // _documentheader_ Custom header info for the specified document
713 // must have a valid collection server to continue
714
715 text_t &collection = args["c"];
716 if (collection.empty()) return;
717 recptproto *collectproto = protos->getrecptproto (collection, logout);
718 if (collectproto == NULL) return;
719
720 text_tset metadata;
721 FilterResponse_t response;
722 text_t &arg_d = args["d"];
723 text_t &arg_cl = args["cl"];
724
725 if (!formatinfo.DocumentArrowsBottom) {
726 disp.setmacro("navarrowsbottom", "document", "");
727 } else if (!formatinfo.DocumentArrowsBottom) {
728 disp.setmacro("navarrowstop", "document", "");
729 }
730
731 if (!arg_d.empty() && (formatinfo.DocumentArrowsBottom || formatinfo.DocumentArrowsTop)) {
732 // set _httpprevarrow_ and _httpnextarrow_
733 set_arrow_macros (args, collectproto, disp, logout);
734 }
735
736 metadata.insert ("Title");
737 metadata.insert ("gs.DocumentHeader");
738 metadata.insert ("DocumentHeader");
739
740 bool fulltoc = false;
741
742 if (args["cl"] != "search") {
743 // see if there's a FullTOC string
744 text_t cl_top, full_toc;
745 get_top (arg_cl, cl_top);
746 if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
747 if (full_toc == "true") fulltoc = true;
748 }
749
750 if (!arg_d.empty() && !fulltoc) {
751 // we're at document level
752
753 metadata.insert ("archivedir");
754
755 comerror_t err;
756 OptionValue_tarray options;
757 // we need to do the query again for the z3950proto
758 if (collectproto->get_protocol_name(err)=="z3950proto") {
759 OptionValue_t opt;
760 opt.name="Term";opt.value=args["q"];options.push_back(opt);
761 opt.name="QueryType";
762 opt.value=(args.getintarg("t")) ? "ranked" : "boolean";
763 options.push_back(opt);
764 opt.name="Index";opt.value=args["h"];options.push_back(opt);
765 }
766
767 //do not display relation metadata
768 disp.setmacro ("relateddoc", "document", "");
769
770 //if preferences indicate relevant docs should be collected
771 //and there is no particular format specified then display
772 //this default format.
773 if(args["rd"] == "1" && formatinfo.RelatedDocuments.empty()){
774
775 text_t relation = g_EmptyText; //string for displaying relation metadata
776
777 //call function in formattools.cpp which will return the text of the
778 //related documents in a vertical list. This is the default format.
779
780 if (get_info (arg_d, collection, args["l"], metadata, options, false, collectproto, response, logout))
781 relation += get_related_docs(collection, collectproto, response.docInfo[0], logout);
782
783 //set macro to be the related document string
784
785 disp.setmacro ("relateddoc", "document", relation);
786 }
787
788
789 // get metadata for this document and it's parents
790 if (get_info (arg_d, collection, args["l"], metadata, options,
791 true, collectproto, response, logout)) {
792
793 disp.setmacro ("header", "document", "_textheader_");
794 text_tarray pagetitlearray;
795 if (!response.docInfo[0].metadata["Title"].values[0].empty())
796 pagetitlearray.push_back (response.docInfo[0].metadata["Title"].values[0]);
797
798 if (args["gt"] != "1") {
799 MetadataInfo_t *parenttitle = response.docInfo[0].metadata["Title"].parent;
800 while (parenttitle != NULL) {
801 if (!parenttitle->values[0].empty())
802 pagetitlearray.push_back (parenttitle->values[0]);
803 parenttitle = parenttitle->parent;
804 }
805 }
806 reverse (pagetitlearray.begin(), pagetitlearray.end());
807 text_t pagetitle;
808 joinchar (pagetitlearray, ": ", pagetitle);
809 // remove html tags from the title
810 text_t::iterator open_tag=pagetitle.begin();
811 while (open_tag < pagetitle.end()) {
812 if (*open_tag == '<') {
813 text_t::iterator close_tag=open_tag+1;
814 text_t::iterator donechar=pagetitle.end();
815 while (close_tag < donechar) {
816 if (*close_tag == '>')
817 break;
818 ++close_tag;
819 }
820 if (close_tag < donechar) // remove this html tag, replace with space
821 *close_tag=' ';
822 pagetitle.erase(open_tag, close_tag);
823 }
824 ++open_tag;
825 }
826 disp.setmacro ("pagetitle", "document", pagetitle);
827
828 // custom header info
829 text_t custom_header;
830 if (is_top (arg_d)) {
831 custom_header = response.docInfo[0].metadata["gs.DocumentHeader"].values[0];
832 if (custom_header.empty()) {
833 // try ex header
834 custom_header = response.docInfo[0].metadata["DocumentHeader"].values[0];
835 }
836 } else {
837 MetadataInfo_t *parentch = response.docInfo[0].metadata["gs.DocumentHeader"].parent;
838 while (parentch != NULL) {
839 custom_header = parentch->values[0];
840 parentch = parentch->parent;
841 }
842 if (custom_header.empty()) {
843 // try ex header
844 MetadataInfo_t *parentch = response.docInfo[0].metadata["DocumentHeader"].parent;
845 while (parentch != NULL) {
846 custom_header = parentch->values[0];
847 parentch = parentch->parent;
848 }
849 }
850 }
851 if (!custom_header.empty()) {
852 disp.setmacro("documentheader", "document", custom_header);
853 }
854
855 if (is_top (arg_d))
856 disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(response.docInfo[0].metadata["archivedir"].values[0]));
857 else {
858 MetadataInfo_t *parentad = response.docInfo[0].metadata["archivedir"].parent;
859 text_t thisOID;
860 while (parentad != NULL) {
861 thisOID = parentad->values[0];
862 parentad = parentad->parent;
863 }
864 disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(thisOID));
865 }
866 }
867 } else {
868 if (!arg_cl.empty()) {
869
870 // create the currentnodevalue macro - this is the value of the node
871 // in the hierarchy that is currently open.
872 if (get_info (arg_cl, collection, args["l"], metadata, false, collectproto, response, logout)) {
873 text_t &title = response.docInfo[0].metadata["Title"].values[0];
874 disp.setmacro ("currentnodevalue", "document", title);
875 }
876 // get metadata for top level classification
877 text_t classtop;
878 get_top (arg_cl, classtop);
879 metadata.insert ("childtype");
880 metadata.insert ("parameters");
881
882 if (get_info (classtop, collection, args["l"], metadata, false, collectproto, response, logout)) {
883
884 text_t &title = response.docInfo[0].metadata["Title"].values[0];
885 bool unknown = false;
886
887 // test if we have macros defined for this classification's
888 // metadata name - if not we'll just display the name
889 text_t tmp;
890 text_t macroname="_label" + title + "_";
891 disp.expandstring ("Global", macroname, tmp);
892 if (tmp == macroname) unknown = true; // it wasn't expanded
893
894 if (unknown) {
895 disp.setmacro ("pagetitle", "document", title);
896 } else {
897 disp.setmacro ("pagetitle", "document", macroname);
898 }
899 /* for ns4/image layout compatibility. when this is no longer
900 * needed, set imagethispage to _label+title+_ */
901 text_t titlemacroname="_titleimage" + title + "_";
902 disp.expandstring ("Global", titlemacroname, tmp);
903 if (tmp == titlemacroname) { /* _titleimage$META_ isn't defined */
904 if (!unknown) /* _label$META_ is defined */
905 disp.setmacro ("imagethispage", "document", macroname);
906 else
907 disp.setmacro ("imagethispage", "document", title);
908 } else { /* _titleimage$META_ is defined */
909 disp.setmacro ("imagethispage", "document", titlemacroname);
910 }
911
912 //if the document is not a document from a collection
913 //we must set the macro to be an empty string
914 disp.setmacro ("relateddoc", "document", "");
915
916 // Add macros specific to the Collage/Phind classifiers
917 text_t &childtype = response.docInfo[0].metadata["childtype"].values[0];
918 if (childtype == "Collage") {
919
920 text_t::iterator a = arg_cl.begin();
921 text_t::iterator b = arg_cl.end();
922
923 bool collage = true;
924 while (a != b) {
925 if (*a == 46) collage = false;
926 ++a;
927 }
928
929 if (collage) {
930 disp.setmacro ("collageclassifier", "document", "_collageapplet_");
931
932 // Next, macros that control the way the classifier is displayed
933 text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
934
935 // extract key=value pairs and set as macros
936 text_t::iterator here = parameters.begin();
937 text_t::iterator end = parameters.end();
938 text_t key, value;
939
940 while (here != end) {
941 // get the next key and value pair
942 here = getdelimitstr (here, end, '=', key);
943 here = getdelimitstr (here, end, ';', value);
944
945 // store this key=value pair
946 if (!key.empty() && !value.empty()) {
947 disp.setmacro ("collage"+key, "document", value);
948 }
949 }
950
951
952 }
953 }
954
955 if (childtype == "Phind") {
956
957 // First, a macro to display the phind classifier
958 disp.setmacro ("phindclassifier", "document", "_phindapplet_");
959
960 // Next, macros that control the way the classifier is displayed
961 text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
962
963 // extract key=value pairs and set as macros
964 text_t::iterator here = parameters.begin();
965 text_t::iterator end = parameters.end();
966 text_t key, value;
967
968 while (here != end) {
969 // get the next key and value pair
970 here = getdelimitstr (here, end, '=', key);
971 here = getdelimitstr (here, end, ';', value);
972
973 // store this key=value pair
974 if (!key.empty() && !value.empty()) {
975 disp.setmacro (key, "document", value);
976 }
977 }
978 } // end if (childtype == "Phind")
979 }
980 } // end if (!arg_cl.empty()) {
981 }
982}
983
984
985bool documentaction::do_action(cgiargsclass &args, recptprotolistclass *protos,
986 browsermapclass *browsers, displayclass &disp,
987 outconvertclass &outconvert, ostream &textout,
988 ostream &logout)
989{
990 if ((args["book"] == "flashxml") && (!args["d"].empty()))
991 {
992 return do_action_flashxml(args,protos,browsers,disp,outconvert,textout,logout);
993 }
994 else if ((args["book"] == "on") && (!args["d"].empty()))
995 {
996 return do_action_book(args,protos,browsers,disp,outconvert,textout,logout);
997 }
998 else
999 {
1000 return do_action_html(args,protos,browsers,disp,outconvert,textout,logout);
1001 }
1002
1003}
1004
1005//displaying the normal display when bookswitch=0(html)
1006bool documentaction::do_action_html(cgiargsclass &args, recptprotolistclass *protos,
1007 browsermapclass *browsers, displayclass &disp,
1008 outconvertclass &outconvert, ostream &textout,
1009 ostream &logout)
1010{
1011 // must have a valid collection server
1012 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
1013 if (collectproto == NULL) {
1014 logout << "documentaction::do_action called with NULL collectproto\n";
1015 textout << outconvert << disp << "_document:header_\n"
1016 << "Error: Attempt to get document without setting collection\n"
1017 << "_document:footer_\n";
1018 } else {
1019
1020 text_t OID = args["d"];
1021 if (OID.empty()) OID = args["cl"];
1022 if (OID.empty()) {
1023 textout << outconvert << disp << "Document contains no data_document:footer_\n";
1024 return true;
1025 }
1026
1027
1028 if (formatinfo.DocumentUseHTML && !args["d"].empty()) {
1029
1030 if (args["f"] == "1") {
1031 textout << outconvert << disp
1032 << "<html><head></head>\n"
1033 << "<frameset rows=\"68,*\" noresize border=0>\n"
1034 << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
1035#ifndef DOCHANDLE
1036 << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d="
1037 << args["d"] << "\">"
1038#else
1039 << "<frame name=\"documenttop\" frameborder=0 src=\"_httpdocumenthandle_("
1040 << args["c"] << "," << args["d"] << ")\">"
1041#endif
1042 << "<noframes>\n"
1043 << "<p>You must have a frame enabled browser to view this.</p>\n"
1044 << "</noframes>\n"
1045 << "</frameset>\n"
1046 << "</html>\n";
1047 } else {
1048 output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
1049 }
1050 return true;
1051 }
1052
1053
1054 textout << outconvert << disp << "_document:header_\n"
1055 << "_document:content_\n";
1056
1057 // output the table of contents
1058 browsetoolsclass b;
1059 b.output_toc(args, browsers, formatinfo, collectproto,
1060 disp, outconvert, textout, logout);
1061
1062 if (formatinfo.DocumentArrowsTop && !args["d"].empty()) {
1063 textout << outconvert << disp << "_document:navarrowstop_\n";
1064 }
1065
1066 //output the related documents (may be the empty string)
1067 //will not output the docs if a format string is specified
1068 textout << outconvert << disp << "_document:relateddoc_\n";
1069
1070 // output the document text
1071 if (!args["d"].empty()) {
1072 output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
1073 }
1074
1075 textout << outconvert << disp << "_document:footer_\n";
1076 }
1077 return true;
1078}
1079
1080//displaying the book display when bookswitch=on
1081bool documentaction::do_action_book(cgiargsclass &args, recptprotolistclass *protos,
1082 browsermapclass *browsers, displayclass &disp,
1083 outconvertclass &outconvert, ostream &textout,
1084 ostream &logout)
1085{
1086 // must have a valid collection server
1087 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
1088 if (collectproto == NULL)
1089 {
1090 logout << "documentaction::do_action called with NULL collectproto\n";
1091 textout << outconvert << disp << "_document:header_\n"
1092 << "Error: Attempt to get document without setting collection\n";
1093 }
1094 else
1095 {
1096 text_t OID = args["d"];
1097 if (OID.empty()) OID = args["cl"];
1098 if (OID.empty())
1099 {
1100 textout << outconvert << disp << "Document contains no data\n";
1101 return true;
1102 }
1103
1104 if (formatinfo.DocumentUseHTML && !args["d"].empty())
1105 {
1106 if (args["f"] == "1")
1107 {
1108 textout << outconvert << disp
1109 << "<html><head></head>\n"
1110 << "<frameset rows=\"68,*\" noresize border=0>\n"
1111 << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
1112 #ifndef DOCHANDLE
1113 << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d="
1114 << args["d"] << "\">"
1115 #else
1116 << "<frame name=\"documenttop\" frameborder=0 src=\"_httpdocumenthandle_("
1117 << args["c"] << "," << args["d"] << ")\">"
1118 #endif
1119 << "<noframes>\n"
1120 << "<p>You must have a frame enabled browser to view this.</p>\n"
1121 << "</noframes>\n"
1122 << "</frameset>\n"
1123 << "</html>\n";
1124 }
1125 else
1126 {
1127 output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
1128 }
1129
1130 return true;
1131 }
1132
1133
1134 //the header bit and the navigation button
1135 textout << outconvert << disp << "_document:header_\n" << "_document:content_\n";
1136
1137 //display the book
1138 textout << outconvert << disp << "_document:flashbook_\n";
1139
1140 //the footer bit without the document arrow
1141 textout << outconvert << disp << "</div> <!-- id=document -->\n";
1142 textout << outconvert << disp << "_endspacer__htmlfooter_\n";
1143 }
1144
1145 return true;
1146}
1147
1148//Displaying the xml when bookswitch=flashxml
1149bool documentaction::do_action_flashxml(cgiargsclass &args, recptprotolistclass *protos,
1150 browsermapclass *browsers, displayclass &disp,
1151 outconvertclass &outconvert, ostream &textout,
1152 ostream &logout)
1153{
1154 // must have a valid collection server
1155 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
1156 if (collectproto == NULL)
1157 {
1158 logout << "documentaction::do_action called with NULL collectproto\n";
1159 textout << outconvert << disp
1160 << "<Message>\n"
1161 << " Error: Attempt to get document without setting collection\n"
1162 << "</Message>\n";
1163 }
1164 else
1165 {
1166 text_t OID = args["d"];
1167 if (OID.empty()) OID = args["cl"];
1168 if (OID.empty())
1169 {
1170 textout << outconvert << disp
1171 << "<Message>\n"
1172 << " Document contains no data\n"
1173 << "</Message>\n";
1174 return true;
1175 }
1176
1177 if (formatinfo.DocumentUseHTML && !args["d"].empty())
1178 {
1179 if (args["f"] == "1")
1180 {
1181 textout << outconvert << disp
1182 << "<Message>\n"
1183 << " Using frames makes no sense for XML output\n"
1184 << "</Message>\n";
1185 }
1186 else
1187 {
1188 output_document_flashxml (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
1189 }
1190
1191 return true;
1192 }
1193
1194 // output the document text
1195 if (!args["d"].empty())
1196 {
1197 output_document_flashxml (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
1198 }
1199 }
1200
1201 return true;
1202}
1203
1204
1205
1206void documentaction::output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
1207 const TermInfo_tarray &terminfo, const text_t &OID,
1208 bool highlight, int hastxt, int wanttext,
1209 text_t &collection, recptproto *collectproto,
1210 browsermapclass *browsers, displayclass &disp,
1211 outconvertclass &outconvert, ostream &textout,
1212 ostream &logout, cgiargsclass &args) {
1213
1214 DocumentRequest_t docrequest;
1215 DocumentResponse_t docresponse;
1216 comerror_t err;
1217 if (hastxt == 1) {
1218
1219 if (wanttext) {
1220 // get the text
1221 docrequest.OID = OID;
1222 collectproto->get_document (collection, docrequest, docresponse, err, logout);
1223
1224 // cut down on overhead by not using formattools if we only want the text
1225 // (wanttext will equal 2 if we want text and other stuff too)
1226 if (wanttext == 1)
1227 if (highlight) {
1228 highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout);
1229 } else {
1230 textout << outconvert << disp << docresponse.doc;
1231 }
1232 }
1233
1234 if (wanttext != 1) {
1235 text_tmap options;
1236 options["text"] = docresponse.doc;
1237
1238 if (formatinfo.AllowExtendedOptions) {
1239 browsetoolsclass b;
1240 b.load_extended_options(options, args, browsers, formatinfo,
1241 collectproto, disp, outconvert, logout);
1242 }
1243
1244 text_t doctext
1245 = get_formatted_string (collection, collectproto, docinfo, disp,
1246 formatlistptr, options, logout);
1247
1248 if (highlight) {
1249 highlighttext(doctext, args, terminfo, disp, outconvert, textout);
1250 } else {
1251 textout << outconvert << disp << doctext;
1252 }
1253 }
1254 }
1255}
1256
1257
1258void documentaction::output_document (const text_t &OID, cgiargsclass &args,
1259 recptproto *collectproto, browsermapclass *browsers,
1260 displayclass &disp, outconvertclass &outconvert,
1261 ostream &textout, ostream &logout) {
1262 FilterResponse_t inforesponse;
1263 FilterResponse_t queryresponse;
1264 text_tset metadata;
1265 bool getParents = false;
1266 bool highlight = false;
1267 int wanttext = 0;
1268 int arg_gt = args.getintarg("gt");
1269 text_t &collection = args["c"];
1270
1271 // if we have a query string and highlighting is turned on we need
1272 // to redo the query to get the terms for highlighting
1273
1274 if (!args["q"].empty() && args.getintarg("hl")) {
1275
1276 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
1277 bool segment = false;
1278 if (cinfo != NULL) {
1279 segment = cinfo->isSegmented;
1280 }
1281 FilterRequest_t request;
1282 comerror_t err;
1283 request.filterResultOptions = FRmatchTerms;
1284 text_t formattedstring = args["q"];
1285 format_querystring (formattedstring, args.getintarg("b"), segment);
1286 set_queryfilter_options (request, formattedstring, args);
1287 args["q"] = formattedstring; // need to set this here for phrase
1288 // highlighting, where we look at the querystring
1289 collectproto->filter (args["c"], request, queryresponse, err, logout);
1290 if (err != noError) {
1291 outconvertclass text_t2ascii;
1292 logout << text_t2ascii
1293 << "documentaction::output_document: call to QueryFilter failed "
1294 << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
1295 highlight = false;
1296 } else {
1297 highlight = true;
1298 }
1299 }
1300
1301 format_t *formatlistptr = new format_t();
1302 parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
1303
1304 metadata.insert ("hastxt");
1305 metadata.insert ("haschildren");
1306
1307 if (formatinfo.DocumentText == "[Text]")
1308 wanttext = 1;
1309 else {
1310 char *docformat = formatinfo.DocumentText.getcstr();
1311 if (strstr (docformat, "[Text]") != NULL)
1312 wanttext = 2;
1313 delete []docformat;
1314 }
1315
1316 textout << outconvert << "<div class=\"documenttext\">\n";
1317
1318 if (get_info (OID, collection, args["l"], metadata, getParents, collectproto, inforesponse, logout)) {
1319 int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
1320 int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
1321
1322 if (arg_gt == 0) {
1323 output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
1324 OID, highlight, hastxt, wanttext, collection, collectproto,
1325 browsers, disp, outconvert, textout, logout, args);
1326
1327 } else {
1328
1329 ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
1330
1331 // text is to be expanded
1332 text_t exOID = OID;
1333 if (haschildren != 1) exOID = get_parent (OID);
1334 if (exOID.empty()) exOID = OID;
1335
1336 // if we're not in a document (i.e. we're in a top level classification)
1337 // we need to pass "is_classify = true" to get_contents so that it
1338 // doesn't recurse all the way through each document in the classification
1339 bool is_classify = false;
1340 if (args["d"].empty()) is_classify = true;
1341
1342 get_contents (exOID, is_classify, metadata, collection, args["l"],
1343 collectproto, inforesponse, logout);
1344
1345 ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
1346 ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
1347
1348 if (arg_gt == 1) {
1349 // check if there are more than 10 sections containing text to be expanded -
1350 // if there are output warning message - this isn't a great way to do this
1351 // since the sections may be very large or very small - one day I'll fix it
1352 // -- Stefan.
1353 int seccount = 0;
1354 while (sechere != secend) {
1355 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
1356 if (shastxt == 1) ++seccount;
1357 if (seccount > 10) break;
1358 ++sechere;
1359 }
1360 if (seccount > 10) {
1361 // more than 10 sections so output warning message and text
1362 // for current section only
1363 textout << outconvert << disp << "<div class=\"warning\">_document:textltwarning_</div>\n";
1364
1365 output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
1366 OID, highlight, hastxt, wanttext, collection,
1367 collectproto, browsers, disp, outconvert, textout, logout, args);
1368
1369 }
1370 else arg_gt = 2;
1371 }
1372
1373 if (arg_gt == 2) {
1374 // get the text for each section
1375 sechere = inforesponse.docInfo.begin();
1376 int count = 0;
1377 while (sechere != secend) {
1378 textout << outconvert << disp << "\n<p><a name=" << (*sechere).OID << "></a>\n";
1379
1380 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
1381
1382 output_text (*sechere, formatlistptr, queryresponse.termInfo,
1383 (*sechere).OID, highlight, shastxt, wanttext, collection,
1384 collectproto, browsers, disp, outconvert, textout, logout, args);
1385 ++count;
1386 ++sechere;
1387 }
1388 }
1389 }
1390 }
1391 textout << outconvert << "</div>\n";
1392 delete formatlistptr;
1393}
1394
1395void documentaction::output_document_flashxml(const text_t &OID, cgiargsclass &args,
1396 recptproto *collectproto, browsermapclass *browsermap,
1397 displayclass &disp, outconvertclass &outconvert,
1398 ostream &textout, ostream &logout) {
1399 //if this is not at the document level --> do Nothing!!
1400 if (args["d"].empty())
1401 return;
1402
1403 //if we have a query string and highlighting is turned on we need
1404 //to redo the query to get the terms for highlighting
1405 FilterResponse_t queryresponse;
1406 bool highlight = false;
1407 if (!args["q"].empty() && args.getintarg("hl"))
1408 {
1409 text_t &collection = args["c"];
1410 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
1411 bool segment = false;
1412 if (cinfo != NULL)
1413 {
1414 segment = cinfo->isSegmented;
1415 }
1416 FilterRequest_t request;
1417 comerror_t err;
1418 request.filterResultOptions = FRmatchTerms;
1419 text_t formattedstring = args["q"];
1420 format_querystring (formattedstring, args.getintarg("b"), segment);
1421 set_queryfilter_options (request, formattedstring, args);
1422 args["q"] = formattedstring; //need to set this here for phrase
1423 //highlighting, where we look at the querystring
1424 collectproto->filter (args["c"], request, queryresponse, err, logout);
1425 if (err != noError)
1426 {
1427 outconvertclass text_t2ascii;
1428 logout << text_t2ascii
1429 << "documentaction::output_document: call to QueryFilter failed "
1430 << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
1431 highlight = false;
1432 }
1433 else
1434 {
1435 highlight = true;
1436 }
1437 }
1438
1439 FilterResponse_t response;
1440 bool getParents = false;
1441 text_tset metadata;
1442 text_t classifytype, classification, formatstring;
1443
1444 //metadata elements needed by recurse_contents
1445 metadata.insert ("Title");
1446 metadata.insert ("haschildren");
1447
1448 //protocol call
1449 if (!get_info (OID, args["c"], args["l"], metadata, getParents, collectproto, response, logout))
1450 return;
1451
1452 recurse_contents (response.docInfo[0], args, metadata,
1453 getParents, collectproto, disp, outconvert, textout, logout, highlight, queryresponse.termInfo);
1454}
1455
1456void documentaction::recurse_contents(ResultDocInfo_t &section, cgiargsclass &args,
1457 text_tset &metadata, bool &getParents,
1458 recptproto *collectproto, displayclass &disp,
1459 outconvertclass &outconvert, ostream &textout, ostream &logout,
1460 bool highlight, const TermInfo_tarray &terminfo)
1461{
1462 text_t formatstring;
1463
1464 bool is_classify = false;
1465
1466 //output this section
1467 text_t classification = "Document";
1468
1469 textout << outconvert << disp << "<Section>\n";
1470
1471 //get the title
1472 textout << outconvert << disp << "<Description>\n<Metadata name=\"Title\">";
1473 text_t t_title = section.metadata["Title"].values[0];
1474 //if it is highlighted
1475 /*if (highlight == true)
1476 {
1477 highlighttext(t_title, args, terminfo, disp, outconvert, textout);
1478 }
1479 else
1480 {*/
1481 textout << outconvert << disp << t_title;
1482 //}
1483 textout << outconvert << disp << "</Metadata>\n</Description>\n";
1484
1485 //get the text
1486 DocumentRequest_t docrequest;
1487 DocumentResponse_t docresponse;
1488 comerror_t err;
1489 docrequest.OID = section.OID;
1490 text_t &collection = args["c"];
1491 collectproto->get_document(collection, docrequest, docresponse, err, logout);
1492 //if it is highlighted
1493 if (highlight == true)
1494 {
1495 highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout);
1496 }
1497 else
1498 {
1499 textout << outconvert << disp << docresponse.doc;
1500 }
1501 textout << outconvert << disp << "\n";
1502
1503 int haschildren = section.metadata["haschildren"].values[0].getint();
1504
1505 // recurse through children
1506 if (haschildren == 1)
1507 {
1508 FilterResponse_t tmp;
1509 get_children (section.OID, args["c"], args["l"], metadata, getParents, collectproto, tmp, logout);
1510 ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
1511 ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
1512
1513 while (thisdoc != lastdoc)
1514 {
1515 recurse_contents (*thisdoc, args, metadata, getParents, collectproto, disp, outconvert, textout, logout, highlight, terminfo);
1516 ++thisdoc;
1517 }
1518 }
1519
1520 textout << outconvert << disp << "</Section>\n";
1521}
1522
1523void documentaction::set_arrow_macros (cgiargsclass &args, recptproto *collectproto,
1524 displayclass &disp, ostream &logout) {
1525
1526 text_tset metadata;
1527 FilterResponse_t response;
1528 FilterResponse_t presponse;
1529
1530 int haschildren = 0;
1531 text_tarray next_siblings;
1532 text_t previous_sibling;
1533 text_t &arg_d = args["d"];
1534
1535 // get info on current section
1536 metadata.insert("haschildren");
1537 if (!get_info(arg_d, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
1538 logout << "error 1 in documentaction::set_arrow_macros\n";
1539 return;
1540 }
1541 haschildren = response.docInfo[0].metadata["haschildren"].values[0].getint();
1542
1543 // get OIDs of next and previous siblings of current section and
1544 // all it's parents
1545 int parentcount = countchar(arg_d.begin(), arg_d.end(), '.');
1546 text_t thisoid = arg_d;
1547 while (parentcount > 0) {
1548 get_children (get_parent(thisoid), args["c"], args["l"], metadata, false,
1549 collectproto, response, logout);
1550 ResultDocInfo_tarray::iterator this_sibling = response.docInfo.begin();
1551 ResultDocInfo_tarray::iterator last_sibling = response.docInfo.end();
1552 bool first = true;
1553 while (this_sibling != last_sibling) {
1554 if ((*this_sibling).OID == thisoid) {
1555 if (!first && next_siblings.empty()) {
1556 previous_sibling = (*(this_sibling-1)).OID;
1557 int section_has_children = (*(this_sibling-1)).metadata["haschildren"].values[0].getint();
1558 // if previous sibling has children we need to recurse
1559 // down to the last descendant
1560 while (section_has_children) {
1561 get_children (previous_sibling, args["c"], args["l"], metadata, false,
1562 collectproto, presponse, logout);
1563 if (!presponse.docInfo.empty()) {
1564 ResultDocInfo_tarray::iterator it = presponse.docInfo.end() - 1;
1565 previous_sibling = (*it).OID;
1566 section_has_children = (*it).metadata["haschildren"].values[0].getint();
1567 } else {
1568 section_has_children = 0; // this should never happen
1569 }
1570 }
1571 }
1572
1573 if ((this_sibling+1) != last_sibling) {
1574 next_siblings.push_back((*(this_sibling+1)).OID);
1575 } else {
1576 next_siblings.push_back("");
1577 }
1578 break;
1579 }
1580 ++this_sibling;
1581 first = false;
1582 }
1583 thisoid = get_parent(thisoid);
1584 --parentcount;
1585 }
1586
1587 // work out values for next link
1588 if (haschildren) {
1589#ifndef DOCHANLE
1590 disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
1591 "&amp;d=" + arg_d + ".fc");
1592#else
1593 disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+arg_d + ".fc)";
1594
1595#endif
1596
1597 } else {
1598 text_tarray::const_iterator h = next_siblings.begin();
1599 text_tarray::const_iterator e = next_siblings.end();
1600 while (h != e) {
1601 if (!(*h).empty()) {
1602#ifndef DOCHANLE
1603 disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
1604 "&amp;d=" + *h);
1605#else
1606 disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+*h+")";
1607
1608#endif
1609
1610 break;
1611 }
1612 ++h;
1613 }
1614 }
1615
1616 // work out value for previous link
1617 if (!previous_sibling.empty()) {
1618#ifndef DOCHANDLE
1619 disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
1620 "&amp;d=" + previous_sibling);
1621#else
1622 disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+ previous_sibling+")");
1623
1624#endif
1625
1626 } else {
1627 if (countchar(arg_d.begin(), arg_d.end(), '.')) {
1628#ifndef DOCHANDLE
1629 disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
1630 "&amp;d=" + get_parent(arg_d));
1631#else
1632 disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+get_parent(arg_d)+")");
1633
1634#endif
1635
1636 }
1637 }
1638}
Note: See TracBrowser for help on using the repository browser.