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

Last change on this file since 21758 was 21758, checked in by kjdon, 13 years ago

now we dynamically generate srclink (and /srclink, and new srchref which is the link without the a tag), using srclink_file metadata. This is to get gs2 receptionist stuff out of metadata and into the source code where it belongs

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