1 |
|
---|
2 | /**********************************************************************
|
---|
3 | *
|
---|
4 | * browsetools.cpp --
|
---|
5 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
6 | *
|
---|
7 | * A component of the Greenstone digital library software
|
---|
8 | * from the New Zealand Digital Library Project at the
|
---|
9 | * University of Waikato, New Zealand.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | *
|
---|
25 | * $Id: browsetools.cpp 878 2000-01-26 23:46:16Z sjboddie $
|
---|
26 | *
|
---|
27 | *********************************************************************/
|
---|
28 |
|
---|
29 | /*
|
---|
30 | $Log$
|
---|
31 | Revision 1.35 2000/01/26 23:46:16 sjboddie
|
---|
32 | wrap every second button now (was every third)
|
---|
33 |
|
---|
34 | Revision 1.34 1999/11/09 02:28:47 sjboddie
|
---|
35 | fixed minor bug in expanded contents
|
---|
36 |
|
---|
37 | Revision 1.33 1999/10/30 22:22:26 sjboddie
|
---|
38 | added collection argument to browserclass output_section_group
|
---|
39 | functions -- moved table functions to formattools
|
---|
40 |
|
---|
41 | Revision 1.32 1999/10/24 07:22:37 sjboddie
|
---|
42 | added a FullTOC option
|
---|
43 |
|
---|
44 | Revision 1.31 1999/10/20 03:54:20 sjboddie
|
---|
45 | problem with expanded contents
|
---|
46 |
|
---|
47 | Revision 1.30 1999/10/19 21:36:59 sjboddie
|
---|
48 | fixed bug in DocumentContents
|
---|
49 |
|
---|
50 | Revision 1.29 1999/10/19 08:40:12 sjboddie
|
---|
51 | fixed some stupid compiler warnings on windows
|
---|
52 |
|
---|
53 | Revision 1.28 1999/10/18 20:08:36 sjboddie
|
---|
54 | tidied up a few things
|
---|
55 |
|
---|
56 | Revision 1.27 1999/10/15 03:31:42 sjboddie
|
---|
57 | oops, left out an '&'
|
---|
58 |
|
---|
59 | Revision 1.26 1999/10/14 22:58:05 sjboddie
|
---|
60 | finished up on changes to browseing support - may still need some
|
---|
61 | tidying up
|
---|
62 |
|
---|
63 | Revision 1.25 1999/10/10 08:14:04 sjboddie
|
---|
64 | - metadata now returns mp rather than array
|
---|
65 | - redesigned browsing support (although it's not finished so
|
---|
66 | won't currently work ;-)
|
---|
67 |
|
---|
68 | Revision 1.24 1999/09/28 01:46:55 rjmcnab
|
---|
69 | removed some unused stuff
|
---|
70 |
|
---|
71 | Revision 1.23 1999/09/23 10:09:17 sjboddie
|
---|
72 | made some changes so AZLists within other classifications are
|
---|
73 | handled properly
|
---|
74 |
|
---|
75 | Revision 1.22 1999/09/07 23:06:58 rjmcnab
|
---|
76 | removed some compiler warnings.
|
---|
77 |
|
---|
78 | Revision 1.21 1999/09/07 04:56:52 sjboddie
|
---|
79 | added GPL notice
|
---|
80 |
|
---|
81 | Revision 1.20 1999/08/25 04:46:58 sjboddie
|
---|
82 | fixed bug
|
---|
83 |
|
---|
84 | Revision 1.19 1999/08/13 04:18:04 sjboddie
|
---|
85 | fixed some typos
|
---|
86 |
|
---|
87 | Revision 1.18 1999/08/10 22:42:21 sjboddie
|
---|
88 | added more format options to document tocs - there are now just two
|
---|
89 | types of toc - standard (Hierarchical) and document (as in books)
|
---|
90 |
|
---|
91 | Revision 1.17 1999/08/09 02:12:07 sjboddie
|
---|
92 | made it so dates may be only 4 digits (i.e. year only)
|
---|
93 |
|
---|
94 | Revision 1.16 1999/07/30 02:16:10 sjboddie
|
---|
95 | -added ability to display nested classifications (expanded versions
|
---|
96 | of nested classifications has yet to be done).
|
---|
97 | -changed set_arrow_macros slightly to fit in with new showtoppage
|
---|
98 | format option
|
---|
99 |
|
---|
100 | Revision 1.15 1999/07/21 05:01:56 sjboddie
|
---|
101 | wrote handler for DateList classification
|
---|
102 |
|
---|
103 | Revision 1.14 1999/07/20 02:58:15 sjboddie
|
---|
104 | got List and AZList classifications using format strings - tidied
|
---|
105 | up a bit
|
---|
106 |
|
---|
107 | Revision 1.13 1999/07/07 05:44:25 sjboddie
|
---|
108 | Made some changes to allow for new way classifiers work (i.e. you can
|
---|
109 | now have classifiers containing other classifiers). At present there's
|
---|
110 | only a special case for dealing with the hdl 'magazine' section. A bit
|
---|
111 | of a redesign is needed to get it completely flexible
|
---|
112 |
|
---|
113 | Revision 1.12 1999/07/01 03:47:49 rjmcnab
|
---|
114 | Fixed a small warning.
|
---|
115 |
|
---|
116 | Revision 1.11 1999/06/27 21:49:01 sjboddie
|
---|
117 | fixed a couple of version conflicts - tidied up some small things
|
---|
118 |
|
---|
119 | Revision 1.10 1999/06/26 01:07:21 rjmcnab
|
---|
120 | Fixed a small "bug" -- well I probably just covered another one...
|
---|
121 |
|
---|
122 | Revision 1.9 1999/06/24 05:12:15 sjboddie
|
---|
123 | lots of small changes
|
---|
124 |
|
---|
125 | Revision 1.8 1999/06/17 03:06:53 sjboddie
|
---|
126 | got detach button working properly - the close book icon is now disabled
|
---|
127 | when page is detached as the javascript close() function I was using is
|
---|
128 | too unreliable over different browsers
|
---|
129 | note that in my last comment I meant the "cl" arg (not the "c" arg).
|
---|
130 |
|
---|
131 | Revision 1.7 1999/06/16 23:53:14 sjboddie
|
---|
132 | tidied a few things up. documentaction::define_external_macros now
|
---|
133 | resets the "c" arg if it's set to something stupid by the .xx suffixes
|
---|
134 |
|
---|
135 | Revision 1.6 1999/06/16 04:03:47 sjboddie
|
---|
136 | Now sets "cl" arg to "search" when going to a document from a search
|
---|
137 | results page. This allows the close book icon (in hierarchy toc) to
|
---|
138 | take you back to the results page if that's where you came from.
|
---|
139 | If you got to the document page somehow other than from a
|
---|
140 | classification or a search (i.e. if "cl" isn't set) then the close
|
---|
141 | book icon is disabled
|
---|
142 |
|
---|
143 | Revision 1.5 1999/06/16 03:11:25 sjboddie
|
---|
144 | get_info() now takes a getParents argument
|
---|
145 |
|
---|
146 | Revision 1.4 1999/05/10 03:40:26 sjboddie
|
---|
147 | lots of changes - slowly getting document action sorted out
|
---|
148 |
|
---|
149 | Revision 1.3 1999/04/30 01:59:39 sjboddie
|
---|
150 | lots of stuff - getting documentaction working (documentaction replaces
|
---|
151 | old browseaction)
|
---|
152 |
|
---|
153 | Revision 1.2 1999/03/29 02:14:29 sjboddie
|
---|
154 |
|
---|
155 | More changes to browseaction
|
---|
156 |
|
---|
157 | Revision 1.1 1999/03/25 03:10:15 sjboddie
|
---|
158 |
|
---|
159 | new library for browse stuff
|
---|
160 |
|
---|
161 | */
|
---|
162 |
|
---|
163 | #include "browsetools.h"
|
---|
164 | #include "OIDtools.h"
|
---|
165 |
|
---|
166 |
|
---|
167 | // output_controls displays the detach, expand/contract contents,
|
---|
168 | // expand/contract text and highlighting/no highlighting buttons
|
---|
169 | static void output_controls (cgiargsclass &args, const text_tarray &ibuttons,
|
---|
170 | recptproto * /*collectproto*/, displayclass &disp,
|
---|
171 | outconvertclass &outconvert, ostream &textout,
|
---|
172 | ostream &/*logout*/) {
|
---|
173 |
|
---|
174 | if (args["u"] != "1") {
|
---|
175 |
|
---|
176 | FilterResponse_t response;
|
---|
177 | text_tarray metadata;
|
---|
178 | text_tarray buttons;
|
---|
179 |
|
---|
180 | text_tarray::const_iterator here = ibuttons.begin();
|
---|
181 | text_tarray::const_iterator end = ibuttons.end();
|
---|
182 |
|
---|
183 | while (here != end) {
|
---|
184 |
|
---|
185 | if (*here == "Detach")
|
---|
186 | buttons.push_back ("_document:imagedetach_");
|
---|
187 | else if (*here == "Highlight") {
|
---|
188 | if (args["hl"] == "1")
|
---|
189 | buttons.push_back ("_document:imagenohighlight_");
|
---|
190 | else
|
---|
191 | buttons.push_back ("_document:imagehighlight_");
|
---|
192 | } else if (*here == "Expand Contents") {
|
---|
193 | if (args["gc"] == "1")
|
---|
194 | buttons.push_back ("_document:imagecontracttoc_");
|
---|
195 | else
|
---|
196 | buttons.push_back ("_document:imageexpandtoc_");
|
---|
197 | } else if (*here == "Expand Text") {
|
---|
198 | if (args.getintarg("gt"))
|
---|
199 | buttons.push_back ("_document:imagecontracttext_");
|
---|
200 | else
|
---|
201 | buttons.push_back ("_document:imageexpandtext_");
|
---|
202 | }
|
---|
203 | here ++;
|
---|
204 | }
|
---|
205 |
|
---|
206 | here = buttons.begin();
|
---|
207 | end = buttons.end();
|
---|
208 | int count = 0;
|
---|
209 | while (here != end) {
|
---|
210 | if ((count != 0) && ((count % 2) == 0)) textout << "<br>\n";
|
---|
211 | textout << outconvert << disp << *here;
|
---|
212 | count ++;
|
---|
213 | here ++;
|
---|
214 | }
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | // at the moment this just writes out the html to display
|
---|
220 | // the cover image (assuming it's called cover.jpg)
|
---|
221 | // this whole thing should be done with a call to the collection
|
---|
222 | // server which would send a link to the cover image if there
|
---|
223 | // was one otherwise send title, author and stuff
|
---|
224 | static void output_cover_image (cgiargsclass &args, recptproto * /*collectproto*/,
|
---|
225 | displayclass &disp, outconvertclass &outconvert,
|
---|
226 | ostream &textout, ostream &/*logout*/) {
|
---|
227 |
|
---|
228 | if (args["d"].empty()) return;
|
---|
229 |
|
---|
230 | textout << outconvert << disp <<
|
---|
231 | "<img src=\"_httpcollection_/archives/_thisOID_/cover.jpg\"><br>\n";
|
---|
232 | }
|
---|
233 |
|
---|
234 | static void output_titles (cgiargsclass &args, recptproto *collectproto,
|
---|
235 | formatinfo_t &formatinfo, displayclass &disp,
|
---|
236 | outconvertclass &outconvert, ostream &textout,
|
---|
237 | ostream &logout) {
|
---|
238 |
|
---|
239 | if (args["d"].empty()) return;
|
---|
240 |
|
---|
241 | text_tset metadata;
|
---|
242 | bool getParents;
|
---|
243 | FilterResponse_t response;
|
---|
244 |
|
---|
245 | format_t *formatlistptr = new format_t();
|
---|
246 | parse_formatstring (formatinfo.DocumentHeading, formatlistptr, metadata, getParents);
|
---|
247 |
|
---|
248 | if (!get_info (args["d"], args["c"], metadata, getParents, collectproto, response, logout))
|
---|
249 | return;
|
---|
250 |
|
---|
251 | textout << outconvert << disp << get_formatted_string (response.docInfo[0], formatlistptr);
|
---|
252 | }
|
---|
253 |
|
---|
254 |
|
---|
255 | static void recurse_contents (ResultDocInfo_t §ion, cgiargsclass &args, bool fulltoc,
|
---|
256 | browserclass *bptr, text_tset &metadata, bool &getParents,
|
---|
257 | format_t *formatlistptr, format_tmap &formatlistmap,
|
---|
258 | formatinfo_t &formatinfo, browsermapclass *browsermap,
|
---|
259 | int tabcount, recptproto *collectproto, displayclass &disp,
|
---|
260 | outconvertclass &outconvert, ostream &textout, ostream &logout) {
|
---|
261 | text_t formatstring;
|
---|
262 |
|
---|
263 | bool is_classify = false;
|
---|
264 | if (args["d"].empty() || fulltoc) is_classify = true;
|
---|
265 |
|
---|
266 | // output this section
|
---|
267 | bool use_table = is_table_content (formatlistptr);
|
---|
268 | tabcount += bptr->output_section_group (section, args, "", tabcount, formatlistptr, use_table,
|
---|
269 | metadata, getParents, collectproto, disp, outconvert,
|
---|
270 | textout, logout);
|
---|
271 |
|
---|
272 | text_t classification;
|
---|
273 | if (!is_classify) classification = "Document";
|
---|
274 | else get_top (args["cl"], classification);
|
---|
275 |
|
---|
276 | int haschildren = section.metadata["haschildren"].values[0].getint();
|
---|
277 | const text_t &doctype = section.metadata["doctype"].values[0];
|
---|
278 | text_t classifytype = section.metadata["childtype"].values[0];
|
---|
279 | // HLists and DateLists are displayed as VLists when contents
|
---|
280 | // are expanded, Paged documents are displayed as HLists
|
---|
281 | if (classifytype == "HList" || classifytype == "DateList") classifytype = "VList";
|
---|
282 | if (classifytype == "Paged") classifytype = "HList";
|
---|
283 |
|
---|
284 | // recurse through children
|
---|
285 | if ((haschildren == 1) && (!is_classify || fulltoc || doctype == "classify")) {
|
---|
286 |
|
---|
287 | // get browser for displaying children
|
---|
288 | bptr = browsermap->getbrowser (classifytype);
|
---|
289 | bptr->load_metadata_defaults (metadata);
|
---|
290 |
|
---|
291 | // get the formatstring if there is one
|
---|
292 | if (!get_formatstring (classification, classifytype,
|
---|
293 | formatinfo.formatstrings, formatstring))
|
---|
294 | formatstring = bptr->get_default_formatstring();
|
---|
295 |
|
---|
296 | format_tmap::const_iterator it = formatlistmap.find (formatstring);
|
---|
297 | // check if formatlistptr is cached
|
---|
298 | if (it != formatlistmap.end()) formatlistptr = (*it).second;
|
---|
299 | else {
|
---|
300 | formatlistptr = new format_t();
|
---|
301 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
302 | formatlistmap[formatstring] = formatlistptr;
|
---|
303 | }
|
---|
304 |
|
---|
305 | FilterResponse_t tmp;
|
---|
306 | get_children (section.OID, args["c"], metadata, getParents, collectproto, tmp, logout);
|
---|
307 | ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
|
---|
308 | ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
|
---|
309 |
|
---|
310 | while (thisdoc != lastdoc) {
|
---|
311 | recurse_contents (*thisdoc, args, fulltoc, bptr, metadata, getParents,
|
---|
312 | formatlistptr, formatlistmap, formatinfo, browsermap,
|
---|
313 | tabcount, collectproto, disp, outconvert, textout, logout);
|
---|
314 | thisdoc ++;
|
---|
315 | }
|
---|
316 | }
|
---|
317 | }
|
---|
318 |
|
---|
319 |
|
---|
320 | // expanded_contents recurses through all contents. there's a special case
|
---|
321 | // for an HList when contents are expanded (i.e. it's displayed as a VList)
|
---|
322 | //
|
---|
323 | // if we're inside a document we expand all contents from the top,
|
---|
324 | // if we're at classification level we'll just expand out those contents below
|
---|
325 | // the current one
|
---|
326 |
|
---|
327 | static void expanded_contents (cgiargsclass &args, int tabcount, bool fulltoc,
|
---|
328 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
329 | recptproto *collectproto, displayclass &disp,
|
---|
330 | outconvertclass &outconvert, ostream &textout,
|
---|
331 | ostream &logout) {
|
---|
332 |
|
---|
333 | if (args["d"].empty() && args["cl"].empty()) return;
|
---|
334 | text_t OID;
|
---|
335 |
|
---|
336 | FilterResponse_t response;
|
---|
337 | bool getParents = false;
|
---|
338 | text_tset metadata;
|
---|
339 | text_t classifytype, classification, formatstring;
|
---|
340 |
|
---|
341 | if (!args["d"].empty()) {
|
---|
342 | // document level
|
---|
343 | if (fulltoc) {
|
---|
344 | get_top (args["cl"], OID);
|
---|
345 | classification = OID;
|
---|
346 | }
|
---|
347 | else {
|
---|
348 | // always expand document level from top
|
---|
349 | get_top (args["d"], OID);
|
---|
350 | classification = "Document";
|
---|
351 | }
|
---|
352 | } else {
|
---|
353 | // classification level
|
---|
354 | OID = args["cl"];
|
---|
355 | get_top (args["cl"], classification);
|
---|
356 | }
|
---|
357 |
|
---|
358 | // get classifytype of this level
|
---|
359 | text_t tOID;
|
---|
360 | if (is_top(OID)) {
|
---|
361 | classifytype = "thistype";
|
---|
362 | tOID = OID;
|
---|
363 | } else {
|
---|
364 | classifytype = "childtype";
|
---|
365 | tOID = get_parent (OID);
|
---|
366 | }
|
---|
367 | metadata.insert (classifytype);
|
---|
368 |
|
---|
369 | if (!get_info (tOID, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
370 | return;
|
---|
371 | classifytype = response.docInfo[0].metadata[classifytype].values[0];
|
---|
372 | // if we still don't have a classifytype we'll use the default
|
---|
373 | if (classifytype.empty()) {
|
---|
374 | browserclass *bptr = browsermap->get_default_browser ();
|
---|
375 | classifytype = bptr->get_browser_name ();
|
---|
376 | }
|
---|
377 |
|
---|
378 | // HLists are displayed as VLists when contents are expanded,
|
---|
379 | // Paged documents are displayed as HLists
|
---|
380 | if (classifytype == "HList") {
|
---|
381 | classifytype = "VList";
|
---|
382 | text_t pOID = get_parent (OID);
|
---|
383 | if (!pOID.empty()) {
|
---|
384 | OID = pOID;
|
---|
385 | // this is assuming that top levels are always 'Invisible' !!!
|
---|
386 | if (is_top (OID)) classifytype = "Invisible";
|
---|
387 | }
|
---|
388 | }
|
---|
389 | if (classifytype == "Paged") classifytype = "HList";
|
---|
390 |
|
---|
391 | metadata.erase (metadata.begin(), metadata.end());
|
---|
392 |
|
---|
393 | // metadata elements needed by recurse_contents
|
---|
394 | metadata.insert ("childtype");
|
---|
395 | metadata.insert ("doctype");
|
---|
396 | metadata.insert ("haschildren");
|
---|
397 |
|
---|
398 | // load up metadata array with browser defaults
|
---|
399 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
400 | bptr->load_metadata_defaults (metadata);
|
---|
401 |
|
---|
402 | // get the formatstring if there is one or use the browsers default
|
---|
403 | if (!get_formatstring (classification, classifytype,
|
---|
404 | formatinfo.formatstrings, formatstring))
|
---|
405 | formatstring = bptr->get_default_formatstring();
|
---|
406 |
|
---|
407 | format_t *formatlistptr = new format_t();
|
---|
408 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
409 |
|
---|
410 | // protocol call
|
---|
411 | if (!get_info (OID, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
412 | return;
|
---|
413 |
|
---|
414 | format_tmap formatlistmap;
|
---|
415 | formatlistmap[formatstring] = formatlistptr;
|
---|
416 |
|
---|
417 | recurse_contents (response.docInfo[0], args, fulltoc, bptr, metadata,
|
---|
418 | getParents, formatlistptr, formatlistmap, formatinfo, browsermap,
|
---|
419 | tabcount, collectproto, disp, outconvert, textout, logout);
|
---|
420 |
|
---|
421 | // clean up format list pointers
|
---|
422 | format_tmap::const_iterator here = formatlistmap.begin();
|
---|
423 | format_tmap::const_iterator end = formatlistmap.end();
|
---|
424 | while (here != end) {
|
---|
425 | delete (*here).second;
|
---|
426 | here ++;
|
---|
427 | }
|
---|
428 | }
|
---|
429 |
|
---|
430 |
|
---|
431 | static void load_formatstring (const text_t &classifytype, text_tset &metadata,
|
---|
432 | bool &getParents, const text_t &classification,
|
---|
433 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
434 | format_tmap &formatlistmap) {
|
---|
435 | text_t formatstring;
|
---|
436 |
|
---|
437 | // load up metadata array with browser defaults
|
---|
438 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
439 | bptr->load_metadata_defaults (metadata);
|
---|
440 |
|
---|
441 | // get the formatstring if there is one or use the browsers default
|
---|
442 | if (!get_formatstring (classification, classifytype,
|
---|
443 | formatinfo.formatstrings, formatstring))
|
---|
444 | formatstring = bptr->get_default_formatstring();
|
---|
445 |
|
---|
446 | // see if it's cached
|
---|
447 | format_tmap::const_iterator it = formatlistmap.find (formatstring);
|
---|
448 | if (it == formatlistmap.end()) {
|
---|
449 | format_t *formatlistptr = new format_t();
|
---|
450 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
451 | formatlistmap[formatstring] = formatlistptr;
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | static void load_formatstrings (FilterResponse_t &response, text_tset &metadata,
|
---|
456 | bool &getParents, const text_t &classification,
|
---|
457 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
458 | format_tmap &formatlistmap) {
|
---|
459 |
|
---|
460 | text_tset cache;
|
---|
461 |
|
---|
462 | ResultDocInfo_tarray::iterator thisdoc = response.docInfo.begin();
|
---|
463 | ResultDocInfo_tarray::iterator lastdoc = response.docInfo.end();
|
---|
464 |
|
---|
465 | while (thisdoc != lastdoc) {
|
---|
466 |
|
---|
467 | if (is_top ((*thisdoc).OID))
|
---|
468 | load_formatstring ((*thisdoc).metadata["thistype"].values[0], metadata,
|
---|
469 | getParents, classification, browsermap, formatinfo,
|
---|
470 | formatlistmap);
|
---|
471 |
|
---|
472 | text_t &childtype = (*thisdoc).metadata["childtype"].values[0];
|
---|
473 | text_tset::const_iterator it = cache.find (childtype);
|
---|
474 | if (it == cache.end()) {
|
---|
475 | load_formatstring (childtype, metadata, getParents, classification,
|
---|
476 | browsermap, formatinfo, formatlistmap);
|
---|
477 | cache.insert (childtype);
|
---|
478 | }
|
---|
479 | thisdoc ++;
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 | static void output_parents (FilterResponse_t &response, cgiargsclass &args,
|
---|
484 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
485 | format_tmap &formatlistmap, const text_t &classification,
|
---|
486 | int &tabcount, text_tset &metadata, bool &getParents,
|
---|
487 | recptproto *collectproto, displayclass &disp,
|
---|
488 | outconvertclass &outconvert, ostream &textout,
|
---|
489 | ostream &logout) {
|
---|
490 |
|
---|
491 | format_t *formatlistptr = NULL;
|
---|
492 | text_t classifytype, formatstring;
|
---|
493 | bool use_table, first = true;
|
---|
494 | ResultDocInfo_tarray::iterator thisparent = response.docInfo.begin();
|
---|
495 | ResultDocInfo_tarray::iterator lastparent = response.docInfo.end();
|
---|
496 | while (thisparent != lastparent) {
|
---|
497 |
|
---|
498 | // get classifytype of this level
|
---|
499 | if (is_top ((*thisparent).OID)) classifytype = (*thisparent).metadata["thistype"].values[0];
|
---|
500 | else if (!first) classifytype = (*(thisparent-1)).metadata["childtype"].values[0];
|
---|
501 |
|
---|
502 | // if we still don't have a classifytype we'll use the default
|
---|
503 | if (classifytype.empty()) {
|
---|
504 | browserclass *bptr = browsermap->get_default_browser ();
|
---|
505 | classifytype = bptr->get_browser_name ();
|
---|
506 | }
|
---|
507 |
|
---|
508 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
509 |
|
---|
510 | // get the formatstring if there is one or use the browsers default
|
---|
511 | if (!get_formatstring (classification, classifytype,
|
---|
512 | formatinfo.formatstrings, formatstring))
|
---|
513 | formatstring = bptr->get_default_formatstring();
|
---|
514 |
|
---|
515 | // see if it's cached
|
---|
516 | format_tmap::const_iterator it = formatlistmap.find (formatstring);
|
---|
517 | if (it != formatlistmap.end()) formatlistptr = (*it).second;
|
---|
518 | else {
|
---|
519 | logout << "browsetools error\n";
|
---|
520 | return;
|
---|
521 | }
|
---|
522 |
|
---|
523 | use_table = is_table_content (formatlistptr);
|
---|
524 | tabcount += bptr->output_section_group (*thisparent, args, "", tabcount, formatlistptr,
|
---|
525 | use_table, metadata, getParents, collectproto,
|
---|
526 | disp, outconvert, textout, logout);
|
---|
527 | first = false;
|
---|
528 | thisparent ++;
|
---|
529 | }
|
---|
530 | }
|
---|
531 |
|
---|
532 |
|
---|
533 | static void contracted_contents (cgiargsclass &args, int tabcount, bool fulltoc,
|
---|
534 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
535 | recptproto *collectproto, displayclass &disp,
|
---|
536 | outconvertclass &outconvert, ostream &textout,
|
---|
537 | ostream &logout) {
|
---|
538 | FilterResponse_t response;
|
---|
539 | text_tset metadata;
|
---|
540 | bool getParents = false;
|
---|
541 | text_t formatstring;
|
---|
542 | text_tarray parents;
|
---|
543 | text_t OID = args["d"];
|
---|
544 | text_t classification = "Document";
|
---|
545 | if (OID.empty()) {
|
---|
546 | OID = args["cl"];
|
---|
547 | get_top (OID, classification);
|
---|
548 | } else if (fulltoc)
|
---|
549 | get_top (args["cl"], classification);
|
---|
550 |
|
---|
551 | bool haschildren = has_children (OID, args["c"], collectproto, logout);
|
---|
552 |
|
---|
553 | if ((!args["d"].empty()) && fulltoc)
|
---|
554 | get_parents_array (args["cl"] + ".fc", parents);
|
---|
555 | if (haschildren) get_parents_array (OID + ".fc", parents);
|
---|
556 | else get_parents_array (OID, parents);
|
---|
557 |
|
---|
558 | if (!parents.empty()) {
|
---|
559 | // get classifytypes of each parent
|
---|
560 | metadata.insert ("thistype");
|
---|
561 | metadata.insert ("childtype");
|
---|
562 |
|
---|
563 | if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
564 | return;
|
---|
565 |
|
---|
566 | // get formatstrings for all parents
|
---|
567 | format_tmap formatlistmap;
|
---|
568 | load_formatstrings (response, metadata, getParents, classification,
|
---|
569 | browsermap, formatinfo, formatlistmap);
|
---|
570 |
|
---|
571 | if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
572 | return;
|
---|
573 |
|
---|
574 | // display each parent
|
---|
575 | output_parents (response, args, browsermap, formatinfo, formatlistmap,
|
---|
576 | classification, tabcount, metadata, getParents,
|
---|
577 | collectproto, disp, outconvert, textout, logout);
|
---|
578 |
|
---|
579 | metadata.erase (metadata.begin(), metadata.end());
|
---|
580 |
|
---|
581 | // clean up cached format list pointers
|
---|
582 | format_tmap::const_iterator here = formatlistmap.begin();
|
---|
583 | format_tmap::const_iterator end = formatlistmap.end();
|
---|
584 | while (here != end) {
|
---|
585 | delete (*here).second;
|
---|
586 | here ++;
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | // get childrens classifytype
|
---|
591 | text_t classifytype;
|
---|
592 | int numparents = response.docInfo.size();
|
---|
593 | if (!parents.empty())
|
---|
594 | classifytype = response.docInfo[numparents-1].metadata["childtype"].values[0];
|
---|
595 | else {
|
---|
596 | // use the default
|
---|
597 | browserclass *bptr = browsermap->get_default_browser ();
|
---|
598 | classifytype = bptr->get_browser_name ();
|
---|
599 | }
|
---|
600 |
|
---|
601 | // load up metadata array with browser defaults
|
---|
602 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
603 | bptr->load_metadata_defaults (metadata);
|
---|
604 |
|
---|
605 | // get the formatstring if there is one or use the browsers default
|
---|
606 | if (!get_formatstring (classification, classifytype,
|
---|
607 | formatinfo.formatstrings, formatstring))
|
---|
608 | formatstring = bptr->get_default_formatstring();
|
---|
609 |
|
---|
610 | format_t *formatlistptr = new format_t();
|
---|
611 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
612 |
|
---|
613 | if (haschildren)
|
---|
614 | get_children (OID, args["c"], metadata, getParents,
|
---|
615 | collectproto, response, logout);
|
---|
616 | else
|
---|
617 | get_children (OID + ".pr", args["c"], metadata, getParents,
|
---|
618 | collectproto, response, logout);
|
---|
619 |
|
---|
620 | // display children
|
---|
621 | bool use_table = is_table_content (formatlistptr);
|
---|
622 | bptr->output_section_group (response, args, "", tabcount, formatlistptr, use_table,
|
---|
623 | metadata, getParents, collectproto, disp, outconvert,
|
---|
624 | textout, logout);
|
---|
625 |
|
---|
626 | delete formatlistptr;
|
---|
627 | }
|
---|
628 |
|
---|
629 | void output_toc (cgiargsclass &args, browsermapclass *browsermap,
|
---|
630 | formatinfo_t &formatinfo, recptproto *collectproto,
|
---|
631 | displayclass &disp, outconvertclass &outconvert,
|
---|
632 | ostream &textout, ostream &logout) {
|
---|
633 |
|
---|
634 | int tabcount = 0;
|
---|
635 | bool havecontrols = false;
|
---|
636 | bool fulltoc = false;
|
---|
637 |
|
---|
638 | if (args["cl"] != "search") {
|
---|
639 | // see if there's a FullTOC string
|
---|
640 | text_t cl_top, full_toc;
|
---|
641 | get_top (args["cl"], cl_top);
|
---|
642 | if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
|
---|
643 | if (full_toc == "true") fulltoc = true;
|
---|
644 | }
|
---|
645 |
|
---|
646 | // get the cover image (if there is one) and the control buttons
|
---|
647 | // if we're inside a book
|
---|
648 | if ((!fulltoc) && (!args["d"].empty())) {
|
---|
649 | textout << "<p><table cellpadding=0 cellspacing=0><tr>\n";
|
---|
650 | textout << "<td valign=top";
|
---|
651 | if (formatinfo.DocumentContents) textout << " width=200>\n";
|
---|
652 | else textout << " width=100%>\n";
|
---|
653 | if (formatinfo.DocumentImages)
|
---|
654 | output_cover_image (args, collectproto, disp, outconvert, textout, logout);
|
---|
655 | else if (formatinfo.DocumentTitles)
|
---|
656 | output_titles (args, collectproto, formatinfo, disp, outconvert, textout, logout);
|
---|
657 | output_controls (args, formatinfo.DocumentButtons, collectproto, disp,
|
---|
658 | outconvert, textout, logout);
|
---|
659 | textout << "</td><td valign=top>\n";
|
---|
660 | havecontrols = true;
|
---|
661 | }
|
---|
662 |
|
---|
663 | if (formatinfo.DocumentContents || args["d"].empty()) {
|
---|
664 | if (args.getintarg("gc") == 1) {
|
---|
665 |
|
---|
666 | // expanded table of contents
|
---|
667 | expanded_contents (args, tabcount, fulltoc, browsermap, formatinfo,
|
---|
668 | collectproto, disp, outconvert, textout, logout);
|
---|
669 | } else {
|
---|
670 |
|
---|
671 | // contracted table of contents
|
---|
672 | contracted_contents (args, tabcount, fulltoc, browsermap, formatinfo,
|
---|
673 | collectproto, disp, outconvert, textout, logout);
|
---|
674 | }
|
---|
675 | }
|
---|
676 |
|
---|
677 | if (havecontrols) textout << "</td></tr></table>\n";
|
---|
678 | }
|
---|