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 649 1999-10-10 08:14:12Z sjboddie $
|
---|
26 | *
|
---|
27 | *********************************************************************/
|
---|
28 |
|
---|
29 | /*
|
---|
30 | $Log$
|
---|
31 | Revision 1.25 1999/10/10 08:14:04 sjboddie
|
---|
32 | - metadata now returns mp rather than array
|
---|
33 | - redesigned browsing support (although it's not finished so
|
---|
34 | won't currently work ;-)
|
---|
35 |
|
---|
36 | Revision 1.24 1999/09/28 01:46:55 rjmcnab
|
---|
37 | removed some unused stuff
|
---|
38 |
|
---|
39 | Revision 1.23 1999/09/23 10:09:17 sjboddie
|
---|
40 | made some changes so AZLists within other classifications are
|
---|
41 | handled properly
|
---|
42 |
|
---|
43 | Revision 1.22 1999/09/07 23:06:58 rjmcnab
|
---|
44 | removed some compiler warnings.
|
---|
45 |
|
---|
46 | Revision 1.21 1999/09/07 04:56:52 sjboddie
|
---|
47 | added GPL notice
|
---|
48 |
|
---|
49 | Revision 1.20 1999/08/25 04:46:58 sjboddie
|
---|
50 | fixed bug
|
---|
51 |
|
---|
52 | Revision 1.19 1999/08/13 04:18:04 sjboddie
|
---|
53 | fixed some typos
|
---|
54 |
|
---|
55 | Revision 1.18 1999/08/10 22:42:21 sjboddie
|
---|
56 | added more format options to document tocs - there are now just two
|
---|
57 | types of toc - standard (Hierarchical) and document (as in books)
|
---|
58 |
|
---|
59 | Revision 1.17 1999/08/09 02:12:07 sjboddie
|
---|
60 | made it so dates may be only 4 digits (i.e. year only)
|
---|
61 |
|
---|
62 | Revision 1.16 1999/07/30 02:16:10 sjboddie
|
---|
63 | -added ability to display nested classifications (expanded versions
|
---|
64 | of nested classifications has yet to be done).
|
---|
65 | -changed set_arrow_macros slightly to fit in with new showtoppage
|
---|
66 | format option
|
---|
67 |
|
---|
68 | Revision 1.15 1999/07/21 05:01:56 sjboddie
|
---|
69 | wrote handler for DateList classification
|
---|
70 |
|
---|
71 | Revision 1.14 1999/07/20 02:58:15 sjboddie
|
---|
72 | got List and AZList classifications using format strings - tidied
|
---|
73 | up a bit
|
---|
74 |
|
---|
75 | Revision 1.13 1999/07/07 05:44:25 sjboddie
|
---|
76 | Made some changes to allow for new way classifiers work (i.e. you can
|
---|
77 | now have classifiers containing other classifiers). At present there's
|
---|
78 | only a special case for dealing with the hdl 'magazine' section. A bit
|
---|
79 | of a redesign is needed to get it completely flexible
|
---|
80 |
|
---|
81 | Revision 1.12 1999/07/01 03:47:49 rjmcnab
|
---|
82 | Fixed a small warning.
|
---|
83 |
|
---|
84 | Revision 1.11 1999/06/27 21:49:01 sjboddie
|
---|
85 | fixed a couple of version conflicts - tidied up some small things
|
---|
86 |
|
---|
87 | Revision 1.10 1999/06/26 01:07:21 rjmcnab
|
---|
88 | Fixed a small "bug" -- well I probably just covered another one...
|
---|
89 |
|
---|
90 | Revision 1.9 1999/06/24 05:12:15 sjboddie
|
---|
91 | lots of small changes
|
---|
92 |
|
---|
93 | Revision 1.8 1999/06/17 03:06:53 sjboddie
|
---|
94 | got detach button working properly - the close book icon is now disabled
|
---|
95 | when page is detached as the javascript close() function I was using is
|
---|
96 | too unreliable over different browsers
|
---|
97 | note that in my last comment I meant the "cl" arg (not the "c" arg).
|
---|
98 |
|
---|
99 | Revision 1.7 1999/06/16 23:53:14 sjboddie
|
---|
100 | tidied a few things up. documentaction::define_external_macros now
|
---|
101 | resets the "c" arg if it's set to something stupid by the .xx suffixes
|
---|
102 |
|
---|
103 | Revision 1.6 1999/06/16 04:03:47 sjboddie
|
---|
104 | Now sets "cl" arg to "search" when going to a document from a search
|
---|
105 | results page. This allows the close book icon (in hierarchy toc) to
|
---|
106 | take you back to the results page if that's where you came from.
|
---|
107 | If you got to the document page somehow other than from a
|
---|
108 | classification or a search (i.e. if "cl" isn't set) then the close
|
---|
109 | book icon is disabled
|
---|
110 |
|
---|
111 | Revision 1.5 1999/06/16 03:11:25 sjboddie
|
---|
112 | get_info() now takes a getParents argument
|
---|
113 |
|
---|
114 | Revision 1.4 1999/05/10 03:40:26 sjboddie
|
---|
115 | lots of changes - slowly getting document action sorted out
|
---|
116 |
|
---|
117 | Revision 1.3 1999/04/30 01:59:39 sjboddie
|
---|
118 | lots of stuff - getting documentaction working (documentaction replaces
|
---|
119 | old browseaction)
|
---|
120 |
|
---|
121 | Revision 1.2 1999/03/29 02:14:29 sjboddie
|
---|
122 |
|
---|
123 | More changes to browseaction
|
---|
124 |
|
---|
125 | Revision 1.1 1999/03/25 03:10:15 sjboddie
|
---|
126 |
|
---|
127 | new library for browse stuff
|
---|
128 |
|
---|
129 | */
|
---|
130 |
|
---|
131 | #include "browsetools.h"
|
---|
132 | #include "OIDtools.h"
|
---|
133 |
|
---|
134 |
|
---|
135 | // simply checks to see if formatstring begins with a <td> tag
|
---|
136 | static bool is_table_content (const text_t &formatstring) {
|
---|
137 | text_t::const_iterator here = formatstring.begin();
|
---|
138 | text_t::const_iterator end = formatstring.end();
|
---|
139 |
|
---|
140 | while (here != end) {
|
---|
141 | if (*here != ' ') {
|
---|
142 | if (*here == '<') {
|
---|
143 | if ((*(here+1) == 't' || *(here+1) == 'T') &&
|
---|
144 | (*(here+2) == 'd' || *(here+2) == 'D') &&
|
---|
145 | (*(here+3) == '>' || *(here+3) == ' '))
|
---|
146 | return true;
|
---|
147 | } else return false;
|
---|
148 | }
|
---|
149 | here ++;
|
---|
150 | }
|
---|
151 | return false;
|
---|
152 | }
|
---|
153 |
|
---|
154 | static bool is_table_content (const format_t *formatlistptr) {
|
---|
155 |
|
---|
156 | if (formatlistptr == NULL) return false;
|
---|
157 |
|
---|
158 | if (formatlistptr->command == comText)
|
---|
159 | return is_table_content (formatlistptr->text);
|
---|
160 |
|
---|
161 | return false;
|
---|
162 | }
|
---|
163 |
|
---|
164 | // expects haschidren, doctype, and classifytype metadata elements
|
---|
165 | static void recurse_contents (ResultDocInfo_t §ion, cgiargsclass &args,
|
---|
166 | browserclass *bptr, text_tset &metadata, bool &getParents,
|
---|
167 | format_t *formatlistptr, format_tmap &formatlistmap,
|
---|
168 | formatinfo_t &formatinfo, browsermapclass *browsermap,
|
---|
169 | int colnumber, recptproto *collectproto, displayclass &disp,
|
---|
170 | outconvertclass &outconvert, ostream &textout, ostream &logout) {
|
---|
171 | text_t formatstring;
|
---|
172 |
|
---|
173 | bool is_classify = false;
|
---|
174 | if (args["d"].empty()) is_classify = true;
|
---|
175 |
|
---|
176 | // output this section
|
---|
177 | bool use_table = is_table_content (formatlistptr);
|
---|
178 | colnumber += bptr->output_section_group (section, args, colnumber, formatlistptr,
|
---|
179 | use_table, disp, outconvert, textout, logout);
|
---|
180 |
|
---|
181 | text_t classification;
|
---|
182 | if (!is_classify) classification = "Document";
|
---|
183 | else get_top (section.OID, classification);
|
---|
184 |
|
---|
185 | int haschildren = section.metadata["haschildren"].values[0].getint();
|
---|
186 | const text_t &doctype = section.metadata["doctype"].values[0];
|
---|
187 | text_t classifytype = section.metadata["classifytype"].values[0];
|
---|
188 | // HLists are displayed as VLists when contents are expanded,
|
---|
189 | // Books are displayed as HLists
|
---|
190 | if (classifytype == "HList") classifytype = "VList";
|
---|
191 | if (classifytype == "Book") classifytype = "HList";
|
---|
192 |
|
---|
193 | // recurse through children
|
---|
194 | if ((haschildren == 1) && ((!is_classify) || (doctype == "classify"))) {
|
---|
195 |
|
---|
196 | // get browser for displaying children
|
---|
197 | bptr = browsermap->getbrowser (classifytype);
|
---|
198 | bptr->load_metadata_defaults (metadata);
|
---|
199 |
|
---|
200 | // get the formatstring if there is one
|
---|
201 | if (!get_formatstring (classification, classifytype,
|
---|
202 | formatinfo.formatstrings, formatstring))
|
---|
203 | formatstring = bptr->get_default_formatstring();
|
---|
204 |
|
---|
205 | format_tmap::const_iterator it = formatlistmap.find (formatstring);
|
---|
206 | // check if formatlistptr is cached
|
---|
207 | if (it != formatlistmap.end()) formatlistptr = (*it).second;
|
---|
208 | else {
|
---|
209 | formatlistptr = new format_t();
|
---|
210 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
211 | formatlistmap[formatstring] = formatlistptr;
|
---|
212 | }
|
---|
213 |
|
---|
214 | FilterResponse_t tmp;
|
---|
215 | get_children (section.OID, args["c"], metadata, getParents, collectproto, tmp, logout);
|
---|
216 | ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
|
---|
217 | ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
|
---|
218 |
|
---|
219 | while (thisdoc != lastdoc) {
|
---|
220 | recurse_contents (*thisdoc, args, bptr, metadata, getParents,
|
---|
221 | formatlistptr, formatlistmap, formatinfo, browsermap,
|
---|
222 | colnumber, collectproto, disp, outconvert, textout, logout);
|
---|
223 | thisdoc ++;
|
---|
224 | }
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 | // expanded_contents recurses through all contents. there's a special case
|
---|
230 | // for an HList when contents are expanded (i.e. it's displayed as a VList)
|
---|
231 | //
|
---|
232 | // if we're inside a document we expand all contents from the top,
|
---|
233 | // if we're at classification level we'll just expand out those contents below
|
---|
234 | // the current one
|
---|
235 |
|
---|
236 | static void expanded_contents (cgiargsclass &args, browsermapclass *browsermap,
|
---|
237 | formatinfo_t &formatinfo, recptproto *collectproto,
|
---|
238 | displayclass &disp, outconvertclass &outconvert,
|
---|
239 | ostream &textout, ostream &logout) {
|
---|
240 |
|
---|
241 | if (args["d"].empty() && args["cl"].empty()) return;
|
---|
242 | text_t OID;
|
---|
243 |
|
---|
244 | FilterResponse_t response;
|
---|
245 | bool getParents = false;
|
---|
246 | text_tset metadata;
|
---|
247 | text_t classifytype, classification, formatstring;
|
---|
248 | int colnumber = 0;
|
---|
249 |
|
---|
250 | if (!args["d"].empty()) {
|
---|
251 | // document level - expand from top
|
---|
252 | get_top (args["d"], OID);
|
---|
253 | classification = "Document";
|
---|
254 | } else {
|
---|
255 | // classification level
|
---|
256 | OID = args["cl"];
|
---|
257 | get_top (args["cl"], classification);
|
---|
258 | }
|
---|
259 |
|
---|
260 | // get classifytype of this level
|
---|
261 | text_t tOID;
|
---|
262 | if (is_top(OID)) {
|
---|
263 | classifytype = "thistype";
|
---|
264 | tOID = OID;
|
---|
265 | } else {
|
---|
266 | classifytype = "childtype";
|
---|
267 | tOID = get_parent (OID);
|
---|
268 | }
|
---|
269 | metadata.insert (classifytype);
|
---|
270 |
|
---|
271 | if (!get_info (tOID, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
272 | return;
|
---|
273 | classifytype = response.docInfo[0].metadata[classifytype].values[0];
|
---|
274 | // if we still don't have a classifytype we'll use the default
|
---|
275 | if (classifytype.empty()) {
|
---|
276 | browserclass *bptr = browsermap->get_default_browser ();
|
---|
277 | classifytype = bptr->get_browser_name ();
|
---|
278 | }
|
---|
279 |
|
---|
280 | // HLists are displayed as VLists when contents are expanded,
|
---|
281 | // Books are displayed as HLists
|
---|
282 | if (classifytype == "HList") classifytype = "VList";
|
---|
283 | if (classifytype == "Book") classifytype = "HList";
|
---|
284 |
|
---|
285 | metadata.erase (metadata.begin(), metadata.end());
|
---|
286 |
|
---|
287 | // metadata elements needed by recurse_contents
|
---|
288 | metadata.insert ("classifytype");
|
---|
289 | metadata.insert ("doctype");
|
---|
290 | metadata.insert ("haschildren");
|
---|
291 |
|
---|
292 | // load up metadata array with browser defaults
|
---|
293 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
294 | bptr->load_metadata_defaults (metadata);
|
---|
295 |
|
---|
296 | // get the formatstring if there is one or use the browsers default
|
---|
297 | if (!get_formatstring (classification, classifytype,
|
---|
298 | formatinfo.formatstrings, formatstring))
|
---|
299 | formatstring = bptr->get_default_formatstring();
|
---|
300 |
|
---|
301 | format_t *formatlistptr = new format_t();
|
---|
302 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
303 |
|
---|
304 | // protocol call
|
---|
305 | if (!get_info (OID, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
306 | return;
|
---|
307 |
|
---|
308 | format_tmap formatlistmap;
|
---|
309 | formatlistmap[formatstring] = formatlistptr;
|
---|
310 |
|
---|
311 | recurse_contents (response.docInfo[0], args, bptr, metadata,
|
---|
312 | getParents, formatlistptr, formatlistmap, formatinfo, browsermap,
|
---|
313 | colnumber, collectproto, disp, outconvert, textout, logout);
|
---|
314 |
|
---|
315 | // clean up format list pointers
|
---|
316 | format_tmap::const_iterator here = formatlistmap.begin();
|
---|
317 | format_tmap::const_iterator end = formatlistmap.end();
|
---|
318 | while (here != end) {
|
---|
319 | delete (*here).second;
|
---|
320 | here ++;
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | static void load_formatstring (const text_t &classifytype, text_tset &metadata,
|
---|
325 | bool &getParents, const text_t &classification,
|
---|
326 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
327 | format_tmap &formatlistmap) {
|
---|
328 | text_t formatstring;
|
---|
329 |
|
---|
330 | // load up metadata array with browser defaults
|
---|
331 | browserclass *bptr = browsermap->getbrowser (classifytype);
|
---|
332 | bptr->load_metadata_defaults (metadata);
|
---|
333 |
|
---|
334 | // get the formatstring if there is one or use the browsers default
|
---|
335 | if (!get_formatstring (classification, classifytype,
|
---|
336 | formatinfo.formatstrings, formatstring))
|
---|
337 | formatstring = bptr->get_default_formatstring();
|
---|
338 |
|
---|
339 | // see if it's cached
|
---|
340 | format_tmap::const_iterator it = formatlistmap.find (formatstring);
|
---|
341 | if (it == formatlistmap.end()) {
|
---|
342 | format_t *formatlistptr = new format_t();
|
---|
343 | parse_formatstring (formatstring, formatlistptr, metadata, getParents);
|
---|
344 | formatlistmap[formatstring] = formatlistptr;
|
---|
345 | }
|
---|
346 | }
|
---|
347 |
|
---|
348 | static void load_formatstrings (FilterResponse_t &response, text_tset &metadata,
|
---|
349 | bool &getParents, const text_t &classification,
|
---|
350 | browsermapclass *browsermap, formatinfo_t &formatinfo,
|
---|
351 | format_tmap &formatlistmap) {
|
---|
352 |
|
---|
353 | text_tset cache;
|
---|
354 |
|
---|
355 | ResultDocInfo_tarray::iterator thisdoc = response.docInfo.begin();
|
---|
356 | ResultDocInfo_tarray::iterator lastdoc = response.docInfo.end();
|
---|
357 |
|
---|
358 | while (thisdoc != lastdoc) {
|
---|
359 | if (classification != "Document" && is_top ((*thisdoc).OID)) {
|
---|
360 | text_t &thistype = (*thisdoc).metadata["thistype"].values[0];
|
---|
361 | if (!thistype.empty()) load_formatstring (thistype, metadata, getParents, classification,
|
---|
362 | browsermap, formatinfo, formatlistmap);
|
---|
363 | }
|
---|
364 | text_t &childtype = (*thisdoc).metadata["childtype"].values[0];
|
---|
365 | text_tset::const_iterator it = cache.find (childtype);
|
---|
366 | if (it == cache.end()) {
|
---|
367 | if (!childtype.empty()) {
|
---|
368 | load_formatstring (childtype, metadata, getParents, classification,
|
---|
369 | browsermap, formatinfo, formatlistmap);
|
---|
370 | cache.insert (childtype);
|
---|
371 | }
|
---|
372 | }
|
---|
373 | thisdoc ++;
|
---|
374 | }
|
---|
375 | }
|
---|
376 |
|
---|
377 |
|
---|
378 | static void contracted_contents (cgiargsclass &args, browsermapclass *browsermap,
|
---|
379 | formatinfo_t &formatinfo, recptproto *collectproto,
|
---|
380 | displayclass &disp, outconvertclass &outconvert,
|
---|
381 | ostream &textout, ostream &logout) {
|
---|
382 | FilterResponse_t response;
|
---|
383 | text_tset metadata;
|
---|
384 | bool getParents = false;
|
---|
385 | text_tarray parents;
|
---|
386 | text_t OID = args["d"];
|
---|
387 | if (OID.empty()) OID = args["d"];
|
---|
388 | text_t classification = "Document";
|
---|
389 | if (args["d"].empty()) get_top (args["cl"], classification);
|
---|
390 |
|
---|
391 | bool haschildren = has_children (OID, args["c"], collectproto, logout);
|
---|
392 |
|
---|
393 | if (haschildren) get_parents_array (OID + ".fc", parents);
|
---|
394 | else get_parents_array (OID, parents);
|
---|
395 |
|
---|
396 | // get classifytypes of each parent
|
---|
397 | metadata.insert ("thistype");
|
---|
398 | metadata.insert ("childtype");
|
---|
399 | if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
|
---|
400 | return;
|
---|
401 |
|
---|
402 | metadata.erase (metadata.begin(), metadata.end());
|
---|
403 |
|
---|
404 | // get formatstrings for all parents
|
---|
405 | format_tmap formatlistmap;
|
---|
406 | load_formatstrings (response, metadata, getParents, classification,
|
---|
407 | browsermap, formatinfo, formatlistmap);
|
---|
408 |
|
---|
409 | ///////////////////
|
---|
410 |
|
---|
411 | }
|
---|
412 |
|
---|
413 | void output_toc (cgiargsclass &args, browsermapclass *browsermap,
|
---|
414 | formatinfo_t &formatinfo, recptproto *collectproto,
|
---|
415 | displayclass &disp, outconvertclass &outconvert,
|
---|
416 | ostream &textout, ostream &logout) {
|
---|
417 |
|
---|
418 | if (args.getintarg("gc") == 1) {
|
---|
419 |
|
---|
420 | // expanded table of contents
|
---|
421 | expanded_contents (args, browsermap, formatinfo, collectproto,
|
---|
422 | disp, outconvert, textout, logout);
|
---|
423 | } else {
|
---|
424 |
|
---|
425 | // contracted table of contents
|
---|
426 | contracted_contents (args, browsermap, formatinfo, collectproto,
|
---|
427 | disp, outconvert, textout, logout);
|
---|
428 |
|
---|
429 | }
|
---|
430 | }
|
---|