source: trunk/gsdl/src/recpt/browsetools.cpp@ 5017

Last change on this file since 5017 was 4983, checked in by sjboddie, 21 years ago

Bug fix in recent changes to document formatting code

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 30.1 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 4983 2003-07-18 17:34:48Z sjboddie $
26 *
27 *********************************************************************/
28
29#include "browsetools.h"
30#include "OIDtools.h"
31#include "gsdlunicode.h"
32
33#include <sstream>
34
35
36// output_controls displays the detach, expand/contract contents,
37// expand/contract text and highlighting/no highlighting buttons
38
39void output_controls (cgiargsclass &args, const text_tarray &ibuttons,
40 recptproto * /*collectproto*/, displayclass &disp,
41 outconvertclass &outconvert, ostream &textout,
42 ostream &/*logout*/) {
43
44 if (args["u"] != "1") {
45
46 FilterResponse_t response;
47 text_tarray metadata;
48 text_tarray buttons;
49
50 text_tarray::const_iterator here = ibuttons.begin();
51 text_tarray::const_iterator end = ibuttons.end();
52
53 while (here != end) {
54
55 if (*here == "Detach")
56 buttons.push_back ("_document:imagedetach_");
57 else if (*here == "Highlight") {
58 if (args["hl"] == "1")
59 buttons.push_back ("_document:imagenohighlight_");
60 else
61 buttons.push_back ("_document:imagehighlight_");
62 } else if (*here == "Expand Contents") {
63 if (args["gc"] == "1")
64 buttons.push_back ("_document:imagecontracttoc_");
65 else
66 buttons.push_back ("_document:imageexpandtoc_");
67 } else if (*here == "Expand Text") {
68 if (args.getintarg("gt"))
69 buttons.push_back ("_document:imagecontracttext_");
70 else
71 buttons.push_back ("_document:imageexpandtext_");
72 }
73 here ++;
74 }
75
76 here = buttons.begin();
77 end = buttons.end();
78 int count = 0;
79 while (here != end) {
80 if ((count != 0) && ((count % 2) == 0)) textout<< outconvert << "<br>\n";
81 textout << outconvert << disp << *here;
82 count ++;
83 here ++;
84 }
85 }
86}
87
88text_t get_cover_image () {
89 return "_httpcollimg_/{Or}{[parent(Top):archivedir],[archivedir]}/cover.jpg";
90}
91
92// at the moment this just writes out the html to display
93// the cover image (assuming it's called cover.jpg)
94// this whole thing should be done with a call to the collection
95// server which would send a link to the cover image if there
96// was one otherwise send title, author and stuff
97void output_cover_image (cgiargsclass &args, recptproto * /*collectproto*/,
98 displayclass &disp, outconvertclass &outconvert,
99 ostream &textout, ostream &/*logout*/) {
100
101 if (args["d"].empty()) return;
102
103 textout << outconvert << disp << "<img src=\"_httpcollimg_/_thisOID_/cover.jpg\"><br>\n";
104}
105
106void output_titles (cgiargsclass &args, recptproto *collectproto,
107 browsermapclass *browsermap, formatinfo_t &formatinfo,
108 displayclass &disp, outconvertclass &outconvert,
109 ostream &textout, ostream &logout) {
110
111 if (args["d"].empty()) return;
112
113 text_tset metadata;
114 bool getParents;
115 FilterResponse_t response;
116
117 format_t *formatlistptr = new format_t();
118 parse_formatstring (formatinfo.DocumentHeading, formatlistptr, metadata, getParents);
119
120 if (!get_info (args["d"], args["c"], metadata, getParents, collectproto, response, logout))
121 return;
122
123 text_tmap options;
124 if (formatinfo.AllowExtendedOptions) {
125 load_extended_options(options, args, browsermap, formatinfo,
126 collectproto, disp, outconvert, logout);
127 }
128 textout << outconvert << disp
129 << get_formatted_string (args["c"],collectproto, response.docInfo[0], disp,
130 formatlistptr, options, logout);
131}
132
133//this function outputs the related documents in the format specified
134//in the collection configuration file if the collection preferences
135//indicate they wish related documents to be displayed.
136void output_related_docs (cgiargsclass &args, recptproto *collectproto,
137 formatinfo_t &formatinfo, displayclass &disp,
138 outconvertclass &outconvert, ostream &textout,
139 ostream &logout) {
140
141 if (args["d"].empty()) return; //if no OID
142 if (args["rd"] != "1") return; //if preferences say no related documents
143
144 text_tset metadata;
145 bool getParents;
146 FilterResponse_t response;
147
148 //create new format pointer and parse the related doc format
149 //string specified in the collection config file
150 format_t *formatlistptr = new format_t();
151 parse_formatstring (formatinfo.RelatedDocuments, formatlistptr, metadata, getParents);
152
153 if (!get_info (args["d"], args["c"], metadata, getParents, collectproto, response, logout))
154 return;
155
156 //get the format string from formattools.cpp
157 text_tmap options; // no options
158 text_t relateddocs = get_formatted_string (args["c"],collectproto, response.docInfo[0],
159 disp, formatlistptr, options, logout);
160 //output the related documents
161 textout << outconvert << disp << relateddocs;
162}
163
164
165
166static void recurse_contents (ResultDocInfo_t &section, cgiargsclass &args, bool fulltoc,
167 browserclass *bptr, text_tset &metadata, bool &getParents,
168 format_t *formatlistptr, format_tmap &formatlistmap,
169 formatinfo_t &formatinfo, browsermapclass *browsermap,
170 int tabcount, recptproto *collectproto, displayclass &disp,
171 outconvertclass &outconvert, ostream &textout, ostream &logout) {
172 text_t formatstring;
173
174 bool is_classify = false;
175 if (args["d"].empty() || fulltoc) is_classify = true;
176
177 // output this section
178 bool use_table = is_table_content (formatlistptr);
179 tabcount += bptr->output_section_group (section, args, args["c"], tabcount, formatlistptr, use_table,
180 metadata, getParents, collectproto, disp, outconvert,
181 textout, logout);
182
183 text_t classification;
184 if (!is_classify) classification = "Document";
185 else get_top (args["cl"], classification);
186
187 int haschildren = section.metadata["haschildren"].values[0].getint();
188 const text_t &doctype = section.metadata["doctype"].values[0];
189 text_t classifytype = section.metadata["childtype"].values[0];
190 // HLists and DateLists are displayed as VLists when contents
191 // are expanded, Paged documents are displayed as HLists
192 if (classifytype == "HList" || classifytype == "DateList") classifytype = "VList";
193 if (classifytype == "Paged") classifytype = "HList";
194
195 // recurse through children
196 if ((haschildren == 1) && (!is_classify || fulltoc || doctype == "classify")) {
197
198 // get browser for displaying children
199 bptr = browsermap->getbrowser (classifytype);
200 bptr->load_metadata_defaults (metadata);
201
202 // get the formatstring if there is one
203 if (!get_formatstring (classification, classifytype,
204 formatinfo.formatstrings, formatstring))
205 formatstring = bptr->get_default_formatstring();
206
207 format_tmap::const_iterator it = formatlistmap.find (formatstring);
208 // check if formatlistptr is cached
209 if (it != formatlistmap.end()) formatlistptr = (*it).second;
210 else {
211 formatlistptr = new format_t();
212 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
213 formatlistmap[formatstring] = formatlistptr;
214 }
215
216 FilterResponse_t tmp;
217 get_children (section.OID, args["c"], metadata, getParents, collectproto, tmp, logout);
218 ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
219 ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
220
221 while (thisdoc != lastdoc) {
222 recurse_contents (*thisdoc, args, fulltoc, bptr, metadata, getParents,
223 formatlistptr, formatlistmap, formatinfo, browsermap,
224 tabcount, collectproto, disp, outconvert, textout, logout);
225 thisdoc ++;
226 }
227 }
228}
229
230
231// expanded_contents recurses through all contents. there's a special case
232// for an HList when contents are expanded (i.e. it's displayed as a VList)
233//
234// if we're inside a document we expand all contents from the top,
235// if we're at classification level we'll just expand out those contents below
236// the current one
237
238void expanded_contents (cgiargsclass &args, int tabcount, bool fulltoc,
239 browsermapclass *browsermap, formatinfo_t &formatinfo,
240 recptproto *collectproto, displayclass &disp,
241 outconvertclass &outconvert, ostream &textout,
242 ostream &logout) {
243
244 if (args["d"].empty() && args["cl"].empty()) return;
245 text_t OID;
246
247 FilterResponse_t response;
248 bool getParents = false;
249 text_tset metadata;
250 text_t classifytype, classification, formatstring;
251
252 if (!args["d"].empty()) {
253 // document level
254 if (fulltoc) {
255 get_top (args["cl"], OID);
256 classification = OID;
257 }
258 else {
259 // always expand document level from top
260 get_top (args["d"], OID);
261 classification = "Document";
262 }
263 } else {
264 // classification level
265 OID = args["cl"];
266 get_top (args["cl"], classification);
267 }
268
269 // get classifytype of this level
270 text_t tOID;
271 if (is_top(OID)) {
272 classifytype = "thistype";
273 tOID = OID;
274 } else {
275 classifytype = "childtype";
276 tOID = get_parent (OID);
277 }
278 metadata.insert (classifytype);
279
280 if (!get_info (tOID, args["c"], metadata, getParents, collectproto, response, logout))
281 return;
282 classifytype = response.docInfo[0].metadata[classifytype].values[0];
283 // if we still don't have a classifytype we'll use the default
284 if (classifytype.empty()) {
285 browserclass *bptr = browsermap->get_default_browser ();
286 classifytype = bptr->get_browser_name ();
287 }
288
289 // HLists are displayed as VLists when contents are expanded,
290 // Paged documents are displayed as HLists
291 if (classifytype == "HList") {
292 classifytype = "VList";
293 text_t pOID = get_parent (OID);
294 if (!pOID.empty()) {
295 OID = pOID;
296 // this is assuming that top levels are always 'Invisible' !!!
297 if (is_top (OID)) classifytype = "Invisible";
298 }
299 }
300 if (classifytype == "Paged") classifytype = "HList";
301
302 metadata.erase (metadata.begin(), metadata.end());
303
304 // metadata elements needed by recurse_contents
305 metadata.insert ("childtype");
306 metadata.insert ("doctype");
307 metadata.insert ("haschildren");
308
309 // load up metadata array with browser defaults
310 browserclass *bptr = browsermap->getbrowser (classifytype);
311 bptr->load_metadata_defaults (metadata);
312
313 // get the formatstring if there is one or use the browsers default
314 if (!get_formatstring (classification, classifytype,
315 formatinfo.formatstrings, formatstring))
316 formatstring = bptr->get_default_formatstring();
317
318 format_t *formatlistptr = new format_t();
319 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
320
321 // protocol call
322 if (!get_info (OID, args["c"], metadata, getParents, collectproto, response, logout))
323 return;
324
325 format_tmap formatlistmap;
326 formatlistmap[formatstring] = formatlistptr;
327
328 recurse_contents (response.docInfo[0], args, fulltoc, bptr, metadata,
329 getParents, formatlistptr, formatlistmap, formatinfo, browsermap,
330 tabcount, collectproto, disp, outconvert, textout, logout);
331
332 // clean up format list pointers
333 format_tmap::const_iterator here = formatlistmap.begin();
334 format_tmap::const_iterator end = formatlistmap.end();
335 while (here != end) {
336 delete (*here).second;
337 here ++;
338 }
339}
340
341
342static void load_formatstring (const text_t &classifytype, text_tset &metadata,
343 bool &getParents, const text_t &classification,
344 browsermapclass *browsermap, formatinfo_t &formatinfo,
345 format_tmap &formatlistmap) {
346 text_t formatstring;
347
348 // load up metadata array with browser defaults
349 browserclass *bptr = browsermap->getbrowser (classifytype);
350 bptr->load_metadata_defaults (metadata);
351
352 // get the formatstring if there is one or use the browsers default
353 if (!get_formatstring (classification, classifytype,
354 formatinfo.formatstrings, formatstring))
355 formatstring = bptr->get_default_formatstring();
356
357 // see if it's cached
358 format_tmap::const_iterator it = formatlistmap.find (formatstring);
359 if (it == formatlistmap.end()) {
360 format_t *formatlistptr = new format_t();
361 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
362 formatlistmap[formatstring] = formatlistptr;
363 }
364}
365
366static void load_formatstrings (FilterResponse_t &response, text_tset &metadata,
367 bool &getParents, const text_t &classification,
368 browsermapclass *browsermap, formatinfo_t &formatinfo,
369 format_tmap &formatlistmap) {
370
371 text_tset cache;
372
373 ResultDocInfo_tarray::iterator thisdoc = response.docInfo.begin();
374 ResultDocInfo_tarray::iterator lastdoc = response.docInfo.end();
375
376 while (thisdoc != lastdoc) {
377
378 if (is_top ((*thisdoc).OID))
379 load_formatstring ((*thisdoc).metadata["thistype"].values[0], metadata,
380 getParents, classification, browsermap, formatinfo,
381 formatlistmap);
382
383 text_t &childtype = (*thisdoc).metadata["childtype"].values[0];
384 text_tset::const_iterator it = cache.find (childtype);
385 if (it == cache.end()) {
386 load_formatstring (childtype, metadata, getParents, classification,
387 browsermap, formatinfo, formatlistmap);
388 cache.insert (childtype);
389 }
390 thisdoc ++;
391 }
392}
393
394static void output_parents (FilterResponse_t &response, cgiargsclass &args,
395 browsermapclass *browsermap, formatinfo_t &formatinfo,
396 format_tmap &formatlistmap, const text_t &classification,
397 int &tabcount, text_tset &metadata, bool &getParents,
398 recptproto *collectproto, displayclass &disp,
399 outconvertclass &outconvert, ostream &textout,
400 ostream &logout) {
401
402 format_t *formatlistptr = NULL;
403 text_t classifytype, formatstring;
404 bool use_table, first = true;
405 ResultDocInfo_tarray::iterator thisparent = response.docInfo.begin();
406 ResultDocInfo_tarray::iterator lastparent = response.docInfo.end();
407 while (thisparent != lastparent) {
408
409 // get classifytype of this level
410 if (is_top ((*thisparent).OID)) classifytype = (*thisparent).metadata["thistype"].values[0];
411 else if (!first) classifytype = (*(thisparent-1)).metadata["childtype"].values[0];
412
413 // if we still don't have a classifytype we'll use the default
414 if (classifytype.empty()) {
415 browserclass *bptr = browsermap->get_default_browser ();
416 classifytype = bptr->get_browser_name ();
417 }
418
419 browserclass *bptr = browsermap->getbrowser (classifytype);
420
421 // get the formatstring if there is one or use the browsers default
422 if (!get_formatstring (classification, classifytype,
423 formatinfo.formatstrings, formatstring))
424 formatstring = bptr->get_default_formatstring();
425
426 // see if it's cached
427 format_tmap::const_iterator it = formatlistmap.find (formatstring);
428 if (it != formatlistmap.end()) formatlistptr = (*it).second;
429 else {
430 logout << "browsetools error\n";
431 return;
432 }
433
434 use_table = is_table_content (formatlistptr);
435 tabcount += bptr->output_section_group (*thisparent, args, "", tabcount, formatlistptr,
436 use_table, metadata, getParents, collectproto,
437 disp, outconvert, textout, logout);
438 first = false;
439 thisparent ++;
440 }
441}
442
443void contracted_contents (cgiargsclass &args, int tabcount, bool fulltoc,
444 browsermapclass *browsermap, formatinfo_t &formatinfo,
445 recptproto *collectproto, displayclass &disp,
446 outconvertclass &outconvert, ostream &textout,
447 ostream &logout) {
448
449 FilterResponse_t response;
450 text_tset metadata;
451 bool getParents = false;
452 text_t formatstring;
453 text_tarray parents;
454 text_t OID = args["d"];
455 text_t classification = "Document";
456
457 // if we're not outputting the TOC for a valid OID, then we should be giving
458 // the TOC of a classification
459 if (OID.empty()) {
460 OID = args["cl"];
461 get_top (OID, classification);
462 }
463 // if we're to give the full TOC of a document, get the parent for the whole
464 // document now
465 else if (fulltoc)
466 get_top (args["cl"], classification);
467
468 bool haschildren = has_children (OID, args["c"], collectproto, logout);
469
470 if ((!args["d"].empty()) && fulltoc)
471 get_parents_array (args["cl"] + ".fc", parents);
472 if (haschildren) get_parents_array (OID + ".fc", parents);
473 else get_parents_array (OID, parents);
474
475 if (!parents.empty()) {
476 // get classifytypes of each parent
477 metadata.insert ("thistype");
478 metadata.insert ("childtype");
479
480 if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
481 return;
482
483 // get formatstrings for all parents
484 format_tmap formatlistmap;
485 load_formatstrings (response, metadata, getParents, classification,
486 browsermap, formatinfo, formatlistmap);
487
488 if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
489 return;
490
491 // display each parent
492 output_parents (response, args, browsermap, formatinfo, formatlistmap,
493 classification, tabcount, metadata, getParents,
494 collectproto, disp, outconvert, textout, logout);
495
496 metadata.erase (metadata.begin(), metadata.end());
497
498 // clean up cached format list pointers
499 format_tmap::const_iterator here = formatlistmap.begin();
500 format_tmap::const_iterator end = formatlistmap.end();
501 while (here != end) {
502 delete (*here).second;
503 here ++;
504 }
505 }
506
507 // get childrens classifytype
508 text_t classifytype;
509 int numparents = response.docInfo.size();
510 if (!parents.empty())
511 classifytype = response.docInfo[numparents-1].metadata["childtype"].values[0];
512 else {
513 // use the default
514 browserclass *bptr = browsermap->get_default_browser ();
515 classifytype = bptr->get_browser_name ();
516 }
517
518 // load up metadata array with browser defaults
519 browserclass *bptr = browsermap->getbrowser (classifytype);
520 bptr->load_metadata_defaults (metadata);
521
522 // get the formatstring if there is one or use the browsers default
523 if (!get_formatstring (classification, classifytype,
524 formatinfo.formatstrings, formatstring))
525 formatstring = bptr->get_default_formatstring();
526
527 format_t *formatlistptr = new format_t();
528 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
529
530 if (haschildren)
531 get_children (OID, args["c"], metadata, getParents,
532 collectproto, response, logout);
533 else if (!is_top(OID)) {
534 get_children (OID + ".pr", args["c"], metadata, getParents,
535 collectproto, response, logout);
536 haschildren = true;
537 }
538
539 // display children
540 if (haschildren) {
541 bool use_table = is_table_content (formatlistptr);
542 bptr->output_section_group (response, args, args["c"], tabcount, formatlistptr, use_table,
543 metadata, getParents, collectproto, disp, outconvert,
544 textout, logout);
545 }
546 delete formatlistptr;
547}
548
549/**
550 * This function outputs contents of a classifier to the reader
551 * including parent levels
552 */
553void expand_show_contents (cgiargsclass &args, int tabcount, bool fulltoc,
554 browsermapclass *browsermap, formatinfo_t &formatinfo,
555 recptproto *collectproto, displayclass &disp,
556 outconvertclass &outconvert, ostream &textout,
557 ostream &logout)
558{
559
560 int coloffset = 0;
561 text_tarray parents;
562 FilterResponse_t response;
563 text_t OID = args["d"];
564 if (OID.empty()) OID = args["cl"];
565
566 bool haschildren = has_children (OID, args["c"], collectproto, logout);
567
568 // get parents list
569 if (!is_top(OID)) get_parents_array (OID, parents);
570 if (args["d"].empty() || haschildren || parents.empty())
571 parents.push_back(OID);
572
573 // if inside a book top title is needed
574 if (!args["d"].empty()) {
575
576 coloffset = 1;
577 text_t classification, classifytype, formatstring, topOID = parents[0];
578 text_tset metadata;
579 format_t *formatlistptr = new format_t();
580 bool use_table, getParents = false;
581
582 get_top (args["cl"], classification);
583
584 // getting information about top OID
585 metadata.insert ("thistype");
586
587 get_info ( topOID, args["c"], metadata, getParents, collectproto, response, logout);
588 if (!response.docInfo[0].metadata["thistype"].values.empty())
589 classifytype = response.docInfo[0].metadata["thistype"].values[0];
590
591 browserclass *bptr = browsermap->getbrowser (classifytype);
592
593 if (classifytype.empty()) {
594 bptr = browsermap->get_default_browser();
595 }
596
597 // get the formatstring if there is one or use the browsers default
598 if (!get_formatstring (classification, classifytype,
599 formatinfo.formatstrings, formatstring))
600 formatstring = bptr->get_default_formatstring();
601
602 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
603
604 metadata.insert ("doctype");
605 metadata.insert ("haschildren");
606
607 get_info (topOID, args["c"], metadata, getParents, collectproto, response, logout);
608
609 // ouput top OID section
610 use_table = is_table_content (formatlistptr);
611 bptr->output_section_group (response.docInfo[0], args, "", tabcount, formatlistptr, use_table,
612 metadata, getParents, collectproto, disp, outconvert, textout, logout);
613
614 }
615
616 recurse_contents_levels (parents, args, coloffset, tabcount, fulltoc, browsermap,
617 formatinfo, collectproto, disp, outconvert, textout, logout);
618
619 textout << outconvert << "</table></td></tr></table>\n";
620}
621
622void recurse_contents_levels (text_tarray &parents,
623 cgiargsclass &args, int coloffset, int tabcount, bool fulltoc,
624 browsermapclass *browsermap, formatinfo_t &formatinfo,
625 recptproto *collectproto, displayclass &disp,
626 outconvertclass &outconvert, ostream &textout,
627 ostream &logout)
628{
629 FilterResponse_t response;
630 text_tset metadata;
631 text_t OID, formatstring, classification, classifytype;;
632 bool use_table, getParents = false;
633 int haschildren = 0;
634 format_t *formatlistptr = new format_t();
635
636 // display children for last level
637 if (tabcount == (parents.size() - 1)) {
638
639 logout << "@@@lastlevel@@@\n";
640 // setting metadata fields
641 metadata.insert ("thistype");
642 metadata.insert ("childtype");
643 metadata.insert ("haschildren");
644
645 OID = parents[tabcount];
646 get_info (OID, args["c"], metadata, getParents, collectproto, response, logout);
647 get_top (OID, classification);
648
649 if (!response.docInfo.empty())
650 haschildren = response.docInfo[0].metadata["haschildren"].values[0].getint();
651
652 // get childrens classifytype
653 if (!response.docInfo.empty())
654 classifytype = response.docInfo[0].metadata["childtype"].values[0];
655 else {
656 // use the default
657 browserclass *bptr = browsermap->get_default_browser ();
658 classifytype = bptr->get_browser_name ();
659 }
660
661 // load up metadata array with browser defaults
662 browserclass *bptr = browsermap->getbrowser (classifytype);
663 bptr->load_metadata_defaults (metadata);
664
665 // get the formatstring if there is one or use the browsers default
666 if (!get_formatstring (classification, classifytype,
667 formatinfo.formatstrings, formatstring))
668 formatstring = bptr->get_default_formatstring();
669
670 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
671
672 if (haschildren)
673 get_children (OID, args["c"], metadata, getParents,
674 collectproto, response, logout);
675 else if (!is_top(OID)) {
676 get_children (OID + ".pr", args["c"], metadata, getParents,
677 collectproto, response, logout);
678 haschildren = true;
679 }
680
681 // display children
682 if (haschildren) {
683 use_table = is_table_content (formatlistptr);
684 bptr->output_section_group (response, args, args["c"], coloffset + tabcount, formatlistptr, use_table,
685 metadata, getParents, collectproto, disp, outconvert,
686 textout, logout);
687 }
688
689 } else {
690
691 text_t pOID;
692 OID = parents[tabcount];
693 get_top (OID, classification);
694
695 // load metadata fields
696 metadata.insert ("thistype");
697 metadata.insert ("childtype");
698 metadata.insert ("haschildren");
699 metadata.insert ("doctype");
700
701 if (tabcount) pOID = parents[tabcount-1];
702 else pOID = OID;
703 get_info (pOID, args["c"], metadata, getParents, collectproto, response, logout);
704
705 // get classifytype of this level
706 if (is_top (pOID)) classifytype = response.docInfo[0].metadata["childtype"].values[0];
707 else classifytype = response.docInfo[0].metadata["thistype"].values[0];
708
709 // if we still don't have a classifytype we'll use the default
710 if (classifytype.empty()) {
711 browserclass *bptr = browsermap->get_default_browser ();
712 classifytype = bptr->get_browser_name ();
713 }
714
715 browserclass *bptr = browsermap->getbrowser (classifytype);
716
717 // get the formatstring if there is one or use the browsers default
718 if (!get_formatstring (classification, classifytype,
719 formatinfo.formatstrings, formatstring))
720 formatstring = bptr->get_default_formatstring();
721
722
723 // parse format string
724 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
725
726 use_table = is_table_content (formatlistptr);
727
728 get_children (OID, args["c"], metadata, getParents, collectproto, response, logout);
729
730 ResultDocInfo_tarray::iterator thissibling = response.docInfo.begin();
731 ResultDocInfo_tarray::iterator lastsibling = response.docInfo.end();
732
733 while (thissibling != lastsibling) {
734
735 logout << "@@@level:@@@" << tabcount << "\n";
736
737 bptr->output_section_group (*thissibling, args, args["c"], coloffset + tabcount, formatlistptr,
738 use_table, metadata, getParents, collectproto,
739 disp, outconvert, textout, logout);
740
741 if ((*thissibling).OID == parents[tabcount+1]) {
742 recurse_contents_levels (parents, args, coloffset, tabcount+1, fulltoc, browsermap,
743 formatinfo, collectproto, disp, outconvert,textout, logout);
744 }
745
746 thissibling ++;
747 }
748 }
749 delete formatlistptr;
750}
751
752/**
753 * This function outputs the contents of a classifier list to the reader -
754 * the document will in fact be empty, so this does the "real" output
755 */
756void output_toc (cgiargsclass &args, browsermapclass *browsermap,
757 formatinfo_t &formatinfo, recptproto *collectproto,
758 displayclass &disp, outconvertclass &outconvert,
759 ostream &textout, ostream &logout) {
760
761 if (!args["d"].empty() && formatinfo.AllowExtendedOptions) {
762 // If AllowExtendedOptions is set and we're viewing a document,
763 // DocumentButtons, DocumentContent, and DocumentImages are effectively
764 // disabled. We just output the DocumentHeading format string and
765 // return
766 output_titles (args, collectproto, browsermap, formatinfo, disp, outconvert, textout, logout);
767 return;
768 }
769
770 int tabcount = 0;
771 bool havecontrols = false;
772 bool fulltoc = false;
773
774 if (args["cl"] != "search") {
775 // see if there's a FullTOC string
776 text_t cl_top, full_toc;
777 get_top (args["cl"], cl_top);
778 if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
779 if (full_toc == "true") fulltoc = true;
780 }
781
782 // get the cover image (if there is one) and the control buttons
783 // if we're inside a book
784 if ((!fulltoc) && (!args["d"].empty())) {
785 textout << outconvert << "<center>\n";
786 textout << outconvert << disp << "<p><table width=_pagewidth_ cellpadding=0 cellspacing=0><tr>\n";
787 textout << outconvert << "<td valign=top align=left";
788 if (formatinfo.DocumentContents) textout << outconvert << " width=200>\n";
789 else textout << outconvert << " width=\"100%\">\n";
790 if (formatinfo.DocumentImages)
791 output_cover_image (args, collectproto, disp, outconvert, textout, logout);
792 else if (formatinfo.DocumentTitles)
793 output_titles (args, collectproto, browsermap, formatinfo, disp, outconvert, textout, logout);
794 if (args["u"] != "1") {
795 output_controls (args, formatinfo.DocumentButtons, collectproto, disp,
796 outconvert, textout, logout);
797 }
798 textout << outconvert << "</td><td valign=\"top\">\n";
799 havecontrols = true;
800 }
801
802 if (formatinfo.DocumentContents || args["d"].empty()) {
803 if (args.getintarg("gc") == 1) {
804
805 // expanded table of contents
806 expanded_contents (args, tabcount, fulltoc, browsermap, formatinfo,
807 collectproto, disp, outconvert, textout, logout);
808 } else if (args.getintarg("gc") == 2) {
809
810 // expand visible levels of table of contents
811 expand_show_contents(args, tabcount, fulltoc, browsermap, formatinfo,
812 collectproto, disp, outconvert, textout, logout);
813 } else {
814
815 // contracted table of contents
816 contracted_contents (args, tabcount, fulltoc, browsermap, formatinfo,
817 collectproto, disp, outconvert, textout, logout);
818 }
819 }
820
821 if (havecontrols) textout << outconvert << "</td></tr></table></center>\n";
822
823 //if there is a format specified in the config file then
824 //try to display the related documents (may not be displayed
825 //if preference file does not indicate a wish to display
826 //related documents.
827 if (!formatinfo.RelatedDocuments.empty())
828 output_related_docs(args, collectproto, formatinfo, disp, outconvert, textout, logout);
829
830}
831
832void load_extended_options(text_tmap &options, cgiargsclass &args, browsermapclass *browsers,
833 formatinfo_t &formatinfo, recptproto *collectproto,
834 displayclass &disp, outconvertclass &outconvert, ostream &logout) {
835
836 options["DocImage"] = get_cover_image();
837
838 ostringstream tmpstr(ostringstream::binary);
839 if (args["gc"] == "1") {
840 expanded_contents (args, 0, false, browsers, formatinfo,
841 collectproto, disp, outconvert, tmpstr,
842 logout);
843 } else {
844 contracted_contents (args, 0, false, browsers, formatinfo,
845 collectproto, disp, outconvert, tmpstr, logout);
846 }
847 text_t tmp = (char *)(tmpstr.str().c_str());
848 int len = tmp.size();
849 char *ctmp = tmp.getcstr();
850 utf8inconvertclass utf82text_t;
851 utf82text_t.setinput(ctmp, len);
852 convertclass::status_t status;
853 utf82text_t.convert(tmp, status);
854 options["DocTOC"] = tmp;
855 delete ctmp;
856
857 options["DocumentButtonDetach"] = "_document:imagedetach_";
858 if (args["hl"] == "1") {
859 options["DocumentButtonHighlight"] = "_document:imagenohighlight_";
860 } else {
861 options["DocumentButtonHighlight"] = "_document:imagehighlight_";
862 }
863 if (args["gc"] == "1") {
864 options["DocumentButtonExpandContents"] = "_document:imagecontracttoc_";
865 } else {
866 options["DocumentButtonExpandContents"] = "_document:imageexpandtoc_";
867 }
868 if (args["gt"] == "1") {
869 options["DocumentButtonExpandText"] = "_document:imagecontracttext_";
870 } else {
871 options["DocumentButtonExpandText"] = "_document:imageexpandtext_";
872 }
873}
Note: See TracBrowser for help on using the repository browser.