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

Last change on this file since 21743 was 21743, checked in by kjdon, 14 years ago

should be using assocfilepath instead of archivedir

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