source: branches/New_Config_Format-branch/gsdl/src/recpt/documentaction.cpp@ 1258

Last change on this file since 1258 was 1258, checked in by nzdl, 24 years ago

caught New_Config_Format-branch up with changes to trunk

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