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 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 | #include "browsetools.h"
|
---|
29 | #include "OIDtools.h"
|
---|
30 |
|
---|
31 | // output_controls displays the detach, expand/contract contents,
|
---|
32 | // expand/contract text and highlighting/no highlighting buttons
|
---|
33 |
|
---|
34 | void output_controls (cgiargsclass &args, const text_tarray &ibuttons,
|
---|
35 | recptproto * /*collectproto*/, displayclass &disp,
|
---|
36 | outconvertclass &outconvert, ostream &textout,
|
---|
37 | ostream &/*logout*/) {
|
---|
38 |
|
---|
39 | textout << outconvert << disp
|
---|
40 | << "_document:imagepagepdf_"
|
---|
41 | << "_document:imagearticlepdf_"
|
---|
42 | << "_document:imagedetach_";
|
---|
43 | if (args["hl"] == "1") {
|
---|
44 | textout << outconvert << disp << "_document:imagenohighlight_";
|
---|
45 | } else {
|
---|
46 | textout << outconvert << disp << "_document:imagehighlight_";
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | // at the moment this just writes out the html to display
|
---|
51 | // the cover image (assuming it's called cover.jpg)
|
---|
52 | // this whole thing should be done with a call to the collection
|
---|
53 | // server which would send a link to the cover image if there
|
---|
54 | // was one otherwise send title, author and stuff
|
---|
55 | void output_cover_image (cgiargsclass &args, recptproto * /*collectproto*/,
|
---|
56 | displayclass &disp, outconvertclass &outconvert,
|
---|
57 | ostream &textout, ostream &/*logout*/) {
|
---|
58 |
|
---|
59 | if (args["d"].empty()) return;
|
---|
60 |
|
---|
61 | textout << outconvert << disp <<
|
---|
62 | "<img src=\"_httpcollimg_/_thisOID_/cover.jpg\"><br>\n";
|
---|
63 | }
|
---|
64 |
|
---|
65 | void output_titles (cgiargsclass &args, recptproto *collectproto,
|
---|
66 | formatinfo_t &formatinfo, displayclass &disp,
|
---|
67 | outconvertclass &outconvert, ostream &textout,
|
---|
68 | ostream &logout) {
|
---|
69 |
|
---|
70 | if (args["d"].empty()) return;
|
---|
71 |
|
---|
72 | text_tset metadata;
|
---|
73 | bool getParents;
|
---|
74 | FilterResponse_t response;
|
---|
75 |
|
---|
76 | format_t *formatlistptr = new format_t();
|
---|
77 | parse_formatstring (formatinfo.DocumentHeading, formatlistptr, metadata, getParents);
|
---|
78 |
|
---|
79 | if (!get_info (args["d"], args["c"], metadata, getParents, collectproto, response, logout))
|
---|
80 | return;
|
---|
81 |
|
---|
82 | textout << outconvert << disp
|
---|
83 | << get_formatted_string (args["c"],collectproto,
|
---|
84 | response.docInfo[0], disp, formatlistptr,
|
---|
85 | logout);
|
---|
86 | }
|
---|
87 |
|
---|
88 | //this function outputs the related documents in the format specified
|
---|
89 | //in the collection configuration file if the collection preferences
|
---|
90 | //indicate they wish related documents to be displayed.
|
---|
91 | void output_related_docs (cgiargsclass &args, recptproto *collectproto,
|
---|
92 | formatinfo_t &formatinfo, displayclass &disp,
|
---|
93 | outconvertclass &outconvert, ostream &textout,
|
---|
94 | ostream &logout) {
|
---|
95 |
|
---|
96 | if (args["d"].empty()) return; //if no OID
|
---|
97 | if (args["rd"] != "1") return; //if preferences say no related documents
|
---|
98 |
|
---|
99 | text_tset metadata;
|
---|
100 | bool getParents;
|
---|
101 | FilterResponse_t response;
|
---|
102 |
|
---|
103 | //create new format pointer and parse the related doc format
|
---|
104 | //string specified in the collection config file
|
---|
105 | format_t *formatlistptr = new format_t();
|
---|
106 | parse_formatstring (formatinfo.RelatedDocuments, formatlistptr, metadata, getParents);
|
---|
107 |
|
---|
108 | if (!get_info (args["d"], args["c"], metadata, getParents, collectproto, response, logout))
|
---|
109 | return;
|
---|
110 |
|
---|
111 | //get the format string from formattools.cpp
|
---|
112 | text_t relateddocs = get_formatted_string (args["c"],collectproto, response.docInfo[0],
|
---|
113 | disp, formatlistptr, logout);
|
---|
114 | //output the related documents
|
---|
115 | textout << outconvert << disp << relateddocs;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | static void recurse_contents (ResultDocInfo_t §ion, cgiargsclass &args, bool fulltoc,
|
---|
121 | browserclass *bptr, text_tset &metadata, bool &getParents,
|
---|
122 | format_t *formatlistptr, format_tmap &formatlistmap,
|
---|
123 | formatinfo_t &formatinfo, browsermapclass *browsermap,
|
---|
124 | int tabcount, recptproto *collectproto, displayclass &disp,
|
---|
125 | outconvertclass &outconvert, ostream &textout, ostream &logout) {
|
---|
126 | text_t formatstring;
|
---|
127 |
|
---|
128 | bool is_classify = false;
|
---|
129 | if (args["d"].empty() || fulltoc) is_classify = true;
|
---|
130 |
|
---|
131 | // output this section
|
---|
132 | bool use_table = is_table_content (formatlistptr);
|
---|
133 | tabcount += bptr->output_section_group (section, args, "", tabcount, formatlistptr, use_table,
|
---|
134 | metadata, getParents, collectproto, disp, outconvert,
|
---|
135 | textout, logout);
|
---|
136 |
|
---|
137 | text_t classification;
|
---|
138 | if (!is_classify) classification = "Document";
|
---|
139 | else get_top (args["cl"], classification);
|
---|
140 |
|
---|
141 | int haschildren = section.metadata["haschildren"].values[0].getint();
|
---|
142 | const text_t &doctype = section.metadata["doctype"].values[0];
|
---|
143 | text_t classifytype = section.metadata["childtype"].values[0];
|
---|
144 | // HLists and DateLists are displayed as VLists when contents
|
---|
145 | // are expanded, Paged documents are displayed as HLists
|
---|
146 | if (classifytype == "HList" || classifytype == "DateList") classifytype = "VList";
|
---|
147 | if (classifytype == "Paged") classifytype = "HList";
|
---|
148 |
|
---|
149 | // recurse through children
|
---|
150 | if ((haschildren == 1) && (!is_classify || fulltoc || doctype == "classify")) {
|
---|
151 |
|
---|
152 | // get browser for displaying children
|
---|
153 | bptr = browsermap->getbrowser (classifytype);
|
---|
154 | bptr->load_metadata_defaults (metadata);
|
---|
155 |
|
---|
156 | // get the formatstring if there is one
|
---|
157 | if (!get_formatstring (classification, classifytype,
|
---|
158 | formatinfo.formatstrings, formatstring))
|
---|
159 | formatstring = bptr->get_default_formatstring();
|
---|
160 |
|
---|
161 | format_tmap::const_iterator it = formatlistmap.find (formatstring);
|
---|
162 | // check if formatlistptr is cached
|
---|
163 | if (it != formatlistmap.end()) formatlistptr = (*it).second;
|
---|
164 | else {
|
---|
165 | formatlistptr = new format_t();
|
---|
166 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
167 | formatlistmap[formatstring] = formatlistptr;
|
---|
168 | }
|
---|
169 |
|
---|
170 | FilterResponse_t tmp;
|
---|
171 | get_children (section.OID, args["c"], metadata, getParents, collectproto, tmp, logout);
|
---|
172 | ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
|
---|
173 | ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
|
---|
174 |
|
---|
175 | while (thisdoc != lastdoc) {
|
---|
176 | recurse_contents (*thisdoc, args, fulltoc, bptr, metadata, getParents,
|
---|
177 | formatlistptr, formatlistmap, formatinfo, browsermap,
|
---|
178 | tabcount, collectproto, disp, outconvert, textout, logout);
|
---|
179 | thisdoc ++;
|
---|
180 | }
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | // expanded_contents recurses through all contents. there's a special case
|
---|
186 | // for an HList when contents are expanded (i.e. it's displayed as a VList)
|
---|
187 | //
|
---|
188 | // if we're inside a document we expand all contents from the top,
|
---|
189 | // if we're at classification level we'll just expand out those contents below
|
---|
190 | // the current one
|
---|
191 |
|
---|
192 | void expanded_contents (cgiargsclass &args, int tabcount, bool fulltoc,
|
---|
193 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
194 | recptproto *collectproto, displayclass &disp,
|
---|
195 | outconvertclass &outconvert, ostream &textout,
|
---|
196 | ostream &logout) {
|
---|
197 |
|
---|
198 | if (args["d"].empty() && args["cl"].empty()) return;
|
---|
199 | text_t OID;
|
---|
200 |
|
---|
201 | FilterResponse_t response;
|
---|
202 | bool getParents = false;
|
---|
203 | text_tset metadata;
|
---|
204 | text_t classifytype, classification, formatstring;
|
---|
205 |
|
---|
206 | if (!args["d"].empty()) {
|
---|
207 | // document level
|
---|
208 | if (fulltoc) {
|
---|
209 | get_top (args["cl"], OID);
|
---|
210 | classification = OID;
|
---|
211 | }
|
---|
212 | else {
|
---|
213 | // always expand document level from top
|
---|
214 | get_top (args["d"], OID);
|
---|
215 | classification = "Document";
|
---|
216 | }
|
---|
217 | } else {
|
---|
218 | // classification level
|
---|
219 | OID = args["cl"];
|
---|
220 | get_top (args["cl"], classification);
|
---|
221 | }
|
---|
222 |
|
---|
223 | // get classifytype of this level
|
---|
224 | text_t tOID;
|
---|
225 | if (is_top(OID)) {
|
---|
226 | classifytype = "thistype";
|
---|
227 | tOID = OID;
|
---|
228 | } else {
|
---|
229 | classifytype = "childtype";
|
---|
230 | tOID = get_parent (OID);
|
---|
231 | }
|
---|
232 | metadata.insert (classifytype);
|
---|
233 |
|
---|
234 | if (!get_info (tOID, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
235 | return;
|
---|
236 | classifytype = response.docInfo[0].metadata[classifytype].values[0];
|
---|
237 | // if we still don't have a classifytype we'll use the default
|
---|
238 | if (classifytype.empty()) {
|
---|
239 | browserclass *bptr = browsermap->get_default_browser ();
|
---|
240 | classifytype = bptr->get_browser_name ();
|
---|
241 | }
|
---|
242 |
|
---|
243 | // HLists are displayed as VLists when contents are expanded,
|
---|
244 | // Paged documents are displayed as HLists
|
---|
245 | if (classifytype == "HList") {
|
---|
246 | classifytype = "VList";
|
---|
247 | text_t pOID = get_parent (OID);
|
---|
248 | if (!pOID.empty()) {
|
---|
249 | OID = pOID;
|
---|
250 | // this is assuming that top levels are always 'Invisible' !!!
|
---|
251 | if (is_top (OID)) classifytype = "Invisible";
|
---|
252 | }
|
---|
253 | }
|
---|
254 | if (classifytype == "Paged") classifytype = "HList";
|
---|
255 |
|
---|
256 | metadata.erase (metadata.begin(), metadata.end());
|
---|
257 |
|
---|
258 | // metadata elements needed by recurse_contents
|
---|
259 | metadata.insert ("childtype");
|
---|
260 | metadata.insert ("doctype");
|
---|
261 | metadata.insert ("haschildren");
|
---|
262 |
|
---|
263 | // load up metadata array with browser defaults
|
---|
264 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
265 | bptr->load_metadata_defaults (metadata);
|
---|
266 |
|
---|
267 | // get the formatstring if there is one or use the browsers default
|
---|
268 | if (!get_formatstring (classification, classifytype,
|
---|
269 | formatinfo.formatstrings, formatstring))
|
---|
270 | formatstring = bptr->get_default_formatstring();
|
---|
271 |
|
---|
272 | format_t *formatlistptr = new format_t();
|
---|
273 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
274 |
|
---|
275 | // protocol call
|
---|
276 | if (!get_info (OID, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
277 | return;
|
---|
278 |
|
---|
279 | format_tmap formatlistmap;
|
---|
280 | formatlistmap[formatstring] = formatlistptr;
|
---|
281 |
|
---|
282 | recurse_contents (response.docInfo[0], args, fulltoc, bptr, metadata,
|
---|
283 | getParents, formatlistptr, formatlistmap, formatinfo, browsermap,
|
---|
284 | tabcount, collectproto, disp, outconvert, textout, logout);
|
---|
285 |
|
---|
286 | // clean up format list pointers
|
---|
287 | format_tmap::const_iterator here = formatlistmap.begin();
|
---|
288 | format_tmap::const_iterator end = formatlistmap.end();
|
---|
289 | while (here != end) {
|
---|
290 | delete (*here).second;
|
---|
291 | here ++;
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 |
|
---|
296 | static void load_formatstring (const text_t &classifytype, text_tset &metadata,
|
---|
297 | bool &getParents, const text_t &classification,
|
---|
298 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
299 | format_tmap &formatlistmap) {
|
---|
300 | text_t formatstring;
|
---|
301 |
|
---|
302 | // load up metadata array with browser defaults
|
---|
303 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
304 | bptr->load_metadata_defaults (metadata);
|
---|
305 |
|
---|
306 | // get the formatstring if there is one or use the browsers default
|
---|
307 | if (!get_formatstring (classification, classifytype,
|
---|
308 | formatinfo.formatstrings, formatstring))
|
---|
309 | formatstring = bptr->get_default_formatstring();
|
---|
310 |
|
---|
311 | // see if it's cached
|
---|
312 | format_tmap::const_iterator it = formatlistmap.find (formatstring);
|
---|
313 | if (it == formatlistmap.end()) {
|
---|
314 | format_t *formatlistptr = new format_t();
|
---|
315 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
316 | formatlistmap[formatstring] = formatlistptr;
|
---|
317 | }
|
---|
318 | }
|
---|
319 |
|
---|
320 | static void load_formatstrings (FilterResponse_t &response, text_tset &metadata,
|
---|
321 | bool &getParents, const text_t &classification,
|
---|
322 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
323 | format_tmap &formatlistmap) {
|
---|
324 |
|
---|
325 | text_tset cache;
|
---|
326 |
|
---|
327 | ResultDocInfo_tarray::iterator thisdoc = response.docInfo.begin();
|
---|
328 | ResultDocInfo_tarray::iterator lastdoc = response.docInfo.end();
|
---|
329 |
|
---|
330 | while (thisdoc != lastdoc) {
|
---|
331 |
|
---|
332 | if (is_top ((*thisdoc).OID))
|
---|
333 | load_formatstring ((*thisdoc).metadata["thistype"].values[0], metadata,
|
---|
334 | getParents, classification, browsermap, formatinfo,
|
---|
335 | formatlistmap);
|
---|
336 |
|
---|
337 | text_t &childtype = (*thisdoc).metadata["childtype"].values[0];
|
---|
338 | text_tset::const_iterator it = cache.find (childtype);
|
---|
339 | if (it == cache.end()) {
|
---|
340 | load_formatstring (childtype, metadata, getParents, classification,
|
---|
341 | browsermap, formatinfo, formatlistmap);
|
---|
342 | cache.insert (childtype);
|
---|
343 | }
|
---|
344 | thisdoc ++;
|
---|
345 | }
|
---|
346 | }
|
---|
347 |
|
---|
348 | static void output_parents (FilterResponse_t &response, cgiargsclass &args,
|
---|
349 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
350 | format_tmap &formatlistmap, const text_t &classification,
|
---|
351 | int &tabcount, text_tset &metadata, bool &getParents,
|
---|
352 | recptproto *collectproto, displayclass &disp,
|
---|
353 | outconvertclass &outconvert, ostream &textout,
|
---|
354 | ostream &logout) {
|
---|
355 |
|
---|
356 | format_t *formatlistptr = NULL;
|
---|
357 | text_t classifytype, formatstring;
|
---|
358 | bool use_table, first = true;
|
---|
359 | ResultDocInfo_tarray::iterator thisparent = response.docInfo.begin();
|
---|
360 | ResultDocInfo_tarray::iterator lastparent = response.docInfo.end();
|
---|
361 | while (thisparent != lastparent) {
|
---|
362 |
|
---|
363 | // get classifytype of this level
|
---|
364 | if (is_top ((*thisparent).OID)) classifytype = (*thisparent).metadata["thistype"].values[0];
|
---|
365 | else if (!first) classifytype = (*(thisparent-1)).metadata["childtype"].values[0];
|
---|
366 |
|
---|
367 | // if we still don't have a classifytype we'll use the default
|
---|
368 | if (classifytype.empty()) {
|
---|
369 | browserclass *bptr = browsermap->get_default_browser ();
|
---|
370 | classifytype = bptr->get_browser_name ();
|
---|
371 | }
|
---|
372 |
|
---|
373 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
374 |
|
---|
375 | // get the formatstring if there is one or use the browsers default
|
---|
376 | if (!get_formatstring (classification, classifytype,
|
---|
377 | formatinfo.formatstrings, formatstring))
|
---|
378 | formatstring = bptr->get_default_formatstring();
|
---|
379 |
|
---|
380 | // see if it's cached
|
---|
381 | format_tmap::const_iterator it = formatlistmap.find (formatstring);
|
---|
382 | if (it != formatlistmap.end()) formatlistptr = (*it).second;
|
---|
383 | else {
|
---|
384 | logout << "browsetools error\n";
|
---|
385 | return;
|
---|
386 | }
|
---|
387 |
|
---|
388 | use_table = is_table_content (formatlistptr);
|
---|
389 | tabcount += bptr->output_section_group (*thisparent, args, "", tabcount, formatlistptr,
|
---|
390 | use_table, metadata, getParents, collectproto,
|
---|
391 | disp, outconvert, textout, logout);
|
---|
392 | first = false;
|
---|
393 | thisparent ++;
|
---|
394 | }
|
---|
395 | }
|
---|
396 |
|
---|
397 | void contracted_contents (cgiargsclass &args, int tabcount, bool fulltoc,
|
---|
398 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
399 | recptproto *collectproto, displayclass &disp,
|
---|
400 | outconvertclass &outconvert, ostream &textout,
|
---|
401 | ostream &logout) {
|
---|
402 |
|
---|
403 | FilterResponse_t response;
|
---|
404 | text_tset metadata;
|
---|
405 | bool getParents = false;
|
---|
406 | text_t formatstring;
|
---|
407 | text_tarray parents;
|
---|
408 | text_t OID = args["d"];
|
---|
409 | text_t classification = "Document";
|
---|
410 |
|
---|
411 | // if we're not outputting the TOC for a valid OID, then we should be giving
|
---|
412 | // the TOC of a classification
|
---|
413 | if (OID.empty()) {
|
---|
414 | OID = args["cl"];
|
---|
415 | get_top (OID, classification);
|
---|
416 | }
|
---|
417 | // if we're to give the full TOC of a document, get the parent for the whole
|
---|
418 | // document now
|
---|
419 | else if (fulltoc)
|
---|
420 | get_top (args["cl"], classification);
|
---|
421 |
|
---|
422 | bool haschildren = has_children (OID, args["c"], collectproto, logout);
|
---|
423 |
|
---|
424 | if ((!args["d"].empty()) && fulltoc)
|
---|
425 | get_parents_array (args["cl"] + ".fc", parents);
|
---|
426 | if (haschildren) get_parents_array (OID + ".fc", parents);
|
---|
427 | else get_parents_array (OID, parents);
|
---|
428 |
|
---|
429 | if (!parents.empty()) {
|
---|
430 | // get classifytypes of each parent
|
---|
431 | metadata.insert ("thistype");
|
---|
432 | metadata.insert ("childtype");
|
---|
433 |
|
---|
434 | if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
435 | return;
|
---|
436 |
|
---|
437 | // get formatstrings for all parents
|
---|
438 | format_tmap formatlistmap;
|
---|
439 | load_formatstrings (response, metadata, getParents, classification,
|
---|
440 | browsermap, formatinfo, formatlistmap);
|
---|
441 |
|
---|
442 | if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
443 | return;
|
---|
444 |
|
---|
445 | // display each parent
|
---|
446 | output_parents (response, args, browsermap, formatinfo, formatlistmap,
|
---|
447 | classification, tabcount, metadata, getParents,
|
---|
448 | collectproto, disp, outconvert, textout, logout);
|
---|
449 |
|
---|
450 | metadata.erase (metadata.begin(), metadata.end());
|
---|
451 |
|
---|
452 | // clean up cached format list pointers
|
---|
453 | format_tmap::const_iterator here = formatlistmap.begin();
|
---|
454 | format_tmap::const_iterator end = formatlistmap.end();
|
---|
455 | while (here != end) {
|
---|
456 | delete (*here).second;
|
---|
457 | here ++;
|
---|
458 | }
|
---|
459 | }
|
---|
460 |
|
---|
461 | // get childrens classifytype
|
---|
462 | text_t classifytype;
|
---|
463 | int numparents = response.docInfo.size();
|
---|
464 | if (!parents.empty())
|
---|
465 | classifytype = response.docInfo[numparents-1].metadata["childtype"].values[0];
|
---|
466 | else {
|
---|
467 | // use the default
|
---|
468 | browserclass *bptr = browsermap->get_default_browser ();
|
---|
469 | classifytype = bptr->get_browser_name ();
|
---|
470 | }
|
---|
471 |
|
---|
472 | // load up metadata array with browser defaults
|
---|
473 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
474 | bptr->load_metadata_defaults (metadata);
|
---|
475 |
|
---|
476 | // get the formatstring if there is one or use the browsers default
|
---|
477 | if (!get_formatstring (classification, classifytype,
|
---|
478 | formatinfo.formatstrings, formatstring))
|
---|
479 | formatstring = bptr->get_default_formatstring();
|
---|
480 |
|
---|
481 | format_t *formatlistptr = new format_t();
|
---|
482 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
483 |
|
---|
484 | if (haschildren)
|
---|
485 | get_children (OID, args["c"], metadata, getParents,
|
---|
486 | collectproto, response, logout);
|
---|
487 | else if (!is_top(OID)) {
|
---|
488 | get_children (OID + ".pr", args["c"], metadata, getParents,
|
---|
489 | collectproto, response, logout);
|
---|
490 | haschildren = true;
|
---|
491 | }
|
---|
492 |
|
---|
493 | // display children
|
---|
494 | if (haschildren) {
|
---|
495 | bool use_table = is_table_content (formatlistptr);
|
---|
496 | // collection used to be "" // **** // check with Stef!!!!
|
---|
497 | bptr->output_section_group (response, args, args["c"], tabcount, formatlistptr, use_table,
|
---|
498 | metadata, getParents, collectproto, disp, outconvert,
|
---|
499 | textout, logout);
|
---|
500 | }
|
---|
501 | delete formatlistptr;
|
---|
502 | }
|
---|
503 |
|
---|
504 | /**
|
---|
505 | * This function outputs contents of a classifier to the reader
|
---|
506 | * including parent levels
|
---|
507 | */
|
---|
508 | void expand_show_contents (cgiargsclass &args, int tabcount, bool fulltoc,
|
---|
509 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
510 | recptproto *collectproto, displayclass &disp,
|
---|
511 | outconvertclass &outconvert, ostream &textout,
|
---|
512 | ostream &logout)
|
---|
513 | {
|
---|
514 |
|
---|
515 | int coloffset = 0;
|
---|
516 | text_tarray parents;
|
---|
517 | FilterResponse_t response;
|
---|
518 | text_t OID = args["d"];
|
---|
519 | if (OID.empty()) OID = args["cl"];
|
---|
520 |
|
---|
521 | bool haschildren = has_children (OID, args["c"], collectproto, logout);
|
---|
522 |
|
---|
523 | // get parents list
|
---|
524 | if (!is_top(OID)) get_parents_array (OID, parents);
|
---|
525 | if (args["d"].empty() || haschildren || parents.empty())
|
---|
526 | parents.push_back(OID);
|
---|
527 |
|
---|
528 | // if inside a book top title is needed
|
---|
529 | if (!args["d"].empty()) {
|
---|
530 |
|
---|
531 | coloffset = 1;
|
---|
532 | text_t classification, classifytype, formatstring, topOID = parents[0];
|
---|
533 | text_tset metadata;
|
---|
534 | format_t *formatlistptr = new format_t();
|
---|
535 | bool use_table, getParents = false;
|
---|
536 |
|
---|
537 | get_top (args["cl"], classification);
|
---|
538 |
|
---|
539 | // getting information about top OID
|
---|
540 | metadata.insert ("thistype");
|
---|
541 |
|
---|
542 | get_info ( topOID, args["c"], metadata, getParents, collectproto, response, logout);
|
---|
543 | if (!response.docInfo[0].metadata["thistype"].values.empty())
|
---|
544 | classifytype = response.docInfo[0].metadata["thistype"].values[0];
|
---|
545 |
|
---|
546 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
547 |
|
---|
548 | if (classifytype.empty()) {
|
---|
549 | bptr = browsermap->get_default_browser();
|
---|
550 | }
|
---|
551 |
|
---|
552 | // get the formatstring if there is one or use the browsers default
|
---|
553 | if (!get_formatstring (classification, classifytype,
|
---|
554 | formatinfo.formatstrings, formatstring))
|
---|
555 | formatstring = bptr->get_default_formatstring();
|
---|
556 |
|
---|
557 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
558 |
|
---|
559 | metadata.insert ("doctype");
|
---|
560 | metadata.insert ("haschildren");
|
---|
561 |
|
---|
562 | get_info (topOID, args["c"], metadata, getParents, collectproto, response, logout);
|
---|
563 |
|
---|
564 | // ouput top OID section
|
---|
565 | use_table = is_table_content (formatlistptr);
|
---|
566 | bptr->output_section_group (response.docInfo[0], args, "", tabcount, formatlistptr, use_table,
|
---|
567 | metadata, getParents, collectproto, disp, outconvert, textout, logout);
|
---|
568 |
|
---|
569 | }
|
---|
570 |
|
---|
571 | recurse_contents_levels (parents, args, coloffset, tabcount, fulltoc, browsermap,
|
---|
572 | formatinfo, collectproto, disp, outconvert, textout, logout);
|
---|
573 |
|
---|
574 | textout << "</table></td></tr></table>\n";
|
---|
575 | }
|
---|
576 |
|
---|
577 | void recurse_contents_levels (text_tarray &parents,
|
---|
578 | cgiargsclass &args, int coloffset, int tabcount, bool fulltoc,
|
---|
579 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
580 | recptproto *collectproto, displayclass &disp,
|
---|
581 | outconvertclass &outconvert, ostream &textout,
|
---|
582 | ostream &logout)
|
---|
583 | {
|
---|
584 | FilterResponse_t response;
|
---|
585 | text_tset metadata;
|
---|
586 | text_t OID, formatstring, classification, classifytype;;
|
---|
587 | bool use_table, getParents = false;
|
---|
588 | int haschildren = 0;
|
---|
589 | format_t *formatlistptr = new format_t();
|
---|
590 |
|
---|
591 | // display children for last level
|
---|
592 | if (tabcount == (parents.size() - 1)) {
|
---|
593 |
|
---|
594 | logout << "@@@lastlevel@@@\n";
|
---|
595 | // setting metadata fields
|
---|
596 | metadata.insert ("thistype");
|
---|
597 | metadata.insert ("childtype");
|
---|
598 | metadata.insert ("haschildren");
|
---|
599 |
|
---|
600 | OID = parents[tabcount];
|
---|
601 | get_info (OID, args["c"], metadata, getParents, collectproto, response, logout);
|
---|
602 | get_top (OID, classification);
|
---|
603 |
|
---|
604 | if (!response.docInfo.empty())
|
---|
605 | haschildren = response.docInfo[0].metadata["haschildren"].values[0].getint();
|
---|
606 |
|
---|
607 | // get childrens classifytype
|
---|
608 | if (!response.docInfo.empty())
|
---|
609 | classifytype = response.docInfo[0].metadata["childtype"].values[0];
|
---|
610 | else {
|
---|
611 | // use the default
|
---|
612 | browserclass *bptr = browsermap->get_default_browser ();
|
---|
613 | classifytype = bptr->get_browser_name ();
|
---|
614 | }
|
---|
615 |
|
---|
616 | // load up metadata array with browser defaults
|
---|
617 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
618 | bptr->load_metadata_defaults (metadata);
|
---|
619 |
|
---|
620 | // get the formatstring if there is one or use the browsers default
|
---|
621 | if (!get_formatstring (classification, classifytype,
|
---|
622 | formatinfo.formatstrings, formatstring))
|
---|
623 | formatstring = bptr->get_default_formatstring();
|
---|
624 |
|
---|
625 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
626 |
|
---|
627 | if (haschildren)
|
---|
628 | get_children (OID, args["c"], metadata, getParents,
|
---|
629 | collectproto, response, logout);
|
---|
630 | else if (!is_top(OID)) {
|
---|
631 | get_children (OID + ".pr", args["c"], metadata, getParents,
|
---|
632 | collectproto, response, logout);
|
---|
633 | haschildren = true;
|
---|
634 | }
|
---|
635 |
|
---|
636 | // display children
|
---|
637 | if (haschildren) {
|
---|
638 | use_table = is_table_content (formatlistptr);
|
---|
639 | bptr->output_section_group (response, args, args["c"], coloffset + tabcount, formatlistptr, use_table,
|
---|
640 | metadata, getParents, collectproto, disp, outconvert,
|
---|
641 | textout, logout);
|
---|
642 | }
|
---|
643 |
|
---|
644 | } else {
|
---|
645 |
|
---|
646 | text_t pOID;
|
---|
647 | OID = parents[tabcount];
|
---|
648 | get_top (OID, classification);
|
---|
649 |
|
---|
650 | // load metadata fields
|
---|
651 | metadata.insert ("thistype");
|
---|
652 | metadata.insert ("childtype");
|
---|
653 | metadata.insert ("haschildren");
|
---|
654 | metadata.insert ("doctype");
|
---|
655 |
|
---|
656 | if (tabcount) pOID = parents[tabcount-1];
|
---|
657 | else pOID = OID;
|
---|
658 | get_info (pOID, args["c"], metadata, getParents, collectproto, response, logout);
|
---|
659 |
|
---|
660 | // get classifytype of this level
|
---|
661 | if (is_top (pOID)) classifytype = response.docInfo[0].metadata["childtype"].values[0];
|
---|
662 | else classifytype = response.docInfo[0].metadata["thistype"].values[0];
|
---|
663 |
|
---|
664 | // if we still don't have a classifytype we'll use the default
|
---|
665 | if (classifytype.empty()) {
|
---|
666 | browserclass *bptr = browsermap->get_default_browser ();
|
---|
667 | classifytype = bptr->get_browser_name ();
|
---|
668 | }
|
---|
669 |
|
---|
670 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
671 |
|
---|
672 | // get the formatstring if there is one or use the browsers default
|
---|
673 | if (!get_formatstring (classification, classifytype,
|
---|
674 | formatinfo.formatstrings, formatstring))
|
---|
675 | formatstring = bptr->get_default_formatstring();
|
---|
676 |
|
---|
677 |
|
---|
678 | // parse format string
|
---|
679 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
680 |
|
---|
681 | use_table = is_table_content (formatlistptr);
|
---|
682 |
|
---|
683 | get_children (OID, args["c"], metadata, getParents, collectproto, response, logout);
|
---|
684 |
|
---|
685 | ResultDocInfo_tarray::iterator thissibling = response.docInfo.begin();
|
---|
686 | ResultDocInfo_tarray::iterator lastsibling = response.docInfo.end();
|
---|
687 |
|
---|
688 | while (thissibling != lastsibling) {
|
---|
689 |
|
---|
690 | logout << "@@@level:@@@" << tabcount << "\n";
|
---|
691 |
|
---|
692 | bptr->output_section_group (*thissibling, args, args["c"], coloffset + tabcount, formatlistptr,
|
---|
693 | use_table, metadata, getParents, collectproto,
|
---|
694 | disp, outconvert, textout, logout);
|
---|
695 |
|
---|
696 | if ((*thissibling).OID == parents[tabcount+1]) {
|
---|
697 | recurse_contents_levels (parents, args, coloffset, tabcount+1, fulltoc, browsermap,
|
---|
698 | formatinfo, collectproto, disp, outconvert,textout, logout);
|
---|
699 | }
|
---|
700 |
|
---|
701 | thissibling ++;
|
---|
702 | }
|
---|
703 | }
|
---|
704 | delete formatlistptr;
|
---|
705 | }
|
---|
706 |
|
---|
707 | /**
|
---|
708 | * This function outputs the contents of a classifier list to the reader -
|
---|
709 | * the document will in fact be empty, so this does the "real" output
|
---|
710 | */
|
---|
711 | void output_toc (cgiargsclass &args, browsermapclass *browsermap,
|
---|
712 | formatinfo_t &formatinfo, recptproto *collectproto,
|
---|
713 | displayclass &disp, outconvertclass &outconvert,
|
---|
714 | ostream &textout, ostream &logout) {
|
---|
715 |
|
---|
716 | int tabcount = 0;
|
---|
717 | bool havecontrols = false;
|
---|
718 | bool fulltoc = false;
|
---|
719 |
|
---|
720 | if (args["cl"] != "search") {
|
---|
721 | // see if there's a FullTOC string
|
---|
722 | text_t cl_top, full_toc;
|
---|
723 | get_top (args["cl"], cl_top);
|
---|
724 | if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
|
---|
725 | if (full_toc == "true") fulltoc = true;
|
---|
726 | }
|
---|
727 |
|
---|
728 | // get the cover image (if there is one) and the control buttons
|
---|
729 | // if we're inside a book
|
---|
730 | if ((!fulltoc) && (!args["d"].empty())) {
|
---|
731 | textout << "<center>\n";
|
---|
732 | textout << outconvert << disp
|
---|
733 | << "<p><table width=\"_pagewidth_\" cellpadding=\"0\" cellspacing=\"0\">\n"
|
---|
734 | << "<tr valign=\"top\">\n"
|
---|
735 | << "<td>\n";
|
---|
736 | output_titles (args, collectproto, formatinfo, disp, outconvert, textout, logout);
|
---|
737 | textout << "</td></tr>\n"
|
---|
738 | << "<tr><td>\n";
|
---|
739 | havecontrols = true;
|
---|
740 | }
|
---|
741 |
|
---|
742 | if (formatinfo.DocumentContents || args["d"].empty()) {
|
---|
743 | if (args.getintarg("gc") == 1) {
|
---|
744 |
|
---|
745 | // expanded table of contents
|
---|
746 | expanded_contents (args, tabcount, fulltoc, browsermap, formatinfo,
|
---|
747 | collectproto, disp, outconvert, textout, logout);
|
---|
748 | } else if (args.getintarg("gc") == 2) {
|
---|
749 |
|
---|
750 | // expand visible levels of table of contents
|
---|
751 | expand_show_contents(args, tabcount, fulltoc, browsermap, formatinfo,
|
---|
752 | collectproto, disp, outconvert, textout, logout);
|
---|
753 | } else {
|
---|
754 |
|
---|
755 | // contracted table of contents
|
---|
756 | contracted_contents (args, tabcount, fulltoc, browsermap, formatinfo,
|
---|
757 | collectproto, disp, outconvert, textout, logout);
|
---|
758 | }
|
---|
759 | }
|
---|
760 |
|
---|
761 | if (havecontrols) {
|
---|
762 | textout << "</td></tr>\n"
|
---|
763 | << "<tr><td>\n";
|
---|
764 | output_controls (args, formatinfo.DocumentButtons, collectproto, disp,
|
---|
765 | outconvert, textout, logout);
|
---|
766 | textout << "</td></tr></table></center>\n";
|
---|
767 | }
|
---|
768 | }
|
---|
769 |
|
---|