source: main/trunk/greenstone2/runtime-src/src/recpt/documentaction.cpp

Last change on this file was 38924, checked in by kjdon, 2 weeks ago

added archivedir option for backwards compatibility for old pre built collections

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