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

Last change on this file since 671 was 669, checked in by sjboddie, 25 years ago

finished changes to browsing support

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 29.6 KB
Line 
1/**********************************************************************
2 *
3 * documentaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * $Id: documentaction.cpp 669 1999-10-14 23:00:53Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.27 1999/10/14 23:00:53 sjboddie
31 finished changes to browsing support
32
33 Revision 1.26 1999/10/10 08:14:06 sjboddie
34 - metadata now returns mp rather than array
35 - redesigned browsing support (although it's not finished so
36 won't currently work ;-)
37
38 Revision 1.25 1999/09/17 04:46:05 sjboddie
39 fixed a couple of problems with 'unknown' classifier
40
41 Revision 1.24 1999/09/17 04:00:26 sjboddie
42 tidied up navigation bar to produce a default "unknown" button if
43 it comes across metadata it can't display
44
45 Revision 1.23 1999/09/07 04:56:54 sjboddie
46 added GPL notice
47
48 Revision 1.22 1999/08/20 01:00:22 sjboddie
49 split some of the larger functions up to simplify the creation of
50 collection specific receptionists
51
52 Revision 1.21 1999/08/11 23:28:03 sjboddie
53 -added support for html classifier
54 - removed _random_ macro - now use _blank for detach page
55
56 Revision 1.20 1999/08/10 23:16:39 sjboddie
57 a couple of small changes to get format options DocumentArrowsBottom
58 and DocumentArrowsTop working correctly
59
60 Revision 1.19 1999/08/10 22:40:01 sjboddie
61 added some more format options including the ability to format the
62 document text
63
64 Revision 1.18 1999/08/09 04:25:18 sjboddie
65 moved OID translation stuff from documentaction::define_external_macros
66 to receptionist
67
68 Revision 1.17 1999/08/09 02:13:53 sjboddie
69 fixed small bug in ShowSectionTitles
70
71 Revision 1.16 1999/08/03 03:30:47 sjboddie
72 a few small changes related to new format options
73
74 Revision 1.15 1999/07/30 02:18:49 sjboddie
75 -added collectinfo argument to some functions
76 -caught up with changes to browsetools (allowing nested classifications)
77 -added showtoppage format option
78
79 Revision 1.14 1999/07/21 05:01:09 sjboddie
80 fixed up wrapping of classificationlinks
81
82 Revision 1.13 1999/07/20 02:59:54 sjboddie
83 List and AZList classifications now use format strings
84
85 Revision 1.12 1999/07/16 00:19:01 sjboddie
86 some changes to the way quoted queries are handled
87
88 Revision 1.11 1999/07/07 05:47:41 sjboddie
89 changed around the way browsetools works
90
91 Revision 1.10 1999/06/29 01:46:44 sjboddie
92 now sets a _navigationbar_ macro even if there aren't any
93 classifications (it will just have the 'search' button
94
95 Revision 1.9 1999/06/27 22:05:58 sjboddie
96 now set a _thisOID_ macro for use in displaying images
97
98 Revision 1.8 1999/06/24 05:12:20 sjboddie
99 lots of small changes
100
101 Revision 1.7 1999/06/17 03:06:58 sjboddie
102 got detach button working properly - the close book icon is now disabled
103 when page is detached as the javascript close() function I was using is
104 too unreliable over different browsers
105 note that in my last comment I meant the "cl" arg (not the "c" arg).
106
107 Revision 1.6 1999/06/16 23:53:15 sjboddie
108 tidied a few things up. documentaction::define_external_macros now
109 resets the "c" arg if it's set to something stupid by the .xx suffixes
110
111 Revision 1.5 1999/06/16 03:10:49 sjboddie
112 define_internal_macros() now sets _pagetitle_ macro to document's title
113 (including parents of current document)
114
115 Revision 1.4 1999/06/15 01:55:29 sjboddie
116 - got text highlighting working
117 - got multiple collections working (now outputs error message if an
118 attempt is made to get a document when the "c" arg isn't set.
119
120 Revision 1.3 1999/06/08 04:29:37 sjboddie
121 added argsinfo to the call to check_cgiargs to make it easy to set
122 args to their default if they're found to be screwed up
123
124 Revision 1.2 1999/05/10 03:40:35 sjboddie
125 lots of changes - slowly getting document action sorted out
126
127 Revision 1.1 1999/04/30 01:59:40 sjboddie
128 lots of stuff - getting documentaction working (documentaction replaces
129 old browseaction)
130
131 Revision 1.2 1999/03/29 02:14:27 sjboddie
132
133 More changes to browseaction
134
135 Revision 1.1 1999/03/25 03:09:40 sjboddie
136
137 subjectbrowseaction became browseaction
138
139
140 */
141
142
143#include <string.h>
144#include "documentaction.h"
145#include "browsetools.h"
146#include "OIDtools.h"
147#include "querytools.h"
148#include "unitool.h"
149
150documentaction::documentaction () {
151
152 // this action uses cgi variables "a", "d", "cl",
153 // "x", "gc", "gt", "gp", and "hl"
154 cgiarginfo arg_ainfo;
155 arg_ainfo.shortname = "a";
156 arg_ainfo.longname = "action";
157 arg_ainfo.multiplechar = true;
158 arg_ainfo.defaultstatus = cgiarginfo::weak;
159 arg_ainfo.argdefault = "p";
160 arg_ainfo.savedarginfo = cgiarginfo::must;
161 argsinfo.addarginfo (NULL, arg_ainfo);
162
163 arg_ainfo.shortname = "d";
164 arg_ainfo.longname = "document OID";
165 arg_ainfo.multiplechar = true;
166 arg_ainfo.defaultstatus = cgiarginfo::none;
167 arg_ainfo.argdefault = "";
168 arg_ainfo.savedarginfo = cgiarginfo::can;
169 argsinfo.addarginfo (NULL, arg_ainfo);
170
171 arg_ainfo.shortname = "cl";
172 arg_ainfo.longname = "classification OID";
173 arg_ainfo.multiplechar = true;
174 arg_ainfo.defaultstatus = cgiarginfo::none;
175 arg_ainfo.argdefault = "";
176 arg_ainfo.savedarginfo = cgiarginfo::can;
177 argsinfo.addarginfo (NULL, arg_ainfo);
178
179 // in this action "gc" controls the expand/contract
180 // contents function
181 arg_ainfo.shortname = "gc";
182 arg_ainfo.longname = "expand contents";
183 arg_ainfo.multiplechar = false;
184 arg_ainfo.defaultstatus = cgiarginfo::weak;
185 arg_ainfo.argdefault = "0";
186 arg_ainfo.savedarginfo = cgiarginfo::can;
187 argsinfo.addarginfo (NULL, arg_ainfo);
188
189 // in this action "gt" controls the expand/contract
190 // text function 0 = not expanded, 1 = expand unless
191 // there are more than 10 sections containing text,
192 // 2 = expand all
193 arg_ainfo.shortname = "gt";
194 arg_ainfo.longname = "expand text";
195 arg_ainfo.multiplechar = false;
196 arg_ainfo.defaultstatus = cgiarginfo::weak;
197 arg_ainfo.argdefault = "0";
198 arg_ainfo.savedarginfo = cgiarginfo::can;
199 argsinfo.addarginfo (NULL, arg_ainfo);
200
201 // in this action "gp" is the "go to page" control
202 // used by the Book type of toc
203 arg_ainfo.shortname = "gp";
204 arg_ainfo.longname = "go to page";
205 arg_ainfo.multiplechar = true;
206 arg_ainfo.defaultstatus = cgiarginfo::none;
207 arg_ainfo.argdefault = "";
208 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
209 argsinfo.addarginfo (NULL, arg_ainfo);
210
211 // in this action "hl" is the "highlighting on/
212 // highlighting off control
213 arg_ainfo.shortname = "hl";
214 arg_ainfo.longname = "highlighting on/off";
215 arg_ainfo.multiplechar = false;
216 arg_ainfo.defaultstatus = cgiarginfo::weak;
217 arg_ainfo.argdefault = "1";
218 arg_ainfo.savedarginfo = cgiarginfo::must;
219 argsinfo.addarginfo (NULL, arg_ainfo);
220
221 // "x" is 0 normally or 1 if page
222 // has been "detached"
223 arg_ainfo.shortname = "x";
224 arg_ainfo.longname = "detached page";
225 arg_ainfo.multiplechar = false;
226 arg_ainfo.defaultstatus = cgiarginfo::weak;
227 arg_ainfo.argdefault = "0";
228 arg_ainfo.savedarginfo = cgiarginfo::must;
229 argsinfo.addarginfo (NULL, arg_ainfo);
230}
231
232documentaction::~documentaction () {
233}
234
235bool documentaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
236 ostream &logout) {
237
238 // check gc argument
239 int arg_gc = args.getintarg("gc");
240 if (arg_gc != 0 && arg_gc != 1) {
241 logout << "Warning: \"gc\" argument out of range (" << arg_gc << ")\n";
242 cgiarginfo *gcinfo = argsinfo.getarginfo ("gc");
243 if (gcinfo != NULL) args["gc"] = gcinfo->argdefault;
244 }
245
246 // check gt argument (may be either 0, 1 or 2)
247 int arg_gt = args.getintarg("gt");
248 if (arg_gt != 0 && arg_gt != 1 && arg_gt != 2) {
249 logout << "Warning: \"gt\" argument out of range (" << arg_gt << ")\n";
250 cgiarginfo *gtinfo = argsinfo.getarginfo ("gt");
251 if (gtinfo != NULL) args["gt"] = gtinfo->argdefault;
252 }
253
254 // check hl argument
255 int arg_hl = args.getintarg("hl");
256 if (arg_hl != 0 && arg_hl != 1) {
257 logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n";
258 cgiarginfo *hlinfo = argsinfo.getarginfo ("hl");
259 if (hlinfo != NULL) args["hl"] = hlinfo->argdefault;
260 }
261
262 // check x argument
263 int arg_x = args.getintarg("x");
264 if (arg_x != 0 && arg_x != 1) {
265 logout << "Warning: \"x\" argument out of range (" << arg_x << ")\n";
266 cgiarginfo *xinfo = argsinfo.getarginfo ("x");
267 if (xinfo != NULL) args["x"] = xinfo->argdefault;
268 }
269
270 return true;
271}
272
273void documentaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
274 text_t &response_data, ostream &/*logout*/) {
275 response = content;
276 response_data = "text/html";
277}
278
279// set_widthtspace calculates how wide the spaces in the nav bar should
280// be and sets the appropriate macro
281void documentaction::set_spacemacro (displayclass &disp, FilterResponse_t &response) {
282
283 text_t width;
284 int twidth, swidth, iwidth = 0;
285
286 int numc = response.docInfo.size();
287 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
288 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
289
290 disp.expandstring ("Global", "_pagewidth_", width);
291 twidth = width.getint();
292
293 disp.expandstring ("query", "_searchwidth_", width);
294 iwidth += width.getint();
295
296 while (dochere != docend) {
297 const text_t &title = (*dochere).metadata["Title"].values[0];
298
299 disp.expandstring ("document", "_" + title + "width_", width);
300 if (width == ("_" + title + "width_"))
301 disp.expandstring ("document", "_defaultwidth_", width);
302 iwidth += width.getint();
303 dochere ++;
304 }
305 if ((twidth - iwidth) < numc) swidth = 2;
306 else {
307 swidth = twidth - iwidth;
308 if (numc > 0) swidth = swidth / numc;
309 }
310 disp.setmacro ("widthtspace", "Global", swidth);
311}
312
313// set_navbarmacros sets _navigationbar_, _javaimagesnavbar_ and _httpbrowseXXX_ macros
314// reponse contains 1 metadata field (Title)
315void documentaction::set_navbarmacros (displayclass &disp, FilterResponse_t &response,
316 cgiargsclass &args) {
317
318 text_t javaimagesnavbar, topparent;
319 text_t &arg_d = args["d"];
320 text_t navigationbar = "<!-- Navigation Bar -->\n";
321
322 get_top (args["cl"], topparent);
323 int numc = response.docInfo.size();
324 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
325 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
326
327 navigationbar += "<nobr>\n";
328 if (args["a"] == "q") {
329 navigationbar += "_icontabsearchgreen_";
330 } else {
331 navigationbar += "_imagesearch_";
332 javaimagesnavbar = "_javasearch_";
333 }
334 if (numc == 0) navigationbar += "_imagespacer_";
335
336 while (dochere != docend) {
337 text_t title = (*dochere).metadata["Title"].values[0];
338
339 bool unknown = false;
340
341 // test the _XXXwidth_ macro to see if image macros are
342 // defined for this type of classification - if not we'll
343 // just display the text
344 text_t tmpwidth;
345 disp.expandstring ("document", "_" + title + "width_", tmpwidth);
346 if (tmpwidth == ("_" + title + "width_")) unknown = true;
347
348 // if we're inside a document all the classification buttons should be enabled
349 if (arg_d.empty() && ((*dochere).OID == topparent)) {
350 if (unknown) navigationbar += "_imagespacer_&nbsp;" + title + "&nbsp;";
351 else navigationbar += "_imagespacer__icontab" + title + "green_";
352 } else {
353
354 // set the _httpbrowseXXX_ macro for this classification
355 if (unknown) navigationbar += "_imagespacer_&nbsp;<a href=\"_httpdocument_&cl=" +
356 (*dochere).OID + "\">" + title + "</a>&nbsp;";
357 else {
358 navigationbar += "_imagespacer__image" + title + "_";
359 disp.setmacro ("httpbrowse" + title, "Global", "_httpdocument_&cl=" + (*dochere).OID);
360 }
361 }
362 if (!unknown) javaimagesnavbar += "_java" + title + "_";
363 dochere ++;
364 }
365 navigationbar += "\n</nobr>\n";
366 navigationbar += "<!-- End of Navigation Bar -->\n";
367 disp.setmacro ("navigationbar", "Global", navigationbar);
368 if (args.getintarg("v") == 0)
369 disp.setmacro ("javaimagesnavbar", "Global", javaimagesnavbar);
370}
371
372// define all the macros which might be used by other actions
373// to produce pages.
374void documentaction::define_external_macros (const ColInfoResponse_t &/*collectinfo*/,
375 displayclass &disp, cgiargsclass &args,
376 recptproto *collectproto, ostream &logout) {
377
378 // define_external_macros sets the following macros:
379
380 // _navigationbar_ this is the navigation bar containing the search button
381 // and any classification buttons - it goes at the top of
382 // most pages. for now we're assuming that there'll always
383 // be a search button - we should probably check that there
384 // is a query action before making this assumption
385
386 // _httpbrowseXXX_ the http macros for each classification (i.e. if there
387 // are Title and Creator classifications _httpbrowseTitle_
388 // and _httpbrowseCreator_ will be set
389
390 // _javaimagesnavbar_ this is the javascript code to shove in to make the
391 // flashy images used by _navigationbar_ work
392
393 // _widthtspace_ the width of the spacers between buttons in navigation
394 // bar
395
396
397 // can't do anything if collectproto is null (i.e. no collection was specified)
398 if (collectproto == NULL) return;
399
400 outconvertclass text_t2ascii;
401 comerror_t err;
402 InfoFiltersResponse_t filterinfo;
403 FilterResponse_t response;
404 text_tset metadata;
405 text_t &collection = args["c"];
406
407 // don't want navigation bar if page is 'detached'
408 if (!args.getintarg("x")) {
409
410 collectproto->get_filterinfo (collection, filterinfo, err, logout);
411 if (err == noError) {
412 // check that there's a browse filter
413 if (filterinfo.filterNames.find ("BrowseFilter") != filterinfo.filterNames.end()) {
414
415 metadata.insert ("Title");
416 bool getParents = false;
417 get_children ("", collection, metadata, getParents, collectproto, response, logout);
418
419 // calculate width of spacers and set _widthtspace_ macro
420 if (args.getintarg("v") == 0) set_spacemacro (disp, response);
421
422 // set _navigationbar_ and _javaimagesnavbar_ macros
423 set_navbarmacros (disp, response, args);
424 }
425 } else {
426 logout << text_t2ascii
427 << "Error (documentaction::define_external_macros()) in call to get_filterinfo() "
428 << get_comerror_string (err);
429 }
430 }
431}
432
433void documentaction::load_formatinfo (const text_tmap &colformat, int gt) {
434
435 formatinfo.clear();
436 text_tmap::const_iterator format_here = colformat.begin();
437 text_tmap::const_iterator format_end = colformat.end();
438
439 while (format_here != format_end) {
440 if (((*format_here).first == "DocumentImages") &&
441 ((*format_here).second == "true"))
442 formatinfo.DocumentImages = true;
443 else if (((*format_here).first == "DocumentTitles") &&
444 ((*format_here).second == "false"))
445 formatinfo.DocumentTitles = false;
446 else if ((*format_here).first == "DocumentHeading")
447 formatinfo.DocumentHeading = (*format_here).second;
448 else if (((*format_here).first == "DocumentContents") &&
449 ((*format_here).second == "false"))
450 formatinfo.DocumentContents = false;
451 else if (((*format_here).first == "DocumentArrowsBottom") &&
452 ((*format_here).second == "false"))
453 formatinfo.DocumentArrowsBottom = false;
454 else if ((*format_here).first == "DocumentButtons")
455 splitchar ((*format_here).second.begin(), (*format_here).second.end(),
456 '|', formatinfo.DocumentButtons);
457 else if ((*format_here).first == "DocumentText")
458 formatinfo.DocumentText = (*format_here).second;
459 else
460 formatinfo.formatstrings[(*format_here).first] = (*format_here).second;
461
462 format_here ++;
463 }
464
465 // never want arrows when text is expanded
466 if (gt)
467 formatinfo.DocumentArrowsBottom = false;
468}
469
470void documentaction::set_java_macros (cgiargsclass &args, displayclass &disp) {
471
472 text_t javaimagescontent = "_javaextras_";
473
474 int arg_gt = args.getintarg("gt");
475 int arg_gc = args.getintarg("gc");
476 int arg_hl = args.getintarg("hl");
477
478 text_tarray::const_iterator button_here = formatinfo.DocumentButtons.begin();
479 text_tarray::const_iterator button_end = formatinfo.DocumentButtons.end();
480
481 while (button_here != button_end) {
482 if (*button_here == "Detach")
483 javaimagescontent += "_javadetach_";
484 else if (*button_here == "Expand Text") {
485 if (arg_gt == 1)
486 javaimagescontent += "_javacontracttext__javacontinue_";
487 else if (arg_gt == 2)
488 javaimagescontent += "_javacontracttext_";
489 else
490 javaimagescontent += "_javaexpandtext_";
491 } else if (*button_here == "Expand Contents") {
492 if (arg_gc == 1)
493 javaimagescontent += "_javacontractcontents_";
494 else
495 javaimagescontent += "_javaexpandcontents_";
496 } else if (*button_here == "Highlight") {
497 if (arg_hl == 1)
498 javaimagescontent += "_javanohighlighting_";
499 else
500 javaimagescontent += "_javahighlighting_";
501 }
502 button_here ++;
503 }
504 disp.setmacro ("javaimagescontent", "document", javaimagescontent);
505}
506
507
508// define all the macros which are related to pages generated
509// by this action. we also load up the formatinfo structure
510// here (it's used in do_action as well as here)
511void documentaction::define_internal_macros (const ColInfoResponse_t &collectinfo,
512 displayclass &disp, cgiargsclass &args,
513 recptproto *collectproto, ostream &logout) {
514
515 // define_internal_macros sets the following macros:
516
517 // _pagetitle_ the title to be displayed at the top of the browser window
518
519 // _imagethispage_ the title image to be displayed at top right of page
520
521 // _navarrows_ this may be overridden to "" when format option
522 // DocumentArrowsBottom is false
523
524 // _header_ the header macro is overridden if we're not at a top level
525 // classification to remove the title block
526
527 // _javaimagescontent_ this is the javascript code to shove in to make the
528 // flashy buttons work
529
530 // _thisOID_ the OID (directory) of the current document - this corresponds
531 // to the archivedir metadata element
532
533 // can't do anything if collectproto is null (i.e. no collection was specified)
534 if (collectproto == NULL) return;
535
536 text_tset metadata;
537 FilterResponse_t response;
538 text_t &arg_d = args["d"];
539 text_t &arg_cl = args["cl"];
540 text_t &collection = args["c"];
541 int gt = args.getintarg("gt");
542 load_formatinfo (collectinfo.format, gt);
543
544 if (!formatinfo.DocumentArrowsBottom)
545 disp.setmacro("navarrows", "document", "");
546
547 metadata.insert ("Title");
548
549 if (!arg_d.empty()) {
550 // we're at document level
551
552 metadata.insert ("archivedir");
553
554 // get metadata for this document and it's parents
555 if (get_info (arg_d, collection, metadata, true, collectproto, response, logout)) {
556 disp.setmacro ("header", "document", "_textheader_");
557
558 text_tarray pagetitlearray;
559 if (!response.docInfo[0].metadata["Title"].values[0].empty())
560 pagetitlearray.push_back (response.docInfo[0].metadata["Title"].values[0]);
561 if (!gt) {
562 MetadataInfo_t *parenttitle = response.docInfo[0].metadata["Title"].parent;
563 while (parenttitle != NULL) {
564 if (!parenttitle->values[0].empty())
565 pagetitlearray.push_back (parenttitle->values[0]);
566 parenttitle = parenttitle->parent;
567 }
568 }
569 reverse (pagetitlearray.begin(), pagetitlearray.end());
570 text_t pagetitle;
571 joinchar (pagetitlearray, ": ", pagetitle);
572 disp.setmacro ("pagetitle", "document", pagetitle);
573
574 if (is_top (arg_d))
575 disp.setmacro ("thisOID", "Global", response.docInfo[0].metadata["archivedir"].values[0]);
576 else {
577 MetadataInfo_t *parentad = response.docInfo[0].metadata["archivedir"].parent;
578 text_t thisOID;
579 while (parentad != NULL) {
580 thisOID = parentad->values[0];
581 parentad = parentad->parent;
582 }
583 disp.setmacro ("thisOID", "Global", thisOID);
584 }
585
586 if (args["u"] != "1")
587 set_java_macros (args, disp);
588
589 }
590 } else {
591 if (!arg_cl.empty()) {
592
593 // get metadata for top level classification
594 text_t classtop;
595 get_top (arg_cl, classtop);
596 if (get_info (classtop, collection, metadata, false, collectproto, response, logout)) {
597
598 text_t &title = response.docInfo[0].metadata["Title"].values[0];
599 bool unknown = false;
600
601 // test the _XXXwidth_ macro to see if image macros are
602 // defined for this type of classification - if not we'll
603 // just display the text
604 text_t tmp;
605 disp.expandstring ("document", "_" + title + "width_", tmp);
606 if (tmp == ("_" + title + "width_")) unknown = true;
607
608 if (unknown) {
609 disp.setmacro ("pagetitle", "document", title);
610 disp.setmacro ("imagethispage", "document", "<h2>" + title + "</h2>");
611 } else {
612 disp.setmacro ("pagetitle", "document", "_text" + title + "page_");
613 disp.setmacro ("imagethispage", "document", "_icon" + title + "page_");
614 }
615 }
616 }
617 }
618}
619
620
621bool documentaction::do_action (cgiargsclass &args, const ColInfoResponse_t &/*collectinfo*/,
622 recptproto *collectproto, displayclass &disp,
623 outconvertclass &outconvert, ostream &textout,
624 ostream &logout) {
625
626 if (collectproto == NULL) {
627 logout << "documentaction::do_action called with NULL collectproto\n";
628 textout << outconvert << disp << "_document:header_\n"
629 << "Error: Attempt to get document without setting collection\n"
630 << "_document:footer_\n";
631 } else {
632
633 text_t OID = args["d"];
634 if (OID.empty()) OID = args["cl"];
635 if (OID.empty()) {
636 textout << outconvert << disp << "Document contains no data_document:footer_\n";
637 return true;
638 }
639
640 textout << outconvert << disp << "_document:header_\n"
641 << "_document:content_\n";
642
643 // output the table of contents
644 output_toc (args, recpt->get_browsermap_ptr(), formatinfo,
645 collectproto, disp, outconvert, textout, logout);
646
647 // output the document text
648 textout << "<p>\n";
649 output_document (OID, args, collectproto, disp, outconvert, textout, logout);
650
651 textout << outconvert << disp << "_document:footer_\n";
652 }
653 return true;
654}
655
656void documentaction::output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
657 const TermInfo_tarray &terminfo, const text_t &OID,
658 bool highlight, int hastxt, int wanttext,
659 text_t &collection, recptproto *collectproto,
660 displayclass &disp, outconvertclass &outconvert,
661 ostream &textout, ostream &logout) {
662
663 DocumentRequest_t docrequest;
664 DocumentResponse_t docresponse;
665 comerror_t err;
666
667 if (hastxt == 1) {
668
669 if (wanttext) {
670 // get the text
671 docrequest.OID = OID;
672 collectproto->get_document (collection, docrequest, docresponse, err, logout);
673
674 // cut down on overhead by not using formattools if we only want the text
675 // (wanttext will equal 2 if we want text and other stuff too)
676 if (wanttext == 1)
677 if (highlight)
678 highlighttext(docresponse.doc, terminfo, disp, outconvert, textout, logout);
679 else
680 textout << outconvert << disp << docresponse.doc;
681 }
682
683 if (wanttext != 1) {
684 text_t doctext = get_formatted_string (docinfo, formatlistptr, docresponse.doc);
685
686 if (highlight)
687 highlighttext(doctext, terminfo, disp, outconvert, textout, logout);
688 else
689 textout << outconvert << disp << doctext;
690 }
691 }
692}
693
694
695void documentaction::output_document (const text_t &OID, cgiargsclass &args,
696 recptproto *collectproto, displayclass &disp,
697 outconvertclass &outconvert, ostream &textout,
698 ostream &logout) {
699 FilterResponse_t inforesponse;
700 FilterResponse_t queryresponse;
701 text_tset metadata;
702 bool getParents = false;
703 bool highlight = false;
704 int wanttext = 0;
705 int arg_gt = args.getintarg("gt");
706 text_t &collection = args["c"];
707
708 // if we have a query string and highlighting is turned on we need
709 // to redo the query to get the terms for highlighting
710 if (!args["q"].empty() && args.getintarg("hl")) {
711 FilterRequest_t request;
712 request.filterResultOptions = FRmatchTerms;
713 if (do_query (request, args, collectproto, queryresponse, logout))
714 highlight = true;
715 }
716
717 format_t *formatlistptr = new format_t();
718 parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
719
720 metadata.insert ("hastxt");
721 metadata.insert ("haschildren");
722
723 if (formatinfo.DocumentText == "[Text]")
724 wanttext = 1;
725 else {
726 char *docformat = formatinfo.DocumentText.getcstr();
727 if (strstr (docformat, "[Text]") != NULL)
728 wanttext = 2;
729 delete docformat;
730 }
731
732 if (get_info (OID, collection, metadata, getParents, collectproto, inforesponse, logout)) {
733 int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
734 int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
735
736 if (arg_gt == 0) {
737 output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
738 OID, highlight, hastxt, wanttext, collection, collectproto,
739 disp, outconvert, textout, logout);
740
741
742 } else {
743
744 ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
745
746 // text is to be expanded
747 text_t exOID = OID;
748 if (haschildren != 1) exOID = get_parent (OID);
749 if (exOID.empty()) exOID = OID;
750
751 // if we're not in a document (i.e. we're in a top level classification)
752 // we need to pass "is_classify = true" to get_contents so that it
753 // doesn't recurse all the way through each document in the classification
754 bool is_classify = false;
755 if (args["d"].empty()) is_classify = true;
756
757 get_contents (exOID, is_classify, metadata, collection,
758 collectproto, inforesponse, logout);
759
760 ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
761 ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
762
763 if (arg_gt == 1) {
764 // check if there are more than 10 sections containing text to be expanded -
765 // if there are output warning message - this isn't a great way to do this
766 // since the sections may be very large or very small - one day I'll fix it
767 // -- Stefan.
768 int seccount = 0;
769 while (sechere != secend) {
770 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
771 if (shastxt == 1) seccount ++;
772 if (seccount > 10) break;
773 sechere ++;
774 }
775 if (seccount > 10) {
776 // more than 10 sections so output warning message and text
777 // for current section only
778 textout << outconvert << disp << "_document:textltwarning_";
779
780 output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
781 OID, highlight, hastxt, wanttext, collection,
782 collectproto, disp, outconvert, textout, logout);
783
784 }
785 else arg_gt = 2;
786 }
787
788 if (arg_gt == 2) {
789 // get the text for each section
790 sechere = inforesponse.docInfo.begin();
791 int count = 0;
792 while (sechere != secend) {
793 textout << outconvert << disp << "\n<p><a name=" << count << "></a>\n";
794
795 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
796
797 output_text (*sechere, formatlistptr, queryresponse.termInfo,
798 (*sechere).OID, highlight, shastxt, wanttext, collection,
799 collectproto, disp, outconvert, textout, logout);
800 count ++;
801 sechere ++;
802 }
803 }
804 }
805 }
806 delete formatlistptr;
807}
808
809// highlighttext highlights query terms in text string and outputs the resulting text string
810void documentaction::highlighttext(text_t &text, const TermInfo_tarray &terms,
811 displayclass &disp, outconvertclass &outconvert,
812 ostream &textout, ostream &/*logout*/) {
813
814 text_tmap allterms;
815 text_tmap::const_iterator it;
816
817 // first load all the term variations into a map
818 TermInfo_tarray::const_iterator this_term = terms.begin();
819 TermInfo_tarray::const_iterator last_term = terms.end();
820 while (this_term != last_term) {
821 text_tarray::const_iterator this_var = (*this_term).matchTerms.begin();
822 text_tarray::const_iterator last_var = (*this_term).matchTerms.end();
823 while (this_var != last_var) {
824 allterms[*this_var] = 1;
825 this_var ++;
826 }
827 this_term ++;
828 }
829
830 // get the text to start and end a hightlight
831 text_t starthighlight = "<b><u>";
832 text_t endhighlight = "</u></b>";
833 if (disp.isdefaultmacro("Global", "starthighlight"))
834 disp.expandstring("Global", "_starthighlight_", starthighlight);
835 if (disp.isdefaultmacro("Global", "endhighlight"))
836 disp.expandstring("Global", "_endhighlight_", endhighlight);
837
838
839 text_t::iterator here = text.begin();
840 text_t::iterator end = text.end();
841 text_t word, buffer;
842 while (here != end) {
843 if (is_unicode_letdig(*here)) {
844 // not word boundary
845 word.push_back(*here);
846 here++;
847
848 } else {
849 // found word boundary
850 // add last word if there was one
851 if (!word.empty()) {
852 it = allterms.find(word);
853 if (it != allterms.end()) {
854 word = starthighlight + word + endhighlight;
855 }
856 buffer += word;
857 word.clear();
858 }
859
860 if (*here == '<') {
861 // skip over rest of html tag
862 while ((here != end) && (*here != '>')) {
863 buffer.push_back(*here);
864 here++;
865 }
866 }
867
868 buffer.push_back(*here);
869 here++;
870
871 if (buffer.size() > 1024) {
872 textout << outconvert << disp << buffer;
873 buffer.clear();
874 }
875 }
876 }
877 textout << outconvert << disp << buffer;
878}
Note: See TracBrowser for help on using the repository browser.