source: gsdl/trunk/runtime-src/src/recpt/documentaction.cpp@ 17985

Last change on this file since 17985 was 17985, checked in by mdewsnip, 15 years ago

Added "_cltop_" macro so you can tell which classifier you're in.

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