source: trunk/gsdl/src/recpt/browsetoolsclass.cpp@ 14072

Last change on this file since 14072 was 14072, checked in by mdewsnip, 17 years ago

Moved document cover image non-compliant HTML out of the C++ code and into document.dm. Many thanks to John Thompson from DL Consulting Ltd (www.dlconsulting.com).

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