source: branches/corba/gsdl/src/recpt/browsetools.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: 20.9 KB
Line 
1
2/**********************************************************************
3 *
4 * browsetools.cpp --
5 * Copyright (C) 1999 The New Zealand Digital Library Project
6 *
7 * A component of the Greenstone digital library software
8 * from the New Zealand Digital Library Project at the
9 * University of Waikato, New Zealand.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * $Id: browsetools.cpp 1067 2000-04-04 15:02:39Z cs025 $
26 *
27 *********************************************************************/
28
29/*
30 $Log$
31 Revision 1.41.2.1 2000/04/04 15:02:34 cs025
32 Corba first commit
33
34 Revision 1.41 2000/04/03 07:25:02 sjboddie
35 replaced old DocumentIcon and DocumentContents format options
36 with DocumentColumn stuff
37
38 Revision 1.40 2000/03/31 03:04:30 nzdl
39 tidied up some of the browsing code - replaced DocumentImages,
40 DocumentTitles and DocumentHeading with DocumentIcon
41
42 Revision 1.39 2000/02/25 02:28:43 sjboddie
43 caught up with assoc directory changes for displaying cover images
44
45 Revision 1.38 2000/02/17 02:42:24 sjboddie
46 minor stuff - fixed some cvs conflicts
47
48 Revision 1.37 2000/02/15 22:53:47 kjm18
49 search history stuff added.
50
51 Revision 1.36 2000/02/06 21:31:36 sjboddie
52 made some formerly static functions accessible from elsewhere (for
53 cstr receptionist)
54
55 Revision 1.35 2000/01/26 23:46:16 sjboddie
56 wrap every second button now (was every third)
57
58 Revision 1.34 1999/11/09 02:28:47 sjboddie
59 fixed minor bug in expanded contents
60
61 Revision 1.33 1999/10/30 22:22:26 sjboddie
62 added collection argument to browserclass output_section_group
63 functions -- moved table functions to formattools
64
65 Revision 1.32 1999/10/24 07:22:37 sjboddie
66 added a FullTOC option
67
68 Revision 1.31 1999/10/20 03:54:20 sjboddie
69 problem with expanded contents
70
71 Revision 1.30 1999/10/19 21:36:59 sjboddie
72 fixed bug in DocumentContents
73
74 Revision 1.29 1999/10/19 08:40:12 sjboddie
75 fixed some stupid compiler warnings on windows
76
77 Revision 1.28 1999/10/18 20:08:36 sjboddie
78 tidied up a few things
79
80 Revision 1.27 1999/10/15 03:31:42 sjboddie
81 oops, left out an '&'
82
83 Revision 1.26 1999/10/14 22:58:05 sjboddie
84 finished up on changes to browseing support - may still need some
85 tidying up
86
87 Revision 1.25 1999/10/10 08:14:04 sjboddie
88 - metadata now returns mp rather than array
89 - redesigned browsing support (although it's not finished so
90 won't currently work ;-)
91
92 Revision 1.24 1999/09/28 01:46:55 rjmcnab
93 removed some unused stuff
94
95 Revision 1.23 1999/09/23 10:09:17 sjboddie
96 made some changes so AZLists within other classifications are
97 handled properly
98
99 Revision 1.22 1999/09/07 23:06:58 rjmcnab
100 removed some compiler warnings.
101
102 Revision 1.21 1999/09/07 04:56:52 sjboddie
103 added GPL notice
104
105 Revision 1.20 1999/08/25 04:46:58 sjboddie
106 fixed bug
107
108 Revision 1.19 1999/08/13 04:18:04 sjboddie
109 fixed some typos
110
111 Revision 1.18 1999/08/10 22:42:21 sjboddie
112 added more format options to document tocs - there are now just two
113 types of toc - standard (Hierarchical) and document (as in books)
114
115 Revision 1.17 1999/08/09 02:12:07 sjboddie
116 made it so dates may be only 4 digits (i.e. year only)
117
118 Revision 1.16 1999/07/30 02:16:10 sjboddie
119 -added ability to display nested classifications (expanded versions
120 of nested classifications has yet to be done).
121 -changed set_arrow_macros slightly to fit in with new showtoppage
122 format option
123
124 Revision 1.15 1999/07/21 05:01:56 sjboddie
125 wrote handler for DateList classification
126
127 Revision 1.14 1999/07/20 02:58:15 sjboddie
128 got List and AZList classifications using format strings - tidied
129 up a bit
130
131 Revision 1.13 1999/07/07 05:44:25 sjboddie
132 Made some changes to allow for new way classifiers work (i.e. you can
133 now have classifiers containing other classifiers). At present there's
134 only a special case for dealing with the hdl 'magazine' section. A bit
135 of a redesign is needed to get it completely flexible
136
137 Revision 1.12 1999/07/01 03:47:49 rjmcnab
138 Fixed a small warning.
139
140 Revision 1.11 1999/06/27 21:49:01 sjboddie
141 fixed a couple of version conflicts - tidied up some small things
142
143 Revision 1.10 1999/06/26 01:07:21 rjmcnab
144 Fixed a small "bug" -- well I probably just covered another one...
145
146 Revision 1.9 1999/06/24 05:12:15 sjboddie
147 lots of small changes
148
149 Revision 1.8 1999/06/17 03:06:53 sjboddie
150 got detach button working properly - the close book icon is now disabled
151 when page is detached as the javascript close() function I was using is
152 too unreliable over different browsers
153 note that in my last comment I meant the "cl" arg (not the "c" arg).
154
155 Revision 1.7 1999/06/16 23:53:14 sjboddie
156 tidied a few things up. documentaction::define_external_macros now
157 resets the "c" arg if it's set to something stupid by the .xx suffixes
158
159 Revision 1.6 1999/06/16 04:03:47 sjboddie
160 Now sets "cl" arg to "search" when going to a document from a search
161 results page. This allows the close book icon (in hierarchy toc) to
162 take you back to the results page if that's where you came from.
163 If you got to the document page somehow other than from a
164 classification or a search (i.e. if "cl" isn't set) then the close
165 book icon is disabled
166
167 Revision 1.5 1999/06/16 03:11:25 sjboddie
168 get_info() now takes a getParents argument
169
170 Revision 1.4 1999/05/10 03:40:26 sjboddie
171 lots of changes - slowly getting document action sorted out
172
173 Revision 1.3 1999/04/30 01:59:39 sjboddie
174 lots of stuff - getting documentaction working (documentaction replaces
175 old browseaction)
176
177 Revision 1.2 1999/03/29 02:14:29 sjboddie
178
179 More changes to browseaction
180
181 Revision 1.1 1999/03/25 03:10:15 sjboddie
182
183 new library for browse stuff
184
185 */
186
187#include "browsetools.h"
188#include "OIDtools.h"
189
190
191static void recurse_contents (ResultDocInfo_t &section, cgiargsclass &args, bool fulltoc,
192 browserclass *bptr, text_tset &metadata, bool &getParents,
193 format_t *formatlistptr, format_tmap &formatlistmap,
194 text_tmap &formatstrings, browsermapclass *browsermap,
195 int tabcount, recptproto *collectproto, displayclass &disp,
196 outconvertclass &outconvert, ostream &textout, ostream &logout) {
197 text_t formatstring;
198
199 bool is_classify = false;
200 if (args["d"].empty() || fulltoc) is_classify = true;
201
202 // output this section
203 bool use_table = is_table_content (formatlistptr);
204 tabcount += bptr->output_section_group (section, args, "", tabcount, formatlistptr, use_table,
205 metadata, getParents, collectproto, disp, outconvert,
206 textout, logout);
207
208 text_t classification;
209 if (!is_classify) classification = "Document";
210 else get_top (args["cl"], classification);
211
212 int haschildren = section.metadata["haschildren"].values[0].getint();
213 const text_t &doctype = section.metadata["doctype"].values[0];
214 text_t classifytype = section.metadata["childtype"].values[0];
215 // HLists and DateLists are displayed as VLists when contents
216 // are expanded, Paged documents are displayed as HLists
217 if (classifytype == "HList" || classifytype == "DateList") classifytype = "VList";
218 if (classifytype == "Paged") classifytype = "HList";
219
220 // recurse through children
221 if ((haschildren == 1) && (!is_classify || fulltoc || doctype == "classify")) {
222
223 // get browser for displaying children
224 bptr = browsermap->getbrowser (classifytype);
225 bptr->load_metadata_defaults (metadata);
226
227 // get the formatstring if there is one
228 if (!get_formatstring (classification, classifytype, formatstrings, formatstring))
229 formatstring = bptr->get_default_formatstring();
230
231 format_tmap::const_iterator it = formatlistmap.find (formatstring);
232 // check if formatlistptr is cached
233 if (it != formatlistmap.end()) formatlistptr = (*it).second;
234 else {
235 formatlistptr = new format_t();
236 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
237 formatlistmap[formatstring] = formatlistptr;
238 }
239
240 FilterResponse_t tmp;
241 get_children (section.OID, args["c"], metadata, getParents, collectproto, tmp, logout);
242 ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
243 ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
244
245 while (thisdoc != lastdoc) {
246 recurse_contents (*thisdoc, args, fulltoc, bptr, metadata, getParents,
247 formatlistptr, formatlistmap, formatstrings, browsermap,
248 tabcount, collectproto, disp, outconvert, textout, logout);
249 thisdoc ++;
250 }
251 }
252}
253
254
255// expanded_contents recurses through all contents. there's a special case
256// for an HList when contents are expanded (i.e. it's displayed as a VList)
257//
258// if we're inside a document we expand all contents from the top,
259// if we're at classification level we'll just expand out those contents below
260// the current one
261
262static void expanded_contents (cgiargsclass &args, int tabcount, bool fulltoc,
263 browsermapclass *browsermap, text_tmap &formatstrings,
264 recptproto *collectproto, displayclass &disp,
265 outconvertclass &outconvert, ostream &textout,
266 ostream &logout) {
267
268 if (args["d"].empty() && args["cl"].empty()) return;
269 text_t OID;
270
271 FilterResponse_t response;
272 bool getParents = false;
273 text_tset metadata;
274 text_t classifytype, classification, formatstring;
275
276 if (!args["d"].empty()) {
277 // document level
278 if (fulltoc) {
279 get_top (args["cl"], OID);
280 classification = OID;
281 }
282 else {
283 // always expand document level from top
284 get_top (args["d"], OID);
285 classification = "Document";
286 }
287 } else {
288 // classification level
289 OID = args["cl"];
290 get_top (args["cl"], classification);
291 }
292
293 // get classifytype of this level
294 text_t tOID;
295 if (is_top(OID)) {
296 classifytype = "thistype";
297 tOID = OID;
298 } else {
299 classifytype = "childtype";
300 tOID = get_parent (OID);
301 }
302 metadata.insert (classifytype);
303
304 if (!get_info (tOID, args["c"], metadata, getParents, collectproto, response, logout))
305 return;
306 classifytype = response.docInfo[0].metadata[classifytype].values[0];
307 // if we still don't have a classifytype we'll use the default
308 if (classifytype.empty()) {
309 browserclass *bptr = browsermap->get_default_browser ();
310 classifytype = bptr->get_browser_name ();
311 }
312
313 // HLists are displayed as VLists when contents are expanded,
314 // Paged documents are displayed as HLists
315 if (classifytype == "HList") {
316 classifytype = "VList";
317 text_t pOID = get_parent (OID);
318 if (!pOID.empty()) {
319 OID = pOID;
320 // this is assuming that top levels are always 'Invisible' !!!
321 if (is_top (OID)) classifytype = "Invisible";
322 }
323 }
324 if (classifytype == "Paged") classifytype = "HList";
325
326 metadata.erase (metadata.begin(), metadata.end());
327
328 // metadata elements needed by recurse_contents
329 metadata.insert ("childtype");
330 metadata.insert ("doctype");
331 metadata.insert ("haschildren");
332
333 // load up metadata array with browser defaults
334 browserclass *bptr = browsermap->getbrowser (classifytype);
335 bptr->load_metadata_defaults (metadata);
336
337 // get the formatstring if there is one or use the browsers default
338 if (!get_formatstring (classification, classifytype, formatstrings, formatstring))
339 formatstring = bptr->get_default_formatstring();
340
341 format_t *formatlistptr = new format_t();
342 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
343
344 // protocol call
345 if (!get_info (OID, args["c"], metadata, getParents, collectproto, response, logout))
346 return;
347
348 format_tmap formatlistmap;
349 formatlistmap[formatstring] = formatlistptr;
350
351 recurse_contents (response.docInfo[0], args, fulltoc, bptr, metadata,
352 getParents, formatlistptr, formatlistmap, formatstrings, browsermap,
353 tabcount, collectproto, disp, outconvert, textout, logout);
354
355 // clean up format list pointers
356 format_tmap::const_iterator here = formatlistmap.begin();
357 format_tmap::const_iterator end = formatlistmap.end();
358 while (here != end) {
359 delete (*here).second;
360 here ++;
361 }
362}
363
364
365static void load_formatstring (const text_t &classifytype, text_tset &metadata,
366 bool &getParents, const text_t &classification,
367 browsermapclass *browsermap, text_tmap &formatstrings,
368 format_tmap &formatlistmap) {
369 text_t formatstring;
370
371 // load up metadata array with browser defaults
372 browserclass *bptr = browsermap->getbrowser (classifytype);
373 bptr->load_metadata_defaults (metadata);
374
375 // get the formatstring if there is one or use the browsers default
376 if (!get_formatstring (classification, classifytype, formatstrings, formatstring))
377 formatstring = bptr->get_default_formatstring();
378
379 // see if it's cached
380 format_tmap::const_iterator it = formatlistmap.find (formatstring);
381 if (it == formatlistmap.end()) {
382 format_t *formatlistptr = new format_t();
383 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
384 formatlistmap[formatstring] = formatlistptr;
385 }
386}
387
388static void load_formatstrings (FilterResponse_t &response, text_tset &metadata,
389 bool &getParents, const text_t &classification,
390 browsermapclass *browsermap, text_tmap &formatstrings,
391 format_tmap &formatlistmap) {
392
393 text_tset cache;
394
395 ResultDocInfo_tarray::iterator thisdoc = response.docInfo.begin();
396 ResultDocInfo_tarray::iterator lastdoc = response.docInfo.end();
397
398 while (thisdoc != lastdoc) {
399
400 if (is_top ((*thisdoc).OID))
401 load_formatstring ((*thisdoc).metadata["thistype"].values[0], metadata,
402 getParents, classification, browsermap, formatstrings,
403 formatlistmap);
404
405 text_t &childtype = (*thisdoc).metadata["childtype"].values[0];
406 text_tset::const_iterator it = cache.find (childtype);
407 if (it == cache.end()) {
408 load_formatstring (childtype, metadata, getParents, classification,
409 browsermap, formatstrings, formatlistmap);
410 cache.insert (childtype);
411 }
412 thisdoc ++;
413 }
414}
415
416static void output_parents (FilterResponse_t &response, cgiargsclass &args,
417 browsermapclass *browsermap, text_tmap &formatstrings,
418 format_tmap &formatlistmap, const text_t &classification,
419 int &tabcount, text_tset &metadata, bool &getParents,
420 recptproto *collectproto, displayclass &disp,
421 outconvertclass &outconvert, ostream &textout,
422 ostream &logout) {
423
424 format_t *formatlistptr = NULL;
425 text_t classifytype, formatstring;
426 bool use_table, first = true;
427 ResultDocInfo_tarray::iterator thisparent = response.docInfo.begin();
428 ResultDocInfo_tarray::iterator lastparent = response.docInfo.end();
429 while (thisparent != lastparent) {
430
431 // get classifytype of this level
432 if (is_top ((*thisparent).OID)) classifytype = (*thisparent).metadata["thistype"].values[0];
433 else if (!first) classifytype = (*(thisparent-1)).metadata["childtype"].values[0];
434
435 // if we still don't have a classifytype we'll use the default
436 if (classifytype.empty()) {
437 browserclass *bptr = browsermap->get_default_browser ();
438 classifytype = bptr->get_browser_name ();
439 }
440
441 browserclass *bptr = browsermap->getbrowser (classifytype);
442
443 // get the formatstring if there is one or use the browsers default
444 if (!get_formatstring (classification, classifytype, formatstrings, formatstring))
445 formatstring = bptr->get_default_formatstring();
446
447 // see if it's cached
448 format_tmap::const_iterator it = formatlistmap.find (formatstring);
449 if (it != formatlistmap.end()) formatlistptr = (*it).second;
450 else {
451 logout << "browsetools error\n";
452 return;
453 }
454
455 use_table = is_table_content (formatlistptr);
456 tabcount += bptr->output_section_group (*thisparent, args, "", tabcount, formatlistptr,
457 use_table, metadata, getParents, collectproto,
458 disp, outconvert, textout, logout);
459 first = false;
460 thisparent ++;
461 }
462}
463
464static void contracted_contents (cgiargsclass &args, int tabcount, bool fulltoc,
465 browsermapclass *browsermap, text_tmap &formatstrings,
466 recptproto *collectproto, displayclass &disp,
467 outconvertclass &outconvert, ostream &textout,
468 ostream &logout) {
469
470 FilterResponse_t response;
471 text_tset metadata;
472 bool getParents = false;
473 text_t formatstring;
474 text_tarray parents;
475 text_t OID = args["d"];
476 text_t classification = "Document";
477
478 // if we're not outputting the TOC for a valid OID, then we should be giving
479 // the TOC of a classification
480 if (OID.empty()) {
481 OID = args["cl"];
482 get_top (OID, classification);
483 }
484 // if we're to give the full TOC of a document, get the parent for the whole
485 // document now
486 else if (fulltoc)
487 get_top (args["cl"], classification);
488
489 bool haschildren = has_children (OID, args["c"], collectproto, logout);
490
491 if ((!args["d"].empty()) && fulltoc)
492 get_parents_array (args["cl"] + ".fc", parents);
493 if (haschildren) get_parents_array (OID + ".fc", parents);
494 else get_parents_array (OID, parents);
495
496 if (!parents.empty()) {
497 // get classifytypes of each parent
498 metadata.insert ("thistype");
499 metadata.insert ("childtype");
500
501 if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
502 return;
503
504 // get formatstrings for all parents
505 format_tmap formatlistmap;
506 load_formatstrings (response, metadata, getParents, classification,
507 browsermap, formatstrings, formatlistmap);
508
509 if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
510 return;
511
512 // display each parent
513 output_parents (response, args, browsermap, formatstrings, formatlistmap,
514 classification, tabcount, metadata, getParents,
515 collectproto, disp, outconvert, textout, logout);
516
517 metadata.erase (metadata.begin(), metadata.end());
518
519 // clean up cached format list pointers
520 format_tmap::const_iterator here = formatlistmap.begin();
521 format_tmap::const_iterator end = formatlistmap.end();
522 while (here != end) {
523 delete (*here).second;
524 here ++;
525 }
526 }
527
528 // get childrens classifytype
529 text_t classifytype;
530 int numparents = response.docInfo.size();
531 if (!parents.empty())
532 classifytype = response.docInfo[numparents-1].metadata["childtype"].values[0];
533 else {
534 // use the default
535 browserclass *bptr = browsermap->get_default_browser ();
536 classifytype = bptr->get_browser_name ();
537 }
538
539 // load up metadata array with browser defaults
540 browserclass *bptr = browsermap->getbrowser (classifytype);
541 bptr->load_metadata_defaults (metadata);
542
543 // get the formatstring if there is one or use the browsers default
544 if (!get_formatstring (classification, classifytype, formatstrings, formatstring))
545 formatstring = bptr->get_default_formatstring();
546
547 format_t *formatlistptr = new format_t();
548 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
549
550 if (haschildren)
551 get_children (OID, args["c"], metadata, getParents,
552 collectproto, response, logout);
553 else if (!is_top(OID)) {
554 get_children (OID + ".pr", args["c"], metadata, getParents,
555 collectproto, response, logout);
556 haschildren = true;
557 }
558
559 // display children
560 if (haschildren) {
561 bool use_table = is_table_content (formatlistptr);
562 bptr->output_section_group (response, args, "", tabcount, formatlistptr, use_table,
563 metadata, getParents, collectproto, disp, outconvert,
564 textout, logout);
565 }
566
567 delete formatlistptr;
568}
569
570/**
571 * This function outputs the contents of a classifier list to the reader -
572 * the document will in fact be empty, so this does the "real" output
573 */
574void output_toc (cgiargsclass &args, browsermapclass *browsermap,
575 text_tmap &formatstrings, recptproto *collectproto,
576 displayclass &disp, outconvertclass &outconvert,
577 ostream &textout, ostream &logout) {
578
579 int tabcount = 0;
580 bool fulltoc = false;
581
582 if (args["cl"] != "search") {
583 // see if there's a FullTOC string
584 text_t cl_top, full_toc;
585 get_top (args["cl"], cl_top);
586 if (get_formatstring (cl_top, "FullTOC", formatstrings, full_toc))
587 if (full_toc == "true") fulltoc = true;
588 }
589
590 if (args["gc"] == 1) {
591
592 // expanded table of contents
593 expanded_contents (args, tabcount, fulltoc, browsermap, formatstrings,
594 collectproto, disp, outconvert, textout, logout);
595 } else {
596
597 // contracted table of contents
598 contracted_contents (args, tabcount, fulltoc, browsermap, formatstrings,
599 collectproto, disp, outconvert, textout, logout);
600 }
601}
Note: See TracBrowser for help on using the repository browser.