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