source: trunk/gsdl/src/recpt/browseaction.cpp@ 207

Last change on this file since 207 was 207, checked in by sjboddie, 25 years ago

subjectbrowseaction became browseaction

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 14.6 KB
Line 
1/**********************************************************************
2 *
3 * browseaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: browseaction.cpp 207 1999-03-25 03:09:41Z sjboddie $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.1 1999/03/25 03:09:40 sjboddie
15
16 subjectbrowseaction became browseaction
17
18
19 */
20
21
22#include "browseaction.h"
23#include "OIDtools.h"
24#include "browsetools.h"
25
26browseaction::browseaction () {
27 // this action uses cgi variables "a", "d", "cl",
28 // "x", and "g"
29 cgiarginfo arg_ainfo;
30 arg_ainfo.shortname = "a";
31 arg_ainfo.longname = "action";
32 arg_ainfo.multiplechar = true;
33 arg_ainfo.defaultstatus = cgiarginfo::weak;
34 arg_ainfo.argdefault = "p";
35 arg_ainfo.savedarginfo = cgiarginfo::must;
36 argsinfo.addarginfo (NULL, arg_ainfo);
37
38 arg_ainfo.shortname = "d";
39 arg_ainfo.longname = "document OID";
40 arg_ainfo.multiplechar = true;
41 arg_ainfo.defaultstatus = cgiarginfo::none;
42 arg_ainfo.argdefault = "";
43 arg_ainfo.savedarginfo = cgiarginfo::can;
44 argsinfo.addarginfo (NULL, arg_ainfo);
45
46 arg_ainfo.shortname = "cl";
47 arg_ainfo.longname = "classification OID";
48 arg_ainfo.multiplechar = true;
49 arg_ainfo.defaultstatus = cgiarginfo::none;
50 arg_ainfo.argdefault = "";
51 arg_ainfo.savedarginfo = cgiarginfo::can;
52 argsinfo.addarginfo (NULL, arg_ainfo);
53
54 // in this action "g" controls the expand/contract
55 // text and expand/contract contents functions
56 // i.e 00 is both contracted 01 is contents contracted,
57 // text expanded etc.
58 arg_ainfo.shortname = "g";
59 arg_ainfo.longname = "browse type";
60 arg_ainfo.multiplechar = true;
61 arg_ainfo.defaultstatus = cgiarginfo::weak;
62 arg_ainfo.argdefault = "00";
63 arg_ainfo.savedarginfo = cgiarginfo::can;
64 argsinfo.addarginfo (NULL, arg_ainfo);
65
66 // "x" is 0 normally or 1 if page
67 // has been "detached"
68 arg_ainfo.shortname = "x";
69 arg_ainfo.longname = "detached page";
70 arg_ainfo.multiplechar = false;
71 arg_ainfo.defaultstatus = cgiarginfo::weak;
72 arg_ainfo.argdefault = "0";
73 arg_ainfo.savedarginfo = cgiarginfo::can;
74 argsinfo.addarginfo (NULL, arg_ainfo);
75}
76
77browseaction::~browseaction () {
78}
79
80bool browseaction::check_cgiargs (cgiargsclass &/*args*/, ostream &/*logout*/) {
81 // don't want to check anything yet.
82 return true;
83}
84
85void browseaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
86 text_t &response_data, ostream &/*logout*/) {
87 response = content;
88 response_data = "text/html";
89}
90
91
92// define all the macros which are related to pages generated
93// by this action
94void browseaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
95 recptproto *collectproto, ostream &logout) {
96
97 text_t ctype, cname, toc;
98 collectproto->get_classification_type (args["cl"], ctype, cname);
99
100 // set the _toc_ macro
101 if (ctype == "hierarchy") get_hierarchy_toc (args, collectproto, toc, logout);
102 else if (ctype == "book") get_book_toc (args, collectproto, toc, logout);
103 else if (ctype == "datelist") get_datelist_toc (args, collectproto, toc, logout);
104 else get_list_toc (args, collectproto, toc, logout); // list is the default
105 disp.setmacro ("toc", cname, toc);
106}
107
108
109bool browseaction::do_action (cgiargsclass &args, recptproto *collectproto,
110 displayclass &disp, outconvertclass &outconvert,
111 ostream &textout, ostream &logout) {
112
113 if (collectproto == NULL) return false;
114
115 text_t ctype, cname;
116 collectproto->get_classification_type (args["cl"], ctype, cname);
117
118 textout << outconvert << disp << ("_" + cname + ":header_\n")
119 << ("_" + cname + ":imagestandardbar_\n") << ("_" + cname + ":content_\n")
120 << ("_" + cname + ":footer_\n");
121
122 return true;
123}
124
125
126
127
128//////////////////////////////////////////////////////////////////////////////////////////////
129// get_top_locator returns (in return_text) the html for the top browsing section
130
131void browseaction::get_top_locator(cgiargsclass &args, recptproto *collectproto,
132 bool oversize, text_t &return_text, ostream &logout) {
133
134 return_text = "\n<!-- top locator produced by browseaction::get_top_locator -->\n\n";
135
136 comerror_t err;
137 MetadataResponse_t resp;
138 MetadataRequest_t req;
139 text_t doclink;
140 text_t &arg_d = args["d"];
141
142 return_text += "<p><table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr>\n";
143
144 if (args["x"] == "1") doclink = "<a href=\"_gwcgi_?e=_compressedoptions_&q=_urlsafequerystring_&x=1";
145 else doclink = "<a href=\"_gwcgi_?e=_compressedoptions_&q=_urlsafequerystring_";
146
147 // get book cover jpeg and detach/expand/collapse buttons
148 if (!arg_d.empty() && !is_top (arg_d)) {
149 text_t top, jpeg_file;
150 get_top(arg_d, top);
151
152 req.OIDs.push_back (top);
153 req.fields.push_back ("Title");
154 req.languages.push_back ("en");
155
156 collectproto->get_metadata (args["c"], req, resp, err, logout);
157 if (err == noError) {
158 text_t jobnum;
159 jobnum = resp.metadata[0];
160 jpeg_file = "_httpcollection_/archives/" + jobnum + "/" + jpeg_file + ".jpg";
161 return_text += "<td valign=top width=200><img src=\"" + jpeg_file + "\"><br>\n";
162 } else {
163 return_text += "Error (" + get_comerror_string (err)
164 + ") while getting metadata\n";
165 }
166
167 if (args["u"] != 1) {
168 // detach button
169 return_text += doclink + "&x=1\" target=\"_pagedest_\" ";
170 return_text += "_imagedetach_";
171 // expand/collapse contents button
172 if (args["g"][0] == '1') {
173 return_text += doclink + "&g=0";
174 return_text.push_back(args["g"][1]);
175 return_text += "_imagecontracttoc_";
176 } else {
177 return_text += doclink + "&g=1";
178 return_text.push_back(args["g"][1]);
179 return_text += "_imageexpandtoc_";
180 }
181 // expand/collapse text buttons
182 if (args["g"][1] == '1') {
183 return_text += doclink + "&g=";
184 return_text.push_back(args["g"][0]);
185 return_text += "_imagecontracttext_";
186 } else {
187 return_text += doclink + "&g=";
188 return_text.push_back(args["g"][0]);
189 return_text += "_imageexpandtext_";
190 }
191 }
192
193 if (oversize) {
194 return_text += "<font color=#FF0000><br>_iconwarning_ this will generate a <br>large amount of\n";
195 return_text += "data <br>\n";
196 return_text += doclink + "&n=1&g=";
197 return_text.push_back(args["g"][0]);
198 return_text += "1\" _imagecont_</font>\n";
199 }
200
201 return_text += "</td>\n";
202
203 } else {
204 // don't want expanded contents at top levels
205 if (args["g"][0] == '1') {
206 text_t t;
207 t.push_back('0');
208 t.push_back(args["g"][1]);
209 args.setarg("g", t);
210 }
211 }
212 return_text += "<td valign=top>\n";
213
214 // get table of contents
215 if (args["g"][0] == '1') {
216 get_expanded_toc(args, collectproto, return_text, logout);
217 } else {
218 get_contracted_toc(args, collectproto, return_text, logout);
219 }
220
221 return_text += "</td></tr></table>\n";
222 return_text += "\n<!-- end of top locator -->\n";
223}
224
225
226void browseaction::get_contracted_toc (cgiargsclass &args, recptproto *collectproto,
227 text_t &return_text, ostream &logout) {
228
229 return_text += "\n<!-- contracted toc produced by browseaction::get_contracted_toc -->\n";
230
231 int colnum, tabcount = 0;
232 text_tarray parents, siblings;
233
234 // load up the parents array
235
236 // don't want classifications unless at top level contents
237 if (!(args["cl"]).empty() && is_top(args["d"]))
238 get_parents_array (args["cl"] + ".", parents);
239 get_parents_array (args["d"], parents);
240
241 // load up siblings array
242 if ((args["d"]).empty()) get_children_array (get_parent(args["cl"]), siblings);
243 else if (is_top (args["d"])) get_children_array (args["cl"], siblings);
244 else get_children_array (get_parent(args["d"]), siblings);
245
246 return_text += "<table>\n";
247 colnum = parents.size() + 1;
248
249 // sort out toc of sections parents
250 if (parents.size() > 0)
251 get_parents_toc(args, parents, tabcount, colnum, return_text);
252
253 // sort out toc of sections siblings
254 if (siblings.size() > 0)
255 get_siblings_toc (args, siblings, tabcount, colnum, return_text);
256
257 return_text += "</table>\n";
258 return_text += "\n<!-- end of contracted toc -->\n";
259}
260
261
262void browseaction::get_expanded_toc (cgiargsclass &args, recptproto *collectproto,
263 text_t &return_text, ostream &logout) {
264
265 return_text += "\n<!-- expanded toc produced by browseaction::get_expanded_toc -->\n";
266 /*
267 text_t doclink, icon, pointer, tab, pagetype;
268 int totalcols, tabcols, tabsleft;
269 text_tarray contents;
270
271 // get array of all contents to be included (all contents of entire book)
272 text_t book_top;
273 get_book_top (booksection, book_top);
274 get_contents (book_top, gdbm, contents, totalcols);
275
276 vector<text_t>::const_iterator section = contents.begin();
277 vector<text_t>::const_iterator end = contents.end();
278
279 int count = 1;
280 while (section != end) {
281 tab.clear();
282 gdbm.getinfo(*section, info);
283 text_t icontabs;
284
285 // set up icon
286 icon = "_iconsmalltext_";
287 if (is_top_level(*section)) icon = "_iconopenbook_";
288 else if (!info.contents.empty()) icon = "_iconopenfolder_";
289
290 // set up pointer
291 if (*section == booksection) pointer = "_iconpointer_";
292 else pointer = "_icontab_";
293
294 // set up tabbing
295 tabcols = count_dots(*section);
296 for (int i = 0; i < (tabcols - 1); i++) {
297 icontabs += "_icontab_";
298 }
299 //char *tabcolsstr;
300 //itoa(tabcols, tabcolsstr, 10);
301 tab = "<td valign=top colspan=" + text_t(tabcols);
302 tab += ">" + icontabs + pointer + "</td>";
303 tabsleft = totalcols - tabcols;
304
305 // set up url
306 if (is_book(*section) && !is_top_level(*section))
307 doclink = "<a href=\"_httptext_";
308 else doclink = "<a href=\"_httpbrowse_";
309 if (args["x"] == "1") doclink += "&x=1";
310
311 return_text += "<tr>" + tab + "<td valign=top>";
312 if (is_top_level(*section) && args["x"] == "1") {
313 return_text += "<a href=\"\" onClick = \"close_detach()";
314 } else {
315 if (args["g"][1] == '0' || is_top_level(*section) ||
316 !are_same_chapter(booksection, *section) ||
317 !info.contents.empty()) {
318 return_text += doclink + "d=" + classification;
319 return_text += "." + *section + "&a=" + pagetype;
320 } else {
321 return_text += "<a href=\"#";
322 return_text += count;
323 count ++;
324 }
325 }
326 return_text += "\">" + icon + "</a></td>";
327 return_text += "<td colspan=" + text_t(tabsleft);
328 return_text += ">" + info.title;
329 return_text += "</td></tr>\n";
330
331 section ++;
332 }
333 return_text += "</table>\n";
334 return_text += "</td></tr></table>\n";
335 */
336 return_text += "\n<!-- end of expanded toc -->\n";
337}
338
339
340void browseaction::get_parents_toc (cgiargsclass &args, const text_tarray &parents,
341 int &tabcount, int &colnum, text_t &return_text) {
342
343 return_text += "\n<!-- parents toc produced by browseaction::get_parents_toc -->\n";
344
345 text_t section, tab, icon, doclink;
346
347 doclink = "<a href=\"_httpbrowse_";
348 if (args["x"] == "1") doclink += "&x=1";
349
350 text_tarray::const_iterator thisparent = parents.begin();
351 text_tarray::const_iterator end = parents.end();
352
353 while (thisparent != end) {
354 text_t icontabs;
355 section.clear();
356 tab.clear();
357
358 // set up icon for this parent
359 icon = "_iconopenfolder_";
360 if (is_classification(*thisparent)) icon = "_iconopenbookshelf_";
361 else if (is_top(*thisparent)) icon = "_iconopenbook_";
362
363 for (int j = 0; j < tabcount; j++)
364 icontabs += "_icontab_";
365
366 if (!icontabs.empty()) {
367 tab = "<td valign=top";
368 if (tabcount > 1) tab += " colspan=" + text_t(tabcount);
369 tab += ">" + icontabs + "</td>";
370 }
371 tabcount ++;
372
373 if (is_top(*thisparent) && args["x"] == "1") {
374 return_text += "<tr>" + tab + "<td valign=top><a href=\"\" ";
375 return_text += "onClick = \"close_detach()\">" + icon + "</a></td>";
376 } else {
377 if (is_classification (*thisparent))
378 return_text += "<tr>" + tab + "<td valign=top>" + doclink + "&cl=" + *thisparent;
379 else
380 // this may not need cl= bit once compressed args is done
381 return_text += "<tr>" + tab + "<td valign=top>" + doclink + "&cl=" + args["cl"] + "&d=" + *thisparent;
382 return_text += "\">" + icon + "</a></td>";
383 }
384 return_text += "<td";
385 if (colnum > 1) return_text += " colspan=" + text_t(colnum);
386 return_text += ">" + *thisparent + " title ";
387 return_text += " by " + *thisparent + " author ";
388 return_text += "</td></tr>\n";
389 colnum --;
390 thisparent ++;
391 }
392
393 return_text += "\n<!-- end of parents toc -->\n";
394}
395
396
397void browseaction::get_siblings_toc (cgiargsclass &args, const text_tarray &siblings,
398 int &tabcount, int &colnum, text_t &return_text) {
399
400 return_text += "\n<!-- siblings toc produced by browseaction::get_siblings_toc -->\n";
401
402 text_t tab, icon, pointer, child, doclink;
403 int count = 1;
404
405 doclink = "<a href=\"_httpbrowse_";
406 if (args["x"] == "1") doclink += "&x=1";
407
408 text_tarray::const_iterator thissibling = siblings.begin();
409 text_tarray::const_iterator sibend = siblings.end();
410
411 while (thissibling != sibend) {
412
413 // set up icon for this sibling
414 icon = "_iconclosedfolder_";
415 if (is_classification(*thissibling)) icon = "_iconclosedbookshelf_";
416 else if (is_top(*thissibling)) icon = "_iconclosedbook_";
417
418 // fit pointer into tabbing if current section
419 pointer = "_icontab_";
420 if (is_classification(*thissibling)) {
421 if (*thissibling == args["cl"])
422 pointer = "_iconpointer_";
423 } else if (*thissibling == args["d"]) pointer = "_iconpointer_";
424
425 text_t thesetabs;
426 for (int j = 0; j < (tabcount - 1); j++)
427 thesetabs += "_icontab_";
428
429 tab = "<td valign=top";
430 if (tabcount > 1) tab += " colspan=" + text_t(tabcount);
431 tab += ">" + thesetabs + pointer + "</td>";
432
433 if (contains_text(*thissibling)) {
434 // sibling is text document
435 icon = "_iconsmalltext_";
436
437 return_text += "<tr>" + tab + "<td valign=top>";
438 if (args["g"][1] == '0') {
439 return_text += doclink + "&d=" + *thissibling;
440 } else {
441 return_text += "<a href=\"#";
442 return_text += count;
443 count ++;
444 }
445 return_text += "\">" + icon + "</a></td><td";
446 if (colnum > 1) return_text += " colspan=" + text_t(colnum);
447 return_text += ">" + *thissibling + " title";
448 return_text += " by " + *thissibling + " author";
449 return_text += "</td></tr>\n";
450 } else {
451 // sibling is closed book or folder so clicking
452 // it should open contents
453 get_first_child(*thissibling, child);
454
455 return_text += "<tr>" + tab + "<td valign=top>" + doclink + "&d=" + child;
456 return_text += "\">" + icon + "</a></td><td";
457 if (colnum > 1) return_text += " colspan=" + text_t(colnum);
458 return_text += ">" + *thissibling + " title";
459 return_text += " by " + *thissibling + " author";
460 return_text += "</td></tr>\n";
461 }
462 thissibling ++;
463 }
464 return_text += "\n<!-- end of siblings toc -->\n";
465}
Note: See TracBrowser for help on using the repository browser.