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

Last change on this file since 10873 was 10873, checked in by jrm21, 19 years ago

documentaction modified for new HTML4/CSS stuff (eg stop looking for
icon width macros). Other files modified to tidy up output (put tag
attribute values in quotes, use & instead of &, etc). Not quite
finished yet but it works.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 44.5 KB
RevLine 
[248]1/**********************************************************************
2 *
3 * documentaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
[533]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.
[248]9 *
[533]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 *
[248]24 *********************************************************************/
25
[443]26#include <string.h>
[4936]27
[248]28#include "documentaction.h"
29#include "browsetools.h"
30#include "OIDtools.h"
[267]31#include "querytools.h"
32#include "unitool.h"
[1148]33#include "gsdltools.h"
[3322]34#include "highlighttext.h"
[248]35
36documentaction::documentaction () {
[1270]37 recpt = NULL;
[600]38
[1270]39
[248]40 // this action uses cgi variables "a", "d", "cl",
[257]41 // "x", "gc", "gt", "gp", and "hl"
[248]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;
[7441]55 arg_ainfo.argdefault = g_EmptyText;
[248]56 arg_ainfo.savedarginfo = cgiarginfo::can;
57 argsinfo.addarginfo (NULL, arg_ainfo);
58
[722]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
[248]69 arg_ainfo.shortname = "cl";
70 arg_ainfo.longname = "classification OID";
71 arg_ainfo.multiplechar = true;
72 arg_ainfo.defaultstatus = cgiarginfo::none;
[7441]73 arg_ainfo.argdefault = g_EmptyText;
[248]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
[257]88 // text function 0 = not expanded, 1 = expand unless
89 // there are more than 10 sections containing text,
90 // 2 = expand all
[248]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;
[7441]105 arg_ainfo.argdefault = g_EmptyText;
[248]106 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
107 argsinfo.addarginfo (NULL, arg_ainfo);
108
[257]109 // in this action "hl" is the "highlighting on/
[3322]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)
[257]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
[248]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";
[282]129 arg_ainfo.savedarginfo = cgiarginfo::must;
[248]130 argsinfo.addarginfo (NULL, arg_ainfo);
[870]131
[5124]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
[870]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);
[1941]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
[6645]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;
[7441]177 arg_ainfo.argdefault = g_EmptyText;
[6645]178 arg_ainfo.savedarginfo = cgiarginfo::must;
179 argsinfo.addarginfo (NULL, arg_ainfo);
180
[248]181}
182
183documentaction::~documentaction () {
184}
185
[284]186bool documentaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
[4974]187 recptprotolistclass *protos, ostream &logout) {
[284]188
[4974]189 if(!args["d"].empty())
190 {
[4984]191 text_t docTop;
192 get_top(args["d"],docTop);
193
[4974]194 recptproto* collectproto = protos->getrecptproto (args["c"], logout);
195 if (collectproto != NULL)
196 {
197 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
198
[5024]199 if(cinfo->authenticate == "document")
[4974]200 {
201 // both are either commented out or uncomment and are empty
[5024]202 if (cinfo->public_documents.empty() && cinfo->private_documents.empty())
[4974]203 {
204 //deny everything
205 args["uan"] = "1";
206 args["ug"] = cinfo->auth_group;
207 }
208
[5024]209 // both public_documents and private_documents are turned on !
210 else if (!cinfo->public_documents.empty() && !cinfo->private_documents.empty())
[4974]211 {
212 //deny everything
213 args["uan"] = "1";
214 args["ug"] = cinfo->auth_group;
215 }
216
[5179]217 // if public_documents is set but this document isn't
218 // listed in it we need to authenticate
219 else if ((!cinfo->public_documents.empty()) &&
220 (cinfo->public_documents.find(docTop) == cinfo->public_documents.end()))
221 {
222 args["uan"] = "1";
223 args["ug"] = cinfo->auth_group;
224 }
[4974]225
[5179]226 // if private_documents is set and this document is
227 // listed in it we need to authenticate
228 else if ((!cinfo->private_documents.empty()) &&
229 (cinfo->private_documents.find(docTop) != cinfo->private_documents.end()))
230 {
231 args["uan"] = "1";
232 args["ug"] = cinfo->auth_group;
233 }
[4974]234
235 }
236 }
237 }
238 // check gc argument
239 int arg_gc = args.getintarg("gc");
[2805]240 if (arg_gc < 0 || arg_gc > 2) {
[284]241 logout << "Warning: \"gc\" argument out of range (" << arg_gc << ")\n";
242 cgiarginfo *gcinfo = argsinfo.getarginfo ("gc");
243 if (gcinfo != NULL) args["gc"] = gcinfo->argdefault;
244 }
245
246 // check gt argument (may be either 0, 1 or 2)
247 int arg_gt = args.getintarg("gt");
248 if (arg_gt != 0 && arg_gt != 1 && arg_gt != 2) {
249 logout << "Warning: \"gt\" argument out of range (" << arg_gt << ")\n";
250 cgiarginfo *gtinfo = argsinfo.getarginfo ("gt");
251 if (gtinfo != NULL) args["gt"] = gtinfo->argdefault;
252 }
253
254 // check hl argument
255 int arg_hl = args.getintarg("hl");
[3322]256 if (arg_hl < 0 || arg_hl > 2) {
[284]257 logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n";
258 cgiarginfo *hlinfo = argsinfo.getarginfo ("hl");
259 if (hlinfo != NULL) args["hl"] = hlinfo->argdefault;
260 }
261
262 // check x argument
263 int arg_x = args.getintarg("x");
264 if (arg_x != 0 && arg_x != 1) {
265 logout << "Warning: \"x\" argument out of range (" << arg_x << ")\n";
266 cgiarginfo *xinfo = argsinfo.getarginfo ("x");
267 if (xinfo != NULL) args["x"] = xinfo->argdefault;
268 }
269
[1941]270 //checks whether rd arg is valid
271 int arg_rd = args.getintarg("rd");
272 if (arg_rd != 0 && arg_rd != 1) {
273 logout << "Warning: \"rd\" argument out of range (" << arg_rd << ")\n";
274 cgiarginfo *rdinfo = argsinfo.getarginfo ("rd");
275 if (rdinfo != NULL) args["rd"] = rdinfo->argdefault;
276 }
277
278
[248]279 return true;
280}
281
[758]282void documentaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
283 response_t &response,text_t &response_data,
284 ostream &logout) {
[722]285
[758]286 if ((args["il"] == "w") && (!args["d"].empty())) {
[722]287
[758]288 recptproto* collectproto = protos->getrecptproto (args["c"], logout);
289 if (collectproto != NULL) {
290
[722]291 text_tset metadata;
292 FilterResponse_t filt_response;
[758]293 text_t top;
[722]294
295 metadata.insert ("URL");
[758]296
297 // get metadata for parent document
298 get_top (args["d"], top);
[7432]299 if (get_info (top, args["c"], args["l"], metadata, false, collectproto, filt_response, logout)) {
[781]300 text_t url = filt_response.docInfo[0].metadata["URL"].values[0];
[758]301
302 response = location;
303 response_data = url;
304 return;
305 } else {
306 // error, no URL
307 logout << "Error: documentaction::get_cgihead_info failed on get_info" << endl;
308 }
[722]309 }
[758]310 }
311 response = content;
312 response_data = "text/html";
[248]313}
314
[600]315// set_widthtspace calculates how wide the spaces in the nav bar should
316// be and sets the appropriate macro
[4774]317void documentaction::set_spacemacro (displayclass &disp, FilterResponse_t &response,
318 bool has_search_button) {
[600]319
320 text_t width;
321 int twidth, swidth, iwidth = 0;
322
323 int numc = response.docInfo.size();
[649]324 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
325 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
[600]326
[7433]327 disp.expandstring (displayclass::defaultpackage, "_pagewidth_", width);
[600]328 twidth = width.getint();
[9923]329
[4774]330 if (has_search_button) {
331 disp.expandstring ("query", "_searchwidth_", width);
332 iwidth += width.getint();
333 } else {
334 numc -= 1;
335 }
[600]336
337 while (dochere != docend) {
[649]338 const text_t &title = (*dochere).metadata["Title"].values[0];
[600]339
340 disp.expandstring ("document", "_" + title + "width_", width);
[9923]341 if (width == ("_" + title + "width_")) {
[649]342 disp.expandstring ("document", "_defaultwidth_", width);
[9923]343 }
[600]344 iwidth += width.getint();
[9620]345 ++dochere;
[600]346 }
[9923]347
[600]348 if ((twidth - iwidth) < numc) swidth = 2;
349 else {
350 swidth = twidth - iwidth;
351 if (numc > 0) swidth = swidth / numc;
352 }
[7433]353 disp.setmacro ("widthtspace", displayclass::defaultpackage, swidth);
[600]354}
355
[1419]356// set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros
[649]357// reponse contains 1 metadata field (Title)
358void documentaction::set_navbarmacros (displayclass &disp, FilterResponse_t &response,
[4893]359 bool has_search_button, cgiargsclass &args,
360 ColInfoResponse_t &cinfo) {
[600]361
362
[4893]363 bool use_pulldown = false;
364 text_tmap::iterator it = cinfo.format.find("NavigationBar");
365 if (it != cinfo.format.end()) {
366 if (it->second == "pulldown") {
367 use_pulldown = true;
368 }
369 }
[600]370
[4893]371 text_t topparent;
372 text_t &arg_d = args["d"];
373 text_t navigationbar = "<!-- Navigation Bar -->\n";
374
[7441]375 text_t date_extra = g_EmptyText;
[4893]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) {
[10873]382
383 navigationbar += "_navtabsearch_";
[4893]384 if (has_search_button) {
385 if (args["a"] == "q") {
[10873]386 navigationbar += "(selected)";
[4893]387 }
388 }
[928]389
[10873]390 if (has_search_button || numc == 0) navigationbar += "_navbarspacer_";
[928]391
[4893]392 bool first = true;
393 while (dochere != docend) {
[7441]394 date_extra = g_EmptyText;
[10873]395 if (!first) navigationbar += "_navbarspacer_";
[4893]396
397 text_t title = (*dochere).metadata["Title"].values[0];
[6645]398 if (title == "Date") { // a date list
399 text_t date_meta = (*dochere).metadata["mdtype"].values[0];
[7441]400 if (date_meta == g_EmptyText) {
[6645]401 date_meta = "Date";
402 }
[10873]403 date_extra = "&amp;dm="+date_meta;
[6645]404 }
[4893]405 bool unknown = false;
406
[10873]407 // test if the _tabtext$FIELD_ macro is defined, which means
408 // this is a "known" metadata type and we have a translation for it
[4893]409 text_t tmpwidth;
[10873]410 text_t macroname="_tabtext" + title + "_";
411 disp.expandstring ("document", macroname, tmpwidth);
412 if (tmpwidth == macroname) // it wasn't expanded
413 unknown = true;
[4893]414
415 // if we're inside a document all the classification buttons should be enabled
[10873]416 text_t this_tab;
417 bool is_top;
418
419 is_top = ((*dochere).OID == topparent);
420
421 // set default text fragment
422 this_tab = "_navtab_(";
423
424 if (unknown) { // just give the field name
425 if (!is_top) {
426 // work out the link for this classifier, as it isn't the
427 // current page
428 this_tab += "_httpdocument_&amp;cl=" + (*dochere).OID
429 + date_extra;
430 }
431 this_tab += "," + title + ",";
432 } else { // use the macro for this field so we get translations
433 this_tab += "_httpbrowse" + title;
434 this_tab += "_,_tabtext" + title;
435 this_tab += "_,_textdescr" + title + "_";
[4893]436 }
[10873]437
438 if (arg_d.empty() && is_top) {
439 // don't link to this classifier as it is the current one
440 this_tab += ",selected";
441 } else if (!unknown) {
442 // set the _httpbrowseXXX_ macro for this classification
443 // set the correct url for this link
444 disp.setmacro ("httpbrowse" + title, displayclass::defaultpackage, "_httpdocument_&amp;cl=" + (*dochere).OID+date_extra);
445 }
446
447 this_tab += ")";
448
449 navigationbar += this_tab;
450
[9620]451 ++dochere;
[4893]452 first = false;
453 }
[5225]454
[10873]455 if (!has_search_button && numc == 1) navigationbar += "_navbarspacer_";
[5225]456
[10873]457 navigationbar += "\n<!-- End of Navigation Bar -->\n";
[4774]458
[4893]459 } else {
[4774]460
[4893]461 navigationbar = "<form method=\"get\" name=\"navform\">\n";
462 navigationbar += "<select name=\"navbar\" onChange=\"location.href=";
463 navigationbar += "document.navform.navbar.options[document.navform.navbar.selectedIndex].value\">\n";
[600]464
[4893]465 if (args["a"] != "q" && args["cl"].empty()) {
[5019]466 navigationbar += "<option value=\"\" selected>_textselectpage_</option>\n";
[4893]467 }
468
469 if (has_search_button) {
470 navigationbar += "<option value=\"_httpquery_\"";
471 if (args["a"] == "q") {
472 navigationbar += " selected";
473 }
[10873]474 navigationbar += ">_tabtextsearch_</option>\n";
[4893]475 }
[649]476
[4893]477 while (dochere != docend) {
478 text_t title = dochere->metadata["Title"].values[0];
[6645]479 if (title == "Date") { // a date list
480 text_t date_meta = (*dochere).metadata["mdtype"].values[0];
481 if (date_meta == "") {
482 date_meta = "Date";
483 }
[10873]484 date_extra = "&amp;dm="+date_meta;
[6645]485 }
486
[10873]487 navigationbar += "<option value=\"_httpdocument_&amp;cl=" + dochere->OID +date_extra+ "\"";
[4893]488 if (topparent == dochere->OID) {
489 navigationbar += " selected";
490 }
491 navigationbar += ">" + title + "</option>\n";
[9620]492 ++dochere;
[4893]493 }
[649]494
[4893]495 navigationbar += "</select>\n";
496 navigationbar += "</form>\n";
497 }
[649]498
[7433]499 disp.setmacro ("navigationbar", displayclass::defaultpackage, navigationbar);
[600]500}
501
[248]502// define all the macros which might be used by other actions
503// to produce pages.
[758]504void documentaction::define_external_macros (displayclass &disp, cgiargsclass &args,
505 recptprotolistclass *protos, ostream &logout) {
[248]506
507 // define_external_macros sets the following macros:
508
509 // _navigationbar_ this is the navigation bar containing the search button
510 // and any classification buttons - it goes at the top of
511 // most pages. for now we're assuming that there'll always
512 // be a search button - we should probably check that there
513 // is a query action before making this assumption
514
515 // _httpbrowseXXX_ the http macros for each classification (i.e. if there
516 // are Title and Creator classifications _httpbrowseTitle_
517 // and _httpbrowseCreator_ will be set
518
[600]519 // _widthtspace_ the width of the spacers between buttons in navigation
520 // bar
[438]521
[870]522 // _httpdocument_ has '&f=1' added if displaying document inside a frame
[248]523
[870]524 // _gsdltop_ macro to replace _top targets with
525
526 // _httppagehome_ overridden home url if html collections have own homepage
527
[3880]528
[758]529 // must have a valid collection server to continue
[4936]530
[758]531 text_t &collection = args["c"];
532 if (collection.empty()) return;
533 recptproto *collectproto = protos->getrecptproto (collection, logout);
[267]534 if (collectproto == NULL) return;
[758]535
[1270]536 if (recpt == NULL) {
537 logout << "ERROR (documentaction::define_external_macros): This action does not contain\n"
538 << " information about any receptionists. The method set_receptionist was\n"
539 << " probably not called from the module which instantiated this action.\n";
540 return;
541 }
542
[248]543 outconvertclass text_t2ascii;
544 comerror_t err;
545 InfoFiltersResponse_t filterinfo;
546 FilterResponse_t response;
[649]547 text_tset metadata;
[277]548
[1347]549 // get info on current collection and load up formatinfo
550 // I'd prefer not to do this here as we're getting
551 // collection info every time (and probably also getting
552 // it in other places some of the time) - One day I'll
553 // fix it ... maybe - Stefan.
554 ColInfoResponse_t cinfo;
[870]555
[1347]556 collectproto->get_collectinfo (collection, cinfo, err, logout);
557 load_formatinfo (cinfo.format, args.getintarg("gt"));
558 // ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
559 // if (cinfo == NULL) {
560 // logout << "ERROR (documentaction::define_external_macros): get_collectinfo_ptr returned NULL\n";
561 // return;
562 // }
563 //load_formatinfo (cinfo->format, args.getintarg("gt"));
564
[870]565 if (formatinfo.DocumentUseHTML) {
566
567 // frame stuff
568 if (args["fc"] == "1") {
569 text_t httpdocument;
[7433]570 disp.expandstring (displayclass::defaultpackage, "_httpdocument_", httpdocument);
[10873]571 httpdocument += "&amp;f=1";
[7433]572 disp.setmacro ("httpdocument", displayclass::defaultpackage, httpdocument);
573 disp.setmacro ("gsdltop", displayclass::defaultpackage, "documenttop");
[2422]574 formatinfo.DocumentText = "[Text]";
[870]575 }
[1348]576 text_tmap::iterator it = cinfo.format.find ("homepage");
577 if (it != cinfo.format.end()) {
[870]578 text_t httppagehome;
579 if (get_link (args, protos, (*it).second, httppagehome, logout))
[7433]580 disp.setmacro ("httppagehome", displayclass::defaultpackage, httppagehome);
[870]581 }
582 }
583
[282]584 // don't want navigation bar if page is 'detached'
585 if (!args.getintarg("x")) {
[248]586
[282]587 collectproto->get_filterinfo (collection, filterinfo, err, logout);
588 if (err == noError) {
589 // check that there's a browse filter
590 if (filterinfo.filterNames.find ("BrowseFilter") != filterinfo.filterNames.end()) {
[248]591
[649]592 metadata.insert ("Title");
[6645]593 metadata.insert ("mdtype"); // in case there is a datelist
[405]594 bool getParents = false;
[7432]595 get_children ("", collection, args["l"], metadata, getParents, collectproto, response, logout);
[282]596
[4774]597 bool has_search_button = true;
598 collectproto->is_searchable(collection, has_search_button, err, logout);
599 if (err != noError) has_search_button = true;
600
[600]601 // calculate width of spacers and set _widthtspace_ macro
[4774]602 if (args.getintarg("v") == 0) set_spacemacro (disp, response, has_search_button);
[450]603
[1419]604 // set _navigationbar_ macro
[4893]605 set_navbarmacros (disp, response, has_search_button, args, cinfo);
[928]606
[248]607 }
[282]608 } else {
609 logout << text_t2ascii
610 << "Error (documentaction::define_external_macros()) in call to get_filterinfo() "
611 << get_comerror_string (err);
[248]612 }
613 }
614}
615
[870]616bool documentaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
617 const text_t &inlink, text_t &outlink, ostream &logout) {
618
619 FilterResponse_t response;
620 text_tset metadata;
621 metadata.insert ("section");
622
623 // check current collection first
624 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
625
[7432]626 if (get_info (inlink, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
[870]627 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
[10873]628 outlink = "_httpdocument_&amp;d=" + response.docInfo[0].metadata["section"].values[0];
[870]629 return true;
630 }
631 }
632
633 // check all the other enabled collections
634
635 if (args["ccs"] == "1" && !args["cc"].empty()) {
636 text_tarray collections;
637 splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
638
639 text_tarray::const_iterator col_here = collections.begin();
640 text_tarray::const_iterator col_end = collections.end();
641
642 while (col_here != col_end) {
643
644 // don't need to check current collection again
[9620]645 if (*col_here == args["c"]) {++col_here; continue;}
[870]646
647 collectproto = protos->getrecptproto (*col_here, logout);
648
[7432]649 if (get_info (inlink, *col_here, args["l"], metadata, false, collectproto, response, logout)) {
[870]650 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
[10873]651 outlink = "_httpdocument_&amp;c=" + *col_here + "&amp;d=" +
[870]652 response.docInfo[0].metadata["section"].values[0];
653 return true;
654 }
655 }
[9620]656 ++col_here;
[870]657 }
658 }
659 return false;
660}
661
[464]662void documentaction::load_formatinfo (const text_tmap &colformat, int gt) {
663
664 formatinfo.clear();
665 text_tmap::const_iterator format_here = colformat.begin();
666 text_tmap::const_iterator format_end = colformat.end();
667
668 while (format_here != format_end) {
[1079]669 if (((*format_here).first == "DocumentImages") &&
670 ((*format_here).second == "true"))
671 formatinfo.DocumentImages = true;
672 else if (((*format_here).first == "DocumentTitles") &&
673 ((*format_here).second == "false"))
674 formatinfo.DocumentTitles = false;
675 else if ((*format_here).first == "DocumentHeading")
676 formatinfo.DocumentHeading = (*format_here).second;
677 else if (((*format_here).first == "DocumentContents") &&
678 ((*format_here).second == "false"))
679 formatinfo.DocumentContents = false;
[464]680 else if (((*format_here).first == "DocumentArrowsBottom") &&
681 ((*format_here).second == "false"))
682 formatinfo.DocumentArrowsBottom = false;
[4868]683 else if (((*format_here).first == "DocumentArrowsTop") &&
684 ((*format_here).second == "true"))
685 formatinfo.DocumentArrowsTop = true;
[464]686 else if ((*format_here).first == "DocumentButtons")
687 splitchar ((*format_here).second.begin(), (*format_here).second.end(),
688 '|', formatinfo.DocumentButtons);
689 else if ((*format_here).first == "DocumentText")
[1941]690 formatinfo.DocumentText = (*format_here).second;
691 else if ((*format_here).first == "RelatedDocuments")
692 formatinfo.RelatedDocuments = (*format_here).second;
[870]693 else if (((*format_here).first == "DocumentUseHTML") &&
694 ((*format_here).second == "true"))
695 formatinfo.DocumentUseHTML = true;
[4972]696 else if (((*format_here).first == "AllowExtendedOptions") &&
697 ((*format_here).second == "true"))
698 formatinfo.AllowExtendedOptions = true;
[649]699 else
700 formatinfo.formatstrings[(*format_here).first] = (*format_here).second;
[870]701
[9620]702 ++format_here;
[464]703 }
704
705 // never want arrows when text is expanded
[4868]706 if (gt) {
707 formatinfo.DocumentArrowsBottom = false;
708 formatinfo.DocumentArrowsTop = false;
709 }
[464]710}
711
712
[248]713// define all the macros which are related to pages generated
[443]714// by this action. we also load up the formatinfo structure
715// here (it's used in do_action as well as here)
[758]716void documentaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
717 recptprotolistclass *protos, ostream &logout) {
[464]718
[248]719 // define_internal_macros sets the following macros:
[464]720
[277]721 // _pagetitle_ the title to be displayed at the top of the browser window
722
[248]723 // _imagethispage_ the title image to be displayed at top right of page
724
[4868]725 // _navarrowsbottom_ this may be overridden to "" when format option
[448]726 // DocumentArrowsBottom is false
727
[4868]728 // _navarrowstop_ likewise for DocumentArrowsTop
729
730 // _httpprevarrow_ links to next and previous sections of document - used
731 // _httpnextarrow_ by DocumentArrowsBottom
732
[248]733 // _header_ the header macro is overridden if we're not at a top level
734 // classification to remove the title block
[257]735
[300]736 // _thisOID_ the OID (directory) of the current document - this corresponds
737 // to the archivedir metadata element
738
[758]739 // must have a valid collection server to continue
[4936]740
741 text_t &collection = args["c"];
[758]742 if (collection.empty()) return;
743 recptproto *collectproto = protos->getrecptproto (collection, logout);
[267]744 if (collectproto == NULL) return;
[758]745
[649]746 text_tset metadata;
[248]747 FilterResponse_t response;
[277]748 text_t &arg_d = args["d"];
749 text_t &arg_cl = args["cl"];
750
[4868]751 if (!formatinfo.DocumentArrowsBottom) {
752 disp.setmacro("navarrowsbottom", "document", "");
753 } else if (!formatinfo.DocumentArrowsBottom) {
754 disp.setmacro("navarrowstop", "document", "");
755 }
[448]756
[4868]757 if (!arg_d.empty() && (formatinfo.DocumentArrowsBottom || formatinfo.DocumentArrowsTop)) {
758 // set _httpprevarrow_ and _httpnextarrow_
759 set_arrow_macros (args, collectproto, disp, logout);
760 }
761
[649]762 metadata.insert ("Title");
[738]763
764 bool fulltoc = false;
765
766 if (args["cl"] != "search") {
767 // see if there's a FullTOC string
768 text_t cl_top, full_toc;
769 get_top (arg_cl, cl_top);
770 if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
771 if (full_toc == "true") fulltoc = true;
772 }
[248]773
[738]774 if (!arg_d.empty() && !fulltoc) {
[248]775 // we're at document level
[649]776
777 metadata.insert ("archivedir");
[1347]778
[2113]779 comerror_t err;
[1347]780 OptionValue_tarray options;
[2646]781 // we need to do the query again for the z3950proto
[2113]782 if (collectproto->get_protocol_name(err)=="z3950proto") {
[1347]783 OptionValue_t opt;
[2646]784 opt.name="Term";opt.value=args["q"];options.push_back(opt);
785 opt.name="QueryType";
786 opt.value=(args.getintarg("t")) ? "ranked" : "boolean";
[1347]787 options.push_back(opt);
[2646]788 opt.name="Index";opt.value=args["h"];options.push_back(opt);
[1347]789 }
[1941]790
791 //do not display relation metadata
792 disp.setmacro ("relateddoc", "document", "");
793
794 //if preferences indicate relevant docs should be collected
795 //and there is no particular format specified then display
796 //this default format.
797 if(args["rd"] == "1" && formatinfo.RelatedDocuments.empty()){
[1347]798
[7441]799 text_t relation = g_EmptyText; //string for displaying relation metadata
[1941]800
801 //call function in formattools.cpp which will return the text of the
802 //related documents in a vertical list. This is the default format.
[4936]803
[7432]804 if (get_info (arg_d, collection, args["l"], metadata, options, false, collectproto, response, logout))
[1941]805 relation += get_related_docs(collection, collectproto, response.docInfo[0], logout);
806
807 //set macro to be the related document string
[4936]808
[1941]809 disp.setmacro ("relateddoc", "document", relation);
810 }
811
812
[277]813 // get metadata for this document and it's parents
[7432]814 if (get_info (arg_d, collection, args["l"], metadata, options,
[1347]815 true, collectproto, response, logout)) {
[1941]816
[248]817 disp.setmacro ("header", "document", "_textheader_");
[1941]818
[669]819 text_tarray pagetitlearray;
820 if (!response.docInfo[0].metadata["Title"].values[0].empty())
821 pagetitlearray.push_back (response.docInfo[0].metadata["Title"].values[0]);
[1941]822
[870]823 if (args["gt"] != "1") {
[669]824 MetadataInfo_t *parenttitle = response.docInfo[0].metadata["Title"].parent;
825 while (parenttitle != NULL) {
826 if (!parenttitle->values[0].empty())
827 pagetitlearray.push_back (parenttitle->values[0]);
828 parenttitle = parenttitle->parent;
[284]829 }
[277]830 }
[669]831 reverse (pagetitlearray.begin(), pagetitlearray.end());
832 text_t pagetitle;
833 joinchar (pagetitlearray, ": ", pagetitle);
[6936]834 // remove html tags from the title
835 text_t::iterator open_tag=pagetitle.begin();
836 while (open_tag < pagetitle.end()) {
837 if (*open_tag == '<') {
838 text_t::iterator close_tag=open_tag+1;
839 text_t::iterator donechar=pagetitle.end();
840 while (close_tag < donechar) {
841 if (*close_tag == '>')
842 break;
843 ++close_tag;
844 }
845 if (close_tag < donechar) // remove this html tag, replace with space
846 *close_tag=' ';
847 pagetitle.erase(open_tag, close_tag);
848 }
849 ++open_tag;
850 }
[277]851 disp.setmacro ("pagetitle", "document", pagetitle);
[669]852
853 if (is_top (arg_d))
[7433]854 disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(response.docInfo[0].metadata["archivedir"].values[0]));
[669]855 else {
856 MetadataInfo_t *parentad = response.docInfo[0].metadata["archivedir"].parent;
857 text_t thisOID;
858 while (parentad != NULL) {
859 thisOID = parentad->values[0];
860 parentad = parentad->parent;
861 }
[7433]862 disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(thisOID));
[669]863 }
[248]864 }
865 } else {
[277]866 if (!arg_cl.empty()) {
[248]867
[9917]868 // create the currentnodevalue macro - this is the value of the node
869 // in the hierarchy that is currently open.
870 if (get_info (arg_cl, collection, args["l"], metadata, false, collectproto, response, logout)) {
871 text_t &title = response.docInfo[0].metadata["Title"].values[0];
872 disp.setmacro ("currentnodevalue", "document", title);
873 }
[248]874 // get metadata for top level classification
[257]875 text_t classtop;
[277]876 get_top (arg_cl, classtop);
[1804]877 metadata.insert ("childtype");
[2017]878 metadata.insert ("parameters");
[1804]879
[7432]880 if (get_info (classtop, collection, args["l"], metadata, false, collectproto, response, logout)) {
[248]881
[649]882 text_t &title = response.docInfo[0].metadata["Title"].values[0];
883 bool unknown = false;
[257]884
[10873]885 // test the _iconXXXpage_ macro to see if image macros are
[649]886 // defined for this type of classification - if not we'll
887 // just display the text
888 text_t tmp;
[10873]889 text_t macroname="_icon" + title + "page_";
890 disp.expandstring ("document", macroname, tmp);
891 if (tmp == macroname) unknown = true; // it wasn't expanded
[604]892
[649]893 if (unknown) {
894 disp.setmacro ("pagetitle", "document", title);
895 disp.setmacro ("imagethispage", "document", "<h2>" + title + "</h2>");
896 } else {
897 disp.setmacro ("pagetitle", "document", "_text" + title + "page_");
898 disp.setmacro ("imagethispage", "document", "_icon" + title + "page_");
899 }
[1804]900
[1941]901 //if the document is not a document from a collection
902 //we must set the macro to be an empty string
903 disp.setmacro ("relateddoc", "document", "");
904
[6811]905 // Add macros specific to the Collage/Phind classifiers
[1804]906 text_t &childtype = response.docInfo[0].metadata["childtype"].values[0];
[6811]907 if (childtype == "Collage") {
908
909 text_t::iterator a = arg_cl.begin();
910 text_t::iterator b = arg_cl.end();
911
912 bool collage = true;
913 while (a != b) {
914 if (*a == 46) collage = false;
[9620]915 ++a;
[6811]916 }
917
[7333]918 if (collage) {
[6811]919 disp.setmacro ("collageclassifier", "document", "_collageapplet_");
[7333]920
921 // Next, macros that control the way the classifier is displayed
922 text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
923
924 // extract key=value pairs and set as macros
925 text_t::iterator here = parameters.begin();
926 text_t::iterator end = parameters.end();
927 text_t key, value;
928
929 while (here != end) {
930 // get the next key and value pair
931 here = getdelimitstr (here, end, '=', key);
932 here = getdelimitstr (here, end, ';', value);
933
934 // store this key=value pair
935 if (!key.empty() && !value.empty()) {
936 disp.setmacro ("collage"+key, "document", value);
937 }
938 }
939
940
941 }
[6811]942 }
943
[1804]944 if (childtype == "Phind") {
[2017]945
946 // First, a macro to display the phind classifier
[1804]947 disp.setmacro ("phindclassifier", "document", "_phindapplet_");
[2017]948
949 // Next, macros that control the way the classifier is displayed
950 text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
951
952 // extract key=value pairs and set as macros
953 text_t::iterator here = parameters.begin();
954 text_t::iterator end = parameters.end();
955 text_t key, value;
956
957 while (here != end) {
958 // get the next key and value pair
959 here = getdelimitstr (here, end, '=', key);
960 here = getdelimitstr (here, end, ';', value);
961
962 // store this key=value pair
963 if (!key.empty() && !value.empty()) {
964 disp.setmacro (key, "document", value);
965 }
966 }
967 } // end if (childtype == "Phind")
[248]968 }
[2017]969 } // end if (!arg_cl.empty()) {
[248]970 }
971}
972
[464]973
[758]974bool documentaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
975 browsermapclass *browsers, displayclass &disp,
[420]976 outconvertclass &outconvert, ostream &textout,
977 ostream &logout) {
[1941]978
[758]979 // must have a valid collection server
980 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
[267]981 if (collectproto == NULL) {
982 logout << "documentaction::do_action called with NULL collectproto\n";
983 textout << outconvert << disp << "_document:header_\n"
984 << "Error: Attempt to get document without setting collection\n"
985 << "_document:footer_\n";
986 } else {
[758]987
[649]988 text_t OID = args["d"];
989 if (OID.empty()) OID = args["cl"];
990 if (OID.empty()) {
991 textout << outconvert << disp << "Document contains no data_document:footer_\n";
992 return true;
993 }
[420]994
[1941]995
[1991]996 if (formatinfo.DocumentUseHTML && !args["d"].empty()) {
[870]997
[1991]998 if (args["f"] == "1") {
999 textout << outconvert << disp
1000 << "<html><head></head>\n"
1001 << "<frameset rows=\"68,*\" noresize border=0>\n"
1002 << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
1003 << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d="
1004 << args["d"] << "\">"
1005 << "<noframes>\n"
1006 << "<p>You must have a frame enabled browser to view this.</p>\n"
1007 << "</noframes>\n"
1008 << "</frameset>\n"
1009 << "</html>\n";
1010 } else {
[4936]1011 output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
[870]1012 }
[1991]1013 return true;
[870]1014 }
1015
[1941]1016
[267]1017 textout << outconvert << disp << "_document:header_\n"
1018 << "_document:content_\n";
[1079]1019
1020 // output the table of contents
1021 output_toc (args, browsers, formatinfo, collectproto,
1022 disp, outconvert, textout, logout);
[1941]1023
[4868]1024 if (formatinfo.DocumentArrowsTop && !args["d"].empty()) {
1025 textout << outconvert << disp << "_document:navarrowstop_\n";
1026 }
1027
[1941]1028 //output the related documents (may be the empty string)
1029 //will not output the docs if a format string is specified
1030 textout << outconvert << disp << "_document:relateddoc_\n";
1031
[284]1032 // output the document text
[3087]1033 if (!args["d"].empty()) {
[3666]1034 textout << outconvert << "<p>\n";
[4936]1035 output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
[3087]1036 }
[284]1037
1038 textout << outconvert << disp << "_document:footer_\n";
1039 }
1040 return true;
1041}
1042
[649]1043void documentaction::output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
[443]1044 const TermInfo_tarray &terminfo, const text_t &OID,
[649]1045 bool highlight, int hastxt, int wanttext,
[4936]1046 text_t &collection, recptproto *collectproto,
1047 browsermapclass *browsers, displayclass &disp,
1048 outconvertclass &outconvert, ostream &textout,
1049 ostream &logout, cgiargsclass &args) {
[443]1050
1051 DocumentRequest_t docrequest;
1052 DocumentResponse_t docresponse;
1053 comerror_t err;
[649]1054 if (hastxt == 1) {
[443]1055
1056 if (wanttext) {
1057 // get the text
1058 docrequest.OID = OID;
1059 collectproto->get_document (collection, docrequest, docresponse, err, logout);
1060
1061 // cut down on overhead by not using formattools if we only want the text
1062 // (wanttext will equal 2 if we want text and other stuff too)
1063 if (wanttext == 1)
[3322]1064 if (highlight) {
1065 highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout);
1066 } else {
[443]1067 textout << outconvert << disp << docresponse.doc;
[3322]1068 }
[443]1069 }
1070
1071 if (wanttext != 1) {
[4906]1072 text_tmap options;
1073 options["text"] = docresponse.doc;
[4936]1074
[4972]1075 if (formatinfo.AllowExtendedOptions) {
1076 load_extended_options(options, args, browsers, formatinfo,
1077 collectproto, disp, outconvert, logout);
[4936]1078 }
1079
[1443]1080 text_t doctext
[4906]1081 = get_formatted_string (collection, collectproto, docinfo, disp,
1082 formatlistptr, options, logout);
[443]1083
[3322]1084 if (highlight) {
1085 highlighttext(doctext, args, terminfo, disp, outconvert, textout);
1086 } else {
[443]1087 textout << outconvert << disp << doctext;
[3322]1088 }
[443]1089 }
1090 }
1091}
1092
1093
[284]1094void documentaction::output_document (const text_t &OID, cgiargsclass &args,
[4936]1095 recptproto *collectproto, browsermapclass *browsers,
1096 displayclass &disp, outconvertclass &outconvert,
1097 ostream &textout, ostream &logout) {
[284]1098 FilterResponse_t inforesponse;
1099 FilterResponse_t queryresponse;
[649]1100 text_tset metadata;
[443]1101 bool getParents = false;
[284]1102 bool highlight = false;
[443]1103 int wanttext = 0;
[284]1104 int arg_gt = args.getintarg("gt");
1105 text_t &collection = args["c"];
[267]1106
[284]1107 // if we have a query string and highlighting is turned on we need
1108 // to redo the query to get the terms for highlighting
[4936]1109
[284]1110 if (!args["q"].empty() && args.getintarg("hl")) {
[6584]1111
1112 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
1113 bool segment = false;
1114 if (cinfo != NULL) {
1115 segment = cinfo->isSegmented;
1116 }
[284]1117 FilterRequest_t request;
[758]1118 comerror_t err;
[284]1119 request.filterResultOptions = FRmatchTerms;
[758]1120 text_t formattedstring = args["q"];
[6584]1121 format_querystring (formattedstring, args.getintarg("b"), segment);
[758]1122 set_queryfilter_options (request, formattedstring, args);
[8715]1123 args["q"] = formattedstring; // need to set this here for phrase
1124 // highlighting, where we look at the querystring
[758]1125 collectproto->filter (args["c"], request, queryresponse, err, logout);
1126 if (err != noError) {
1127 outconvertclass text_t2ascii;
1128 logout << text_t2ascii
1129 << "documentaction::output_document: call to QueryFilter failed "
1130 << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
1131 highlight = false;
1132 } else {
[284]1133 highlight = true;
[758]1134 }
[284]1135 }
1136
[443]1137 format_t *formatlistptr = new format_t();
1138 parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
[431]1139
[649]1140 metadata.insert ("hastxt");
1141 metadata.insert ("haschildren");
[2422]1142
[443]1143 if (formatinfo.DocumentText == "[Text]")
1144 wanttext = 1;
1145 else {
1146 char *docformat = formatinfo.DocumentText.getcstr();
1147 if (strstr (docformat, "[Text]") != NULL)
1148 wanttext = 2;
[9633]1149 delete []docformat;
[443]1150 }
[267]1151
[7432]1152 if (get_info (OID, collection, args["l"], metadata, getParents, collectproto, inforesponse, logout)) {
[649]1153 int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
1154 int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
[669]1155
[284]1156 if (arg_gt == 0) {
[443]1157 output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
1158 OID, highlight, hastxt, wanttext, collection, collectproto,
[4936]1159 browsers, disp, outconvert, textout, logout, args);
[443]1160
1161
[284]1162 } else {
[443]1163
1164 ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
[267]1165
[284]1166 // text is to be expanded
1167 text_t exOID = OID;
[649]1168 if (haschildren != 1) exOID = get_parent (OID);
[443]1169 if (exOID.empty()) exOID = OID;
[267]1170
[284]1171 // if we're not in a document (i.e. we're in a top level classification)
[649]1172 // we need to pass "is_classify = true" to get_contents so that it
[284]1173 // doesn't recurse all the way through each document in the classification
[649]1174 bool is_classify = false;
1175 if (args["d"].empty()) is_classify = true;
[284]1176
[7432]1177 get_contents (exOID, is_classify, metadata, collection, args["l"],
[443]1178 collectproto, inforesponse, logout);
[267]1179
[649]1180 ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
1181 ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
[1860]1182
[284]1183 if (arg_gt == 1) {
1184 // check if there are more than 10 sections containing text to be expanded -
1185 // if there are output warning message - this isn't a great way to do this
1186 // since the sections may be very large or very small - one day I'll fix it
1187 // -- Stefan.
1188 int seccount = 0;
1189 while (sechere != secend) {
[649]1190 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
[9620]1191 if (shastxt == 1) ++seccount;
[284]1192 if (seccount > 10) break;
[9620]1193 ++sechere;
[267]1194 }
[284]1195 if (seccount > 10) {
1196 // more than 10 sections so output warning message and text
1197 // for current section only
1198 textout << outconvert << disp << "_document:textltwarning_";
[443]1199
1200 output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
1201 OID, highlight, hastxt, wanttext, collection,
[4936]1202 collectproto, browsers, disp, outconvert, textout, logout, args);
[284]1203
1204 }
1205 else arg_gt = 2;
1206 }
[257]1207
[284]1208 if (arg_gt == 2) {
[267]1209 // get the text for each section
[284]1210 sechere = inforesponse.docInfo.begin();
1211 int count = 0;
1212 while (sechere != secend) {
[3087]1213 textout << outconvert << disp << "\n<p><a name=" << (*sechere).OID << "></a>\n";
[437]1214
[649]1215 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
[443]1216
1217 output_text (*sechere, formatlistptr, queryresponse.termInfo,
1218 (*sechere).OID, highlight, shastxt, wanttext, collection,
[4936]1219 collectproto, browsers, disp, outconvert, textout, logout, args);
[9620]1220 ++count;
1221 ++sechere;
[267]1222 }
1223 }
1224 }
[257]1225 }
[443]1226 delete formatlistptr;
[267]1227}
[4868]1228
1229void documentaction::set_arrow_macros (cgiargsclass &args, recptproto *collectproto,
1230 displayclass &disp, ostream &logout) {
1231
1232 text_tset metadata;
1233 FilterResponse_t response;
1234 FilterResponse_t presponse;
1235
1236 int haschildren = 0;
1237 text_tarray next_siblings;
1238 text_t previous_sibling;
1239 text_t &arg_d = args["d"];
1240
1241 // get info on current section
1242 metadata.insert("haschildren");
[7432]1243 if (!get_info(arg_d, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
[4868]1244 logout << "error 1 in documentaction::set_arrow_macros\n";
1245 return;
1246 }
1247 haschildren = response.docInfo[0].metadata["haschildren"].values[0].getint();
1248
1249 // get OIDs of next and previous siblings of current section and
1250 // all it's parents
1251 int parentcount = countchar(arg_d.begin(), arg_d.end(), '.');
1252 text_t thisoid = arg_d;
1253 while (parentcount > 0) {
[7432]1254 get_children (get_parent(thisoid), args["c"], args["l"], metadata, false,
[4868]1255 collectproto, response, logout);
1256 ResultDocInfo_tarray::iterator this_sibling = response.docInfo.begin();
1257 ResultDocInfo_tarray::iterator last_sibling = response.docInfo.end();
1258 bool first = true;
1259 while (this_sibling != last_sibling) {
1260 if ((*this_sibling).OID == thisoid) {
1261 if (!first && next_siblings.empty()) {
1262 previous_sibling = (*(this_sibling-1)).OID;
1263 int section_has_children = (*(this_sibling-1)).metadata["haschildren"].values[0].getint();
1264 // if previous sibling has children we need to recurse
1265 // down to the last descendant
1266 while (section_has_children) {
[7432]1267 get_children (previous_sibling, args["c"], args["l"], metadata, false,
[4868]1268 collectproto, presponse, logout);
1269 if (!presponse.docInfo.empty()) {
1270 ResultDocInfo_tarray::iterator it = presponse.docInfo.end() - 1;
1271 previous_sibling = (*it).OID;
1272 section_has_children = (*it).metadata["haschildren"].values[0].getint();
1273 } else {
1274 section_has_children = 0; // this should never happen
1275 }
1276 }
1277 }
1278
1279 if ((this_sibling+1) != last_sibling) {
1280 next_siblings.push_back((*(this_sibling+1)).OID);
1281 } else {
1282 next_siblings.push_back("");
1283 }
1284 break;
1285 }
[9620]1286 ++this_sibling;
[4868]1287 first = false;
1288 }
1289 thisoid = get_parent(thisoid);
[9620]1290 --parentcount;
[4868]1291 }
1292
1293 // work out values for next link
1294 if (haschildren) {
[10873]1295 disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
1296 "&amp;d=" + arg_d + ".fc");
[4868]1297 } else {
1298 text_tarray::const_iterator h = next_siblings.begin();
1299 text_tarray::const_iterator e = next_siblings.end();
1300 while (h != e) {
1301 if (!(*h).empty()) {
[10873]1302 disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
1303 "&amp;d=" + *h);
[4868]1304 break;
1305 }
[9620]1306 ++h;
[4868]1307 }
1308 }
1309
1310 // work out value for previous link
1311 if (!previous_sibling.empty()) {
[10873]1312 disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
1313 "&amp;d=" + previous_sibling);
[4868]1314 } else {
1315 if (countchar(arg_d.begin(), arg_d.end(), '.')) {
[10873]1316 disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
1317 "&amp;d=" + get_parent(arg_d));
[4868]1318 }
1319 }
1320}
Note: See TracBrowser for help on using the repository browser.