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