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

Last change on this file since 7432 was 7432, checked in by mdewsnip, 20 years ago

(Human Info) Added language parameter to all calls of get_info, get_children, has_children, and get_contents. Also, removed some of the modifications so it compiles again.

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