source: branches/corba/gsdl/src/recpt/documentaction.cpp@ 1074

Last change on this file since 1074 was 1067, checked in by cs025, 24 years ago

Corba first commit

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 42.1 KB
Line 
1/**********************************************************************
2 *
3 * documentaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * $Id: documentaction.cpp 1067 2000-04-04 15:02:39Z cs025 $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.36.2.1 2000/04/04 15:02:35 cs025
31 Corba first commit
32
33 Revision 1.36 2000/04/03 07:26:28 sjboddie
34 replaced old DocumentIcon and DocumentContents format options
35 with DocumentColumn stuff
36
37 Revision 1.35 2000/03/31 03:04:31 nzdl
38 tidied up some of the browsing code - replaced DocumentImages,
39 DocumentTitles and DocumentHeading with DocumentIcon
40
41 Revision 1.34 2000/02/15 22:53:49 kjm18
42 search history stuff added.
43
44 Revision 1.33 2000/02/13 20:40:05 sjboddie
45 now dm_safe _thisOID_ macro
46
47 Revision 1.32 2000/01/25 22:39:15 sjboddie
48 added DocumentUseHTML - tidied some things up (and messed up some others)
49
50 Revision 1.31 1999/11/13 08:57:00 sjboddie
51 fixed bug in last changes
52
53 Revision 1.30 1999/11/01 21:54:27 sjboddie
54 changes for cross-collection searching - changes to arguments
55 of many functions
56
57 Revision 1.29 1999/10/24 07:23:40 sjboddie
58 added FullTOC option
59
60 Revision 1.28 1999/10/19 03:23:42 davidb
61 Collection building support through web pages
62 and internal and external link handling for collection documents
63
64 Revision 1.27 1999/10/14 23:00:53 sjboddie
65 finished changes to browsing support
66
67 Revision 1.26 1999/10/10 08:14:06 sjboddie
68 - metadata now returns mp rather than array
69 - redesigned browsing support (although it's not finished so
70 won't currently work ;-)
71
72 Revision 1.25 1999/09/17 04:46:05 sjboddie
73 fixed a couple of problems with 'unknown' classifier
74
75 Revision 1.24 1999/09/17 04:00:26 sjboddie
76 tidied up navigation bar to produce a default "unknown" button if
77 it comes across metadata it can't display
78
79 Revision 1.23 1999/09/07 04:56:54 sjboddie
80 added GPL notice
81
82 Revision 1.22 1999/08/20 01:00:22 sjboddie
83 split some of the larger functions up to simplify the creation of
84 collection specific receptionists
85
86 Revision 1.21 1999/08/11 23:28:03 sjboddie
87 -added support for html classifier
88 - removed _random_ macro - now use _blank for detach page
89
90 Revision 1.20 1999/08/10 23:16:39 sjboddie
91 a couple of small changes to get format options DocumentArrowsBottom
92 and DocumentArrowsTop working correctly
93
94 Revision 1.19 1999/08/10 22:40:01 sjboddie
95 added some more format options including the ability to format the
96 document text
97
98 Revision 1.18 1999/08/09 04:25:18 sjboddie
99 moved OID translation stuff from documentaction::define_external_macros
100 to receptionist
101
102 Revision 1.17 1999/08/09 02:13:53 sjboddie
103 fixed small bug in ShowSectionTitles
104
105 Revision 1.16 1999/08/03 03:30:47 sjboddie
106 a few small changes related to new format options
107
108 Revision 1.15 1999/07/30 02:18:49 sjboddie
109 -added collectinfo argument to some functions
110 -caught up with changes to browsetools (allowing nested classifications)
111 -added showtoppage format option
112
113 Revision 1.14 1999/07/21 05:01:09 sjboddie
114 fixed up wrapping of classificationlinks
115
116 Revision 1.13 1999/07/20 02:59:54 sjboddie
117 List and AZList classifications now use format strings
118
119 Revision 1.12 1999/07/16 00:19:01 sjboddie
120 some changes to the way quoted queries are handled
121
122 Revision 1.11 1999/07/07 05:47:41 sjboddie
123 changed around the way browsetools works
124
125 Revision 1.10 1999/06/29 01:46:44 sjboddie
126 now sets a _navigationbar_ macro even if there aren't any
127 classifications (it will just have the 'search' button
128
129 Revision 1.9 1999/06/27 22:05:58 sjboddie
130 now set a _thisOID_ macro for use in displaying images
131
132 Revision 1.8 1999/06/24 05:12:20 sjboddie
133 lots of small changes
134
135 Revision 1.7 1999/06/17 03:06:58 sjboddie
136 got detach button working properly - the close book icon is now disabled
137 when page is detached as the javascript close() function I was using is
138 too unreliable over different browsers
139 note that in my last comment I meant the "cl" arg (not the "c" arg).
140
141 Revision 1.6 1999/06/16 23:53:15 sjboddie
142 tidied a few things up. documentaction::define_external_macros now
143 resets the "c" arg if it's set to something stupid by the .xx suffixes
144
145 Revision 1.5 1999/06/16 03:10:49 sjboddie
146 define_internal_macros() now sets _pagetitle_ macro to document's title
147 (including parents of current document)
148
149 Revision 1.4 1999/06/15 01:55:29 sjboddie
150 - got text highlighting working
151 - got multiple collections working (now outputs error message if an
152 attempt is made to get a document when the "c" arg isn't set.
153
154 Revision 1.3 1999/06/08 04:29:37 sjboddie
155 added argsinfo to the call to check_cgiargs to make it easy to set
156 args to their default if they're found to be screwed up
157
158 Revision 1.2 1999/05/10 03:40:35 sjboddie
159 lots of changes - slowly getting document action sorted out
160
161 Revision 1.1 1999/04/30 01:59:40 sjboddie
162 lots of stuff - getting documentaction working (documentaction replaces
163 old browseaction)
164
165 Revision 1.2 1999/03/29 02:14:27 sjboddie
166
167 More changes to browseaction
168
169 Revision 1.1 1999/03/25 03:09:40 sjboddie
170
171 subjectbrowseaction became browseaction
172
173
174 */
175
176
177#include <string.h>
178#include "documentaction.h"
179#include "browsetools.h"
180#include "OIDtools.h"
181#include "querytools.h"
182#include "unitool.h"
183#include "htmlutils.h"
184
185documentaction::documentaction () {
186
187 // this action uses cgi variables "a", "d", "cl",
188 // "x", "gc", "gt", "gp", and "hl"
189 cgiarginfo arg_ainfo;
190 arg_ainfo.shortname = "a";
191 arg_ainfo.longname = "action";
192 arg_ainfo.multiplechar = true;
193 arg_ainfo.defaultstatus = cgiarginfo::weak;
194 arg_ainfo.argdefault = "p";
195 arg_ainfo.savedarginfo = cgiarginfo::must;
196 argsinfo.addarginfo (NULL, arg_ainfo);
197
198 arg_ainfo.shortname = "d";
199 arg_ainfo.longname = "document OID";
200 arg_ainfo.multiplechar = true;
201 arg_ainfo.defaultstatus = cgiarginfo::none;
202 arg_ainfo.argdefault = "";
203 arg_ainfo.savedarginfo = cgiarginfo::can;
204 argsinfo.addarginfo (NULL, arg_ainfo);
205
206 // whether or not a document should be retrieved from the
207 // library or the Web.
208 arg_ainfo.shortname = "il";
209 arg_ainfo.longname = "internal link preference";
210 arg_ainfo.multiplechar = false;
211 arg_ainfo.defaultstatus = cgiarginfo::weak;
212 arg_ainfo.argdefault = "l";
213 arg_ainfo.savedarginfo = cgiarginfo::must;
214 argsinfo.addarginfo (NULL, arg_ainfo);
215
216 arg_ainfo.shortname = "cl";
217 arg_ainfo.longname = "classification OID";
218 arg_ainfo.multiplechar = true;
219 arg_ainfo.defaultstatus = cgiarginfo::none;
220 arg_ainfo.argdefault = "";
221 arg_ainfo.savedarginfo = cgiarginfo::can;
222 argsinfo.addarginfo (NULL, arg_ainfo);
223
224 // in this action "gc" controls the expand/contract
225 // contents function
226 arg_ainfo.shortname = "gc";
227 arg_ainfo.longname = "expand contents";
228 arg_ainfo.multiplechar = false;
229 arg_ainfo.defaultstatus = cgiarginfo::weak;
230 arg_ainfo.argdefault = "0";
231 arg_ainfo.savedarginfo = cgiarginfo::can;
232 argsinfo.addarginfo (NULL, arg_ainfo);
233
234 // in this action "gt" controls the expand/contract
235 // text function 0 = not expanded, 1 = expand unless
236 // there are more than 10 sections containing text,
237 // 2 = expand all
238 arg_ainfo.shortname = "gt";
239 arg_ainfo.longname = "expand text";
240 arg_ainfo.multiplechar = false;
241 arg_ainfo.defaultstatus = cgiarginfo::weak;
242 arg_ainfo.argdefault = "0";
243 arg_ainfo.savedarginfo = cgiarginfo::can;
244 argsinfo.addarginfo (NULL, arg_ainfo);
245
246 // in this action "gp" is the "go to page" control
247 // used by the Book type of toc
248 arg_ainfo.shortname = "gp";
249 arg_ainfo.longname = "go to page";
250 arg_ainfo.multiplechar = true;
251 arg_ainfo.defaultstatus = cgiarginfo::none;
252 arg_ainfo.argdefault = "";
253 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
254 argsinfo.addarginfo (NULL, arg_ainfo);
255
256 // in this action "hl" is the "highlighting on/
257 // highlighting off control
258 arg_ainfo.shortname = "hl";
259 arg_ainfo.longname = "highlighting on/off";
260 arg_ainfo.multiplechar = false;
261 arg_ainfo.defaultstatus = cgiarginfo::weak;
262 arg_ainfo.argdefault = "1";
263 arg_ainfo.savedarginfo = cgiarginfo::must;
264 argsinfo.addarginfo (NULL, arg_ainfo);
265
266 // "x" is 0 normally or 1 if page
267 // has been "detached"
268 arg_ainfo.shortname = "x";
269 arg_ainfo.longname = "detached page";
270 arg_ainfo.multiplechar = false;
271 arg_ainfo.defaultstatus = cgiarginfo::weak;
272 arg_ainfo.argdefault = "0";
273 arg_ainfo.savedarginfo = cgiarginfo::must;
274 argsinfo.addarginfo (NULL, arg_ainfo);
275
276 // f arg is set to 1 if document is to
277 // be displayed in a frame
278 arg_ainfo.shortname = "f";
279 arg_ainfo.longname = "frame";
280 arg_ainfo.multiplechar = false;
281 arg_ainfo.defaultstatus = cgiarginfo::weak;
282 arg_ainfo.argdefault = "0";
283 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
284 argsinfo.addarginfo (NULL, arg_ainfo);
285
286 // fc arg is "1" if search bar is to be included (i.e. if "fc" == 1
287 // the httpdocument macro will include "&f=1"
288 arg_ainfo.shortname = "fc";
289 arg_ainfo.longname = "include search bar";
290 arg_ainfo.multiplechar = false;
291 arg_ainfo.defaultstatus = cgiarginfo::weak;
292 arg_ainfo.argdefault = "1";
293 arg_ainfo.savedarginfo = cgiarginfo::must;
294 argsinfo.addarginfo (NULL, arg_ainfo);
295}
296
297documentaction::~documentaction () {
298}
299
300
301// output_controls displays the detach, expand/contract contents,
302// expand/contract text and highlighting/no highlighting buttons
303void documentaction::output_controls (cgiargsclass &args, const text_tarray &ibuttons,
304 recptproto * /*collectproto*/, displayclass &disp,
305 outconvertclass &outconvert, ostream &textout,
306 ostream &/*logout*/) {
307
308 if (args["u"] != "1") {
309
310 FilterResponse_t response;
311 text_tarray metadata;
312 text_tarray buttons;
313
314 text_tarray::const_iterator here = ibuttons.begin();
315 text_tarray::const_iterator end = ibuttons.end();
316
317 while (here != end) {
318
319 if (*here == "Detach")
320 buttons.push_back ("_document:imagedetach_");
321 else if (*here == "Highlight") {
322 if (args["hl"] == "1")
323 buttons.push_back ("_document:imagenohighlight_");
324 else
325 buttons.push_back ("_document:imagehighlight_");
326 } else if (*here == "Expand Contents") {
327 if (args["gc"] == "1")
328 buttons.push_back ("_document:imagecontracttoc_");
329 else
330 buttons.push_back ("_document:imageexpandtoc_");
331 } else if (*here == "Expand Text") {
332 if (args.getintarg("gt"))
333 buttons.push_back ("_document:imagecontracttext_");
334 else
335 buttons.push_back ("_document:imageexpandtext_");
336 }
337 here ++;
338 }
339
340 here = buttons.begin();
341 end = buttons.end();
342 int count = 0;
343 while (here != end) {
344 if ((count != 0) && ((count % 2) == 0)) textout << "<br>\n";
345 textout << outconvert << disp << *here;
346 count ++;
347 here ++;
348 }
349 }
350}
351
352void documentaction::output_formatstring (const text_t &OID, const text_t &collection,
353 recptproto *collectproto, const text_t &formatstring,
354 displayclass &disp, outconvertclass &outconvert,
355 ostream &textout, ostream &logout) {
356
357 if (OID.empty()) return;
358
359 text_tset metadata;
360 bool getParents;
361 FilterResponse_t response;
362
363 format_t *formatlistptr = new format_t();
364 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
365
366 if (!get_info (OID, collection, metadata, getParents, collectproto, response, logout))
367 return;
368
369 textout << outconvert << disp << get_formatted_string (response.docInfo[0], formatlistptr);
370}
371
372// output_headerstring outputs a formatstring that may contain the
373// [Buttons] and [TOC] elements. It separates these elements out,
374// calling output_controls and output_toc respectively to process
375// the special elements. Calls output_formatstring to process the
376// remaining bits of formatstring
377void documentaction::output_headerstring (cgiargsclass &args, recptproto *collectproto,
378 const text_t &formatstring, browsermapclass *browsers,
379 displayclass &disp, outconvertclass &outconvert,
380 ostream &textout, ostream &logout) {
381
382 text_t &OID = args["d"];
383 if (OID.empty()) OID = args["cl"];
384 text_t &collection = args["c"];
385
386 text_t::const_iterator here = formatstring.begin();
387 text_t::const_iterator end = formatstring.end();
388
389 text_t currentstring;
390 while (here != end) {
391 if ((*here == '[') && (*(here+1) == 'B') && (*(here+2) == 'u') &&
392 (*(here+3) == 't') && (*(here+4) == 't') && (*(here+5) == 'o') &&
393 (*(here+6) == 'n') && (*(here+7) == 's') && (*(here+8) == ']')) {
394 here += 8;
395 if (!currentstring.empty()) {
396 output_formatstring (OID, collection, collectproto, currentstring,
397 disp, outconvert, textout, logout);
398 currentstring.clear();
399 }
400
401 output_controls (args, formatinfo.DocumentButtons, collectproto,
402 disp, outconvert, textout, logout);
403
404 } else if ((*here == '[') && (*(here+1) == 'T') && (*(here+2) == 'O') &&
405 (*(here+3) == 'C') && (*(here+4) == ']')) {
406 here += 4;
407 if (!currentstring.empty()) {
408 output_formatstring (OID, collection, collectproto, currentstring,
409 disp, outconvert, textout, logout);
410 currentstring.clear();
411 }
412
413 output_toc (args, browsers, formatinfo.formatstrings, collectproto,
414 disp, outconvert, textout, logout);
415
416 } else {
417 currentstring.push_back (*here);
418 }
419
420 here ++;
421 }
422
423 if (!currentstring.empty())
424 output_formatstring (OID, collection, collectproto, currentstring,
425 disp, outconvert, textout, logout);
426}
427
428bool documentaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
429 ostream &logout) {
430
431 // check gc argument
432 int arg_gc = args.getintarg("gc");
433 if (arg_gc != 0 && arg_gc != 1) {
434 logout << "Warning: \"gc\" argument out of range (" << arg_gc << ")\n";
435 cgiarginfo *gcinfo = argsinfo.getarginfo ("gc");
436 if (gcinfo != NULL) args["gc"] = gcinfo->argdefault;
437 }
438
439 // check gt argument (may be either 0, 1 or 2)
440 int arg_gt = args.getintarg("gt");
441 if (arg_gt != 0 && arg_gt != 1 && arg_gt != 2) {
442 logout << "Warning: \"gt\" argument out of range (" << arg_gt << ")\n";
443 cgiarginfo *gtinfo = argsinfo.getarginfo ("gt");
444 if (gtinfo != NULL) args["gt"] = gtinfo->argdefault;
445 }
446
447 // check hl argument
448 int arg_hl = args.getintarg("hl");
449 if (arg_hl != 0 && arg_hl != 1) {
450 logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n";
451 cgiarginfo *hlinfo = argsinfo.getarginfo ("hl");
452 if (hlinfo != NULL) args["hl"] = hlinfo->argdefault;
453 }
454
455 // check x argument
456 int arg_x = args.getintarg("x");
457 if (arg_x != 0 && arg_x != 1) {
458 logout << "Warning: \"x\" argument out of range (" << arg_x << ")\n";
459 cgiarginfo *xinfo = argsinfo.getarginfo ("x");
460 if (xinfo != NULL) args["x"] = xinfo->argdefault;
461 }
462
463 return true;
464}
465
466void documentaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
467 response_t &response,text_t &response_data,
468 ostream &logout) {
469
470 if ((args["il"] == "w") && (!args["d"].empty())) {
471
472 recptproto* collectproto = protos->getrecptproto (args["c"], logout);
473 if (collectproto != NULL) {
474
475 text_tset metadata;
476 FilterResponse_t filt_response;
477 text_t top;
478
479 metadata.insert ("URL");
480
481 // get metadata for parent document
482 get_top (args["d"], top);
483 if (get_info (top, args["c"], metadata, false, collectproto, filt_response, logout)) {
484 text_t url = filt_response.docInfo[0].metadata["URL"].values[0];
485
486 response = location;
487 response_data = url;
488 return;
489 } else {
490 // error, no URL
491 logout << "Error: documentaction::get_cgihead_info failed on get_info" << endl;
492 }
493 }
494 }
495 response = content;
496 response_data = "text/html";
497}
498
499// set_widthtspace calculates how wide the spaces in the nav bar should
500// be and sets the appropriate macro
501void documentaction::set_spacemacro (displayclass &disp, FilterResponse_t &response) {
502
503 text_t width;
504 int twidth, swidth, iwidth = 0;
505
506 int numc = response.docInfo.size();
507 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
508 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
509
510 disp.expandstring ("Global", "_pagewidth_", width);
511 twidth = width.getint();
512
513 disp.expandstring ("query", "_searchwidth_", width);
514 iwidth += width.getint();
515
516
517
518 while (dochere != docend) {
519 const text_t &title = (*dochere).metadata["Title"].values[0];
520
521 disp.expandstring ("document", "_" + title + "width_", width);
522 if (width == ("_" + title + "width_"))
523 disp.expandstring ("document", "_defaultwidth_", width);
524 iwidth += width.getint();
525 dochere ++;
526 }
527 if ((twidth - iwidth) < numc) swidth = 2;
528 else {
529 swidth = twidth - iwidth;
530 if (numc > 0) swidth = swidth / numc;
531 }
532 disp.setmacro ("widthtspace", "Global", swidth);
533}
534
535// set_navbarmacros sets _navigationbar_, _javaimagesnavbar_ and _httpbrowseXXX_ macros
536// reponse contains 1 metadata field (Title)
537void documentaction::set_navbarmacros (displayclass &disp, FilterResponse_t &response,
538 cgiargsclass &args) {
539
540 text_t javaimagesnavbar, topparent;
541 text_t &arg_d = args["d"];
542 text_t navigationbar = "<!-- Navigation Bar -->\n";
543
544 get_top (args["cl"], topparent);
545 int numc = response.docInfo.size();
546 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
547 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
548
549 navigationbar += "<nobr>\n";
550 if (args["a"] == "q") {
551 navigationbar += "_icontabsearchgreen_";
552 } else {
553 navigationbar += "_imagesearch_";
554 javaimagesnavbar = "_javasearch_";
555 }
556
557
558 if (numc == 0) navigationbar += "_imagespacer_";
559
560 while (dochere != docend) {
561 text_t title = (*dochere).metadata["Title"].values[0];
562
563 bool unknown = false;
564
565 // test the _XXXwidth_ macro to see if image macros are
566 // defined for this type of classification - if not we'll
567 // just display the text
568 text_t tmpwidth;
569 disp.expandstring ("document", "_" + title + "width_", tmpwidth);
570 if (tmpwidth == ("_" + title + "width_")) unknown = true;
571
572 // if we're inside a document all the classification buttons should be enabled
573 if (arg_d.empty() && ((*dochere).OID == topparent)) {
574 if (unknown) navigationbar += "_imagespacer_&nbsp;" + title + "&nbsp;";
575 else navigationbar += "_imagespacer__icontab" + title + "green_";
576 } else {
577
578 // set the _httpbrowseXXX_ macro for this classification
579 if (unknown) navigationbar += "_imagespacer_&nbsp;<a href=\"_httpdocument_&cl=" +
580 (*dochere).OID + "\">" + title + "</a>&nbsp;";
581 else {
582 navigationbar += "_imagespacer__image" + title + "_";
583 disp.setmacro ("httpbrowse" + title, "Global", "_httpdocument_&cl=" + (*dochere).OID);
584 }
585 }
586 if (!unknown) javaimagesnavbar += "_java" + title + "_";
587 dochere ++;
588 }
589 navigationbar += "\n</nobr>\n";
590 navigationbar += "<!-- End of Navigation Bar -->\n";
591 disp.setmacro ("navigationbar", "Global", navigationbar);
592 if (args.getintarg("v") == 0)
593 disp.setmacro ("javaimagesnavbar", "Global", javaimagesnavbar);
594}
595
596// define all the macros which might be used by other actions
597// to produce pages.
598void documentaction::define_external_macros (displayclass &disp, cgiargsclass &args,
599 recptprotolistclass *protos, ostream &logout) {
600
601 // define_external_macros sets the following macros:
602
603 // _navigationbar_ this is the navigation bar containing the search button
604 // and any classification buttons - it goes at the top of
605 // most pages. for now we're assuming that there'll always
606 // be a search button - we should probably check that there
607 // is a query action before making this assumption
608
609 // _httpbrowseXXX_ the http macros for each classification (i.e. if there
610 // are Title and Creator classifications _httpbrowseTitle_
611 // and _httpbrowseCreator_ will be set
612
613 // _javaimagesnavbar_ this is the javascript code to shove in to make the
614 // flashy images used by _navigationbar_ work
615
616 // _widthtspace_ the width of the spacers between buttons in navigation
617 // bar
618
619 // _httpdocument_ has '&f=1' added if displaying document inside a frame
620
621 // _gsdltop_ macro to replace _top targets with
622
623 // _httppagehome_ overridden home url if html collections have own homepage
624
625 // must have a valid collection server to continue
626 text_t &collection = args["c"];
627 if (collection.empty()) return;
628 recptproto *collectproto = protos->getrecptproto (collection, logout);
629 if (collectproto == NULL) return;
630
631 outconvertclass text_t2ascii;
632 comerror_t err;
633 InfoFiltersResponse_t filterinfo;
634 FilterResponse_t response;
635 text_tset metadata;
636
637
638 // get info on current collection and load up formatinfo
639 // I'd prefer not to do this here as we're getting
640 // collection info every time (and probably also getting
641 // it in other places some of the time) - One day I'll
642 // fix it ... maybe - Stefan.
643 ColInfoResponse_t cinfo;
644 collectproto->get_collectinfo (collection, cinfo, err, logout);
645 load_formatinfo (cinfo.format, args.getintarg("gt"));
646
647 if (formatinfo.DocumentUseHTML) {
648
649 // frame stuff
650 if (args["fc"] == "1") {
651 text_t httpdocument;
652 disp.expandstring ("Global", "_httpdocument_", httpdocument);
653 httpdocument += "&f=1";
654 disp.setmacro ("httpdocument", "Global", httpdocument);
655 disp.setmacro ("gsdltop", "Global", "documenttop");
656 }
657 text_tmap::iterator it = cinfo.format.find ("homepage");
658 if (it != cinfo.format.end()) {
659 text_t httppagehome;
660 if (get_link (args, protos, (*it).second, httppagehome, logout))
661 disp.setmacro ("httppagehome", "Global", httppagehome);
662 }
663 }
664
665 // don't want navigation bar if page is 'detached'
666 if (!args.getintarg("x")) {
667
668 collectproto->get_filterinfo (collection, filterinfo, err, logout);
669 if (err == noError) {
670 // check that there's a browse filter
671 if (filterinfo.filterNames.find ("BrowseFilter") != filterinfo.filterNames.end()) {
672
673 metadata.insert ("Title");
674 bool getParents = false;
675 get_children ("", collection, metadata, getParents, collectproto, response, logout);
676
677 // calculate width of spacers and set _widthtspace_ macro
678 if (args.getintarg("v") == 0) set_spacemacro (disp, response);
679
680 // set _navigationbar_ and _javaimagesnavbar_ macros
681 set_navbarmacros (disp, response, args);
682
683 }
684 } else {
685 logout << text_t2ascii
686 << "Error (documentaction::define_external_macros()) in call to get_filterinfo() "
687 << get_comerror_string (err);
688 }
689 }
690}
691
692bool documentaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
693 const text_t &inlink, text_t &outlink, ostream &logout) {
694
695 FilterResponse_t response;
696 text_tset metadata;
697 metadata.insert ("section");
698
699 // check current collection first
700 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
701
702 if (get_info (inlink, args["c"], metadata, false, collectproto, response, logout)) {
703 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
704 outlink = "_httpdocument_&d=" + response.docInfo[0].metadata["section"].values[0];
705 return true;
706 }
707 }
708
709 // check all the other enabled collections
710
711 if (args["ccs"] == "1" && !args["cc"].empty()) {
712 text_tarray collections;
713 splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
714
715 text_tarray::const_iterator col_here = collections.begin();
716 text_tarray::const_iterator col_end = collections.end();
717
718 while (col_here != col_end) {
719
720 // don't need to check current collection again
721 if (*col_here == args["c"]) {col_here ++; continue;}
722
723 collectproto = protos->getrecptproto (*col_here, logout);
724
725 if (get_info (inlink, *col_here, metadata, false, collectproto, response, logout)) {
726 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
727 outlink = "_httpdocument_&c=" + *col_here + "&d=" +
728 response.docInfo[0].metadata["section"].values[0];
729 return true;
730 }
731 }
732 col_here ++;
733 }
734 }
735 return false;
736}
737
738void documentaction::load_formatinfo (const text_tmap &colformat, int gt) {
739
740 formatinfo.clear();
741 text_tmap::const_iterator format_here = colformat.begin();
742 text_tmap::const_iterator format_end = colformat.end();
743
744 while (format_here != format_end) {
745 if ((*format_here).first == "DocumentColumns")
746 formatinfo.DocumentColumns = (*format_here).second;
747 else if ((*format_here).first == "DocumentColumnsTotalWidth")
748 formatinfo.DocumentColumnsTotalWidth = (*format_here).second;
749 else if ((*format_here).first == "DocumentColumnLeft")
750 formatinfo.DocumentColumnLeft = (*format_here).second;
751 else if ((*format_here).first == "DocumentColumnLeftWidth")
752 formatinfo.DocumentColumnLeftWidth = (*format_here).second;
753 else if ((*format_here).first == "DocumentColumnRight")
754 formatinfo.DocumentColumnRight = (*format_here).second;
755 else if (((*format_here).first == "DocumentArrowsBottom") &&
756 ((*format_here).second == "false"))
757 formatinfo.DocumentArrowsBottom = false;
758 else if ((*format_here).first == "DocumentButtons")
759 splitchar ((*format_here).second.begin(), (*format_here).second.end(),
760 '|', formatinfo.DocumentButtons);
761 else if ((*format_here).first == "DocumentText")
762 formatinfo.DocumentText = (*format_here).second;
763 else if (((*format_here).first == "DocumentUseHTML") &&
764 ((*format_here).second == "true"))
765 formatinfo.DocumentUseHTML = true;
766 else
767 formatinfo.formatstrings[(*format_here).first] = (*format_here).second;
768
769 format_here ++;
770 }
771
772 // never want arrows when text is expanded
773 if (gt) formatinfo.DocumentArrowsBottom = false;
774}
775
776void documentaction::set_java_macros (cgiargsclass &args, displayclass &disp) {
777
778 text_t javaimagescontent = "_javaextras_";
779
780 int arg_gt = args.getintarg("gt");
781 int arg_gc = args.getintarg("gc");
782 int arg_hl = args.getintarg("hl");
783
784 text_tarray::const_iterator button_here = formatinfo.DocumentButtons.begin();
785 text_tarray::const_iterator button_end = formatinfo.DocumentButtons.end();
786
787 while (button_here != button_end) {
788 if (*button_here == "Detach")
789 javaimagescontent += "_javadetach_";
790 else if (*button_here == "Expand Text") {
791 if (arg_gt == 1)
792 javaimagescontent += "_javacontracttext__javacontinue_";
793 else if (arg_gt == 2)
794 javaimagescontent += "_javacontracttext_";
795 else
796 javaimagescontent += "_javaexpandtext_";
797 } else if (*button_here == "Expand Contents") {
798 if (arg_gc == 1)
799 javaimagescontent += "_javacontractcontents_";
800 else
801 javaimagescontent += "_javaexpandcontents_";
802 } else if (*button_here == "Highlight") {
803 if (arg_hl == 1)
804 javaimagescontent += "_javanohighlighting_";
805 else
806 javaimagescontent += "_javahighlighting_";
807 }
808 button_here ++;
809 }
810 disp.setmacro ("javaimagescontent", "document", javaimagescontent);
811}
812
813
814// define all the macros which are related to pages generated
815// by this action. we also load up the formatinfo structure
816// here (it's used in do_action as well as here)
817void documentaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
818 recptprotolistclass *protos, ostream &logout) {
819
820 // define_internal_macros sets the following macros:
821
822 // _pagetitle_ the title to be displayed at the top of the browser window
823
824 // _imagethispage_ the title image to be displayed at top right of page
825
826 // _navarrows_ this may be overridden to "" when format option
827 // DocumentArrowsBottom is false
828
829 // _header_ the header macro is overridden if we're not at a top level
830 // classification to remove the title block
831
832 // _javaimagescontent_ this is the javascript code to shove in to make the
833 // flashy buttons work
834
835 // _thisOID_ the OID (directory) of the current document - this corresponds
836 // to the archivedir metadata element
837
838 // must have a valid collection server to continue
839 text_t &collection = args["c"];
840 if (collection.empty()) return;
841 recptproto *collectproto = protos->getrecptproto (collection, logout);
842 if (collectproto == NULL) return;
843
844 text_tset metadata;
845 FilterResponse_t response;
846 text_t &arg_d = args["d"];
847 text_t &arg_cl = args["cl"];
848
849 if (!formatinfo.DocumentArrowsBottom)
850 disp.setmacro("navarrows", "document", "");
851
852 metadata.insert ("Title");
853
854 bool fulltoc = false;
855
856 if (args["cl"] != "search") {
857 // see if there's a FullTOC string
858 text_t cl_top, full_toc;
859 get_top (arg_cl, cl_top);
860 if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
861 if (full_toc == "true") fulltoc = true;
862 }
863
864 if (!arg_d.empty() && !fulltoc) {
865 // we're at document level
866
867 metadata.insert ("archivedir");
868
869 // get metadata for this document and it's parents
870 if (get_info (arg_d, collection, metadata, true, collectproto, response, logout)) {
871 disp.setmacro ("header", "document", "_textheader_");
872
873 text_tarray pagetitlearray;
874 if (!response.docInfo[0].metadata["Title"].values[0].empty())
875 pagetitlearray.push_back (response.docInfo[0].metadata["Title"].values[0]);
876 if (args["gt"] != "1") {
877 MetadataInfo_t *parenttitle = response.docInfo[0].metadata["Title"].parent;
878 while (parenttitle != NULL) {
879 if (!parenttitle->values[0].empty())
880 pagetitlearray.push_back (parenttitle->values[0]);
881 parenttitle = parenttitle->parent;
882 }
883 }
884 reverse (pagetitlearray.begin(), pagetitlearray.end());
885 text_t pagetitle;
886 joinchar (pagetitlearray, ": ", pagetitle);
887 disp.setmacro ("pagetitle", "document", pagetitle);
888
889 if (is_top (arg_d))
890 disp.setmacro ("thisOID", "Global", dm_safe(response.docInfo[0].metadata["archivedir"].values[0]));
891 else {
892 MetadataInfo_t *parentad = response.docInfo[0].metadata["archivedir"].parent;
893 text_t thisOID;
894 while (parentad != NULL) {
895 thisOID = parentad->values[0];
896 parentad = parentad->parent;
897 }
898 disp.setmacro ("thisOID", "Global", dm_safe(thisOID));
899 }
900
901 if (args["u"] != "1")
902 set_java_macros (args, disp);
903
904 }
905 } else {
906 if (!arg_cl.empty()) {
907
908 // get metadata for top level classification
909 text_t classtop;
910 get_top (arg_cl, classtop);
911 if (get_info (classtop, collection, metadata, false, collectproto, response, logout)) {
912
913 text_t &title = response.docInfo[0].metadata["Title"].values[0];
914 bool unknown = false;
915
916 // test the _XXXwidth_ macro to see if image macros are
917 // defined for this type of classification - if not we'll
918 // just display the text
919 text_t tmp;
920 disp.expandstring ("document", "_" + title + "width_", tmp);
921 if (tmp == ("_" + title + "width_")) unknown = true;
922
923 if (unknown) {
924 disp.setmacro ("pagetitle", "document", title);
925 disp.setmacro ("imagethispage", "document", "<h2>" + title + "</h2>");
926 } else {
927 disp.setmacro ("pagetitle", "document", "_text" + title + "page_");
928 disp.setmacro ("imagethispage", "document", "_icon" + title + "page_");
929 }
930 }
931 }
932 }
933}
934
935
936bool documentaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
937 browsermapclass *browsers, displayclass &disp,
938 outconvertclass &outconvert, ostream &textout,
939 ostream &logout) {
940
941
942 // must have a valid collection server
943 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
944 if (collectproto == NULL) {
945 logout << "documentaction::do_action called with NULL collectproto\n";
946 textout << outconvert << disp << "_document:header_\n"
947 << "Error: Attempt to get document without setting collection\n"
948 << "_document:footer_\n";
949 } else {
950
951 text_t OID = args["d"];
952 if (OID.empty()) OID = args["cl"];
953 if (OID.empty()) {
954 textout << outconvert << disp << "Document contains no data_document:footer_\n";
955 return true;
956 }
957
958 if (formatinfo.DocumentUseHTML) {
959
960 if (!args["d"].empty()) {
961 if (args["f"] == "1") {
962 textout << outconvert << disp
963 << "<html><head></head>\n"
964 << "<frameset rows=\"68,*\" noresize border=0>\n"
965 << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?e=_compressedoptions_&a=p&p=nav\">\n"
966 << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?e=_compressedoptions_&a=d&d="
967 << args["d"] << "\">"
968 << "<noframes>\n"
969 << "<p>You must have a frame enabled browser to view this.</p>\n"
970 << "</noframes>\n"
971 << "</frameset>\n"
972 << "</html>\n";
973 } else {
974 output_document (OID, args, collectproto, disp, outconvert, textout, logout);
975 }
976 return true;
977 }
978 }
979
980 textout << outconvert << disp << "_document:header_\n"
981 << "_document:content_\n";
982
983 // currently only display header information at document level,
984 // this should probably be changed to handle stuff like CL1Columns
985 if (!args["d"].empty()) {
986 textout << outconvert << disp
987 << "<p><center><table width=_pagewidth_><tr>\n"
988 << "<td valign=top";
989 if (formatinfo.DocumentColumns == "2") {
990 textout << outconvert << disp
991 << " width=" << formatinfo.DocumentColumnLeftWidth << ">\n";
992 output_headerstring (args, collectproto, formatinfo.DocumentColumnLeft,
993 browsers, disp, outconvert, textout, logout);
994 textout << "\n</td><td valign=top>\n";
995 output_headerstring (args, collectproto, formatinfo.DocumentColumnRight,
996 browsers, disp, outconvert, textout, logout);
997 } else {
998 textout << " width=100%>\n";
999 output_headerstring (args, collectproto, formatinfo.DocumentColumnLeft,
1000 browsers, disp, outconvert, textout, logout);
1001 }
1002 textout << "\n</td></tr></table></center>\n";
1003 } else {
1004 // classification level
1005 output_toc (args, browsers, formatinfo.formatstrings, collectproto,
1006 disp, outconvert, textout, logout);
1007 }
1008
1009 // output the document text
1010 textout << "<p>\n";
1011 output_document (OID, args, collectproto, disp, outconvert, textout, logout);
1012
1013 textout << outconvert << disp << "_document:footer_\n";
1014 }
1015 return true;
1016}
1017
1018void documentaction::output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
1019 const TermInfo_tarray &terminfo, const text_t &OID,
1020 bool highlight, int hastxt, int wanttext,
1021 text_t &collection, recptproto *collectproto,
1022 displayclass &disp, outconvertclass &outconvert,
1023 ostream &textout, ostream &logout) {
1024
1025 DocumentRequest_t docrequest;
1026 DocumentResponse_t docresponse;
1027 comerror_t err;
1028
1029 if (hastxt == 1) {
1030
1031 if (wanttext) {
1032 // get the text
1033 docrequest.OID = OID;
1034 collectproto->get_document (collection, docrequest, docresponse, err, logout);
1035
1036 // cut down on overhead by not using formattools if we only want the text
1037 // (wanttext will equal 2 if we want text and other stuff too)
1038 if (wanttext == 1)
1039 if (highlight)
1040 highlighttext(docresponse.doc, terminfo, disp, outconvert, textout, logout);
1041 else
1042 textout << outconvert << disp << docresponse.doc;
1043 }
1044
1045 if (wanttext != 1) {
1046 text_t doctext = get_formatted_string (docinfo, formatlistptr, docresponse.doc);
1047
1048 if (highlight)
1049 highlighttext(doctext, terminfo, disp, outconvert, textout, logout);
1050 else
1051 textout << outconvert << disp << doctext;
1052 }
1053 }
1054}
1055
1056
1057void documentaction::output_document (const text_t &OID, cgiargsclass &args,
1058 recptproto *collectproto, displayclass &disp,
1059 outconvertclass &outconvert, ostream &textout,
1060 ostream &logout) {
1061 FilterResponse_t inforesponse;
1062 FilterResponse_t queryresponse;
1063 text_tset metadata;
1064 bool getParents = false;
1065 bool highlight = false;
1066 int wanttext = 0;
1067 int arg_gt = args.getintarg("gt");
1068 text_t &collection = args["c"];
1069
1070 // if we have a query string and highlighting is turned on we need
1071 // to redo the query to get the terms for highlighting
1072 if (!args["q"].empty() && args.getintarg("hl")) {
1073 FilterRequest_t request;
1074 comerror_t err;
1075 request.filterResultOptions = FRmatchTerms;
1076 text_t formattedstring = args["q"];
1077 format_querystring (formattedstring, args.getintarg("b"));
1078 set_queryfilter_options (request, formattedstring, args);
1079 collectproto->filter (args["c"], request, queryresponse, err, logout);
1080 if (err != noError) {
1081 outconvertclass text_t2ascii;
1082 logout << text_t2ascii
1083 << "documentaction::output_document: call to QueryFilter failed "
1084 << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
1085 highlight = false;
1086 } else {
1087 highlight = true;
1088 }
1089 }
1090
1091 format_t *formatlistptr = new format_t();
1092 parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
1093
1094 metadata.insert ("hastxt");
1095 metadata.insert ("haschildren");
1096
1097 if (formatinfo.DocumentText == "[Text]")
1098 wanttext = 1;
1099 else {
1100 char *docformat = formatinfo.DocumentText.getcstr();
1101 if (strstr (docformat, "[Text]") != NULL)
1102 wanttext = 2;
1103 delete docformat;
1104 }
1105
1106 if (get_info (OID, collection, metadata, getParents, collectproto, inforesponse, logout)) {
1107 int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
1108 int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
1109
1110 if (arg_gt == 0) {
1111 output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
1112 OID, highlight, hastxt, wanttext, collection, collectproto,
1113 disp, outconvert, textout, logout);
1114
1115
1116 } else {
1117
1118 ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
1119
1120 // text is to be expanded
1121 text_t exOID = OID;
1122 if (haschildren != 1) exOID = get_parent (OID);
1123 if (exOID.empty()) exOID = OID;
1124
1125 // if we're not in a document (i.e. we're in a top level classification)
1126 // we need to pass "is_classify = true" to get_contents so that it
1127 // doesn't recurse all the way through each document in the classification
1128 bool is_classify = false;
1129 if (args["d"].empty()) is_classify = true;
1130
1131 get_contents (exOID, is_classify, metadata, collection,
1132 collectproto, inforesponse, logout);
1133
1134 ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
1135 ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
1136
1137 if (arg_gt == 1) {
1138 // check if there are more than 10 sections containing text to be expanded -
1139 // if there are output warning message - this isn't a great way to do this
1140 // since the sections may be very large or very small - one day I'll fix it
1141 // -- Stefan.
1142 int seccount = 0;
1143 while (sechere != secend) {
1144 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
1145 if (shastxt == 1) seccount ++;
1146 if (seccount > 10) break;
1147 sechere ++;
1148 }
1149 if (seccount > 10) {
1150 // more than 10 sections so output warning message and text
1151 // for current section only
1152 textout << outconvert << disp << "_document:textltwarning_";
1153
1154 output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
1155 OID, highlight, hastxt, wanttext, collection,
1156 collectproto, disp, outconvert, textout, logout);
1157
1158 }
1159 else arg_gt = 2;
1160 }
1161
1162 if (arg_gt == 2) {
1163 // get the text for each section
1164 sechere = inforesponse.docInfo.begin();
1165 int count = 0;
1166 while (sechere != secend) {
1167 textout << outconvert << disp << "\n<p><a name=" << count << "></a>\n";
1168
1169 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
1170
1171 output_text (*sechere, formatlistptr, queryresponse.termInfo,
1172 (*sechere).OID, highlight, shastxt, wanttext, collection,
1173 collectproto, disp, outconvert, textout, logout);
1174 count ++;
1175 sechere ++;
1176 }
1177 }
1178 }
1179 }
1180 delete formatlistptr;
1181}
1182
1183// highlighttext highlights query terms in text string and outputs the resulting text string
1184void documentaction::highlighttext(text_t &text, const TermInfo_tarray &terms,
1185 displayclass &disp, outconvertclass &outconvert,
1186 ostream &textout, ostream &/*logout*/) {
1187
1188 text_tmap allterms;
1189 text_tmap::const_iterator it;
1190
1191 // first load all the term variations into a map
1192 TermInfo_tarray::const_iterator this_term = terms.begin();
1193 TermInfo_tarray::const_iterator last_term = terms.end();
1194 while (this_term != last_term) {
1195 text_tarray::const_iterator this_var = (*this_term).matchTerms.begin();
1196 text_tarray::const_iterator last_var = (*this_term).matchTerms.end();
1197 while (this_var != last_var) {
1198 allterms[*this_var] = 1;
1199 this_var ++;
1200 }
1201 this_term ++;
1202 }
1203
1204 // get the text to start and end a hightlight
1205 text_t starthighlight = "<b><u>";
1206 text_t endhighlight = "</u></b>";
1207 if (disp.isdefaultmacro("Global", "starthighlight"))
1208 disp.expandstring("Global", "_starthighlight_", starthighlight);
1209 if (disp.isdefaultmacro("Global", "endhighlight"))
1210 disp.expandstring("Global", "_endhighlight_", endhighlight);
1211
1212
1213 text_t::iterator here = text.begin();
1214 text_t::iterator end = text.end();
1215 text_t word, buffer;
1216 while (here != end) {
1217 if (is_unicode_letdig(*here)) {
1218 // not word boundary
1219 word.push_back(*here);
1220 here++;
1221
1222 } else {
1223 // found word boundary
1224 // add last word if there was one
1225 if (!word.empty()) {
1226 it = allterms.find(word);
1227 if (it != allterms.end()) {
1228 word = starthighlight + word + endhighlight;
1229 }
1230 buffer += word;
1231 word.clear();
1232 }
1233
1234 if (*here == '<') {
1235 // skip over rest of html tag
1236 while ((here != end) && (*here != '>')) {
1237 buffer.push_back(*here);
1238 here++;
1239 }
1240 }
1241
1242 buffer.push_back(*here);
1243 here++;
1244
1245 if (buffer.size() > 1024) {
1246 textout << outconvert << disp << buffer;
1247 buffer.clear();
1248 }
1249 }
1250 }
1251 textout << outconvert << disp << buffer;
1252}
Note: See TracBrowser for help on using the repository browser.