source: main/tags/2.80/gsdl/src/recpt/documentaction.cpp@ 24528

Last change on this file since 24528 was 14095, checked in by mdewsnip, 17 years ago

Removed non-HTML 4 compliant <p> tag.

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