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