source: main/trunk/greenstone2/runtime-src/src/recpt/browsetoolsclass.cpp@ 20999

Last change on this file since 20999 was 16481, checked in by kjdon, 16 years ago

changed the cover image url so that it works in cross collection searching. changed _httpcollimg_ to _httpprefix_/collect/[collection]/index/assoc

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