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