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

Last change on this file since 28912 was 28912, checked in by ak19, 10 years ago

Commit 5 for security. Handles setmacro() occurrences in non action.cpp files. cl is safe from hacks now.

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