1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * documentaction.cpp --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | *********************************************************************/
|
---|
25 |
|
---|
26 | #include <string.h>
|
---|
27 |
|
---|
28 | #include "documentaction.h"
|
---|
29 | #include "OIDtools.h"
|
---|
30 | #include "querytools.h"
|
---|
31 | #include "unitool.h"
|
---|
32 | #include "gsdltools.h"
|
---|
33 | #include "highlighttext.h"
|
---|
34 | #include "browsetoolsclass.h"
|
---|
35 |
|
---|
36 | documentaction::documentaction () {
|
---|
37 | recpt = NULL;
|
---|
38 |
|
---|
39 | // this action uses cgi variables "a", "d", "cl",
|
---|
40 | // "x", "gc", "gt", "gp", and "hl"
|
---|
41 | cgiarginfo arg_ainfo;
|
---|
42 | arg_ainfo.shortname = "a";
|
---|
43 | arg_ainfo.longname = "action";
|
---|
44 | arg_ainfo.multiplechar = true;
|
---|
45 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
46 | arg_ainfo.argdefault = "p";
|
---|
47 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
48 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
49 |
|
---|
50 | arg_ainfo.shortname = "d";
|
---|
51 | arg_ainfo.longname = "document OID";
|
---|
52 | arg_ainfo.multiplechar = true;
|
---|
53 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
54 | arg_ainfo.argdefault = g_EmptyText;
|
---|
55 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
56 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
57 |
|
---|
58 | // whether or not a document should be retrieved from the
|
---|
59 | // library or the Web.
|
---|
60 | arg_ainfo.shortname = "il";
|
---|
61 | arg_ainfo.longname = "internal link preference";
|
---|
62 | arg_ainfo.multiplechar = false;
|
---|
63 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
64 | arg_ainfo.argdefault = "l";
|
---|
65 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
66 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
67 |
|
---|
68 | arg_ainfo.shortname = "cl";
|
---|
69 | arg_ainfo.longname = "classification OID";
|
---|
70 | arg_ainfo.multiplechar = true;
|
---|
71 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
72 | arg_ainfo.argdefault = g_EmptyText;
|
---|
73 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
74 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
75 |
|
---|
76 | // in this action "gc" controls the expand/contract
|
---|
77 | // contents function
|
---|
78 | arg_ainfo.shortname = "gc";
|
---|
79 | arg_ainfo.longname = "expand contents";
|
---|
80 | arg_ainfo.multiplechar = false;
|
---|
81 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
82 | arg_ainfo.argdefault = "0";
|
---|
83 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
84 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
85 |
|
---|
86 | // in this action "gt" controls the expand/contract
|
---|
87 | // text function 0 = not expanded, 1 = expand unless
|
---|
88 | // there are more than 10 sections containing text,
|
---|
89 | // 2 = expand all
|
---|
90 | arg_ainfo.shortname = "gt";
|
---|
91 | arg_ainfo.longname = "expand text";
|
---|
92 | arg_ainfo.multiplechar = false;
|
---|
93 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
94 | arg_ainfo.argdefault = "0";
|
---|
95 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
96 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
97 |
|
---|
98 | // in this action "gp" is the "go to page" control
|
---|
99 | // used by the Book type of toc
|
---|
100 | arg_ainfo.shortname = "gp";
|
---|
101 | arg_ainfo.longname = "go to page";
|
---|
102 | arg_ainfo.multiplechar = true;
|
---|
103 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
104 | arg_ainfo.argdefault = g_EmptyText;
|
---|
105 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
106 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
107 |
|
---|
108 | // in this action "hl" is the "highlighting on/
|
---|
109 | // highlighting off control ("hl" == "2" is a
|
---|
110 | // special case that forces phrase highlighting
|
---|
111 | // to be used even if the query string doesn't
|
---|
112 | // appear to be a phrase)
|
---|
113 | arg_ainfo.shortname = "hl";
|
---|
114 | arg_ainfo.longname = "highlighting on/off";
|
---|
115 | arg_ainfo.multiplechar = false;
|
---|
116 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
117 | arg_ainfo.argdefault = "1";
|
---|
118 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
119 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
120 |
|
---|
121 | // "x" is 0 normally or 1 if page
|
---|
122 | // has been "detached"
|
---|
123 | arg_ainfo.shortname = "x";
|
---|
124 | arg_ainfo.longname = "detached page";
|
---|
125 | arg_ainfo.multiplechar = false;
|
---|
126 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
127 | arg_ainfo.argdefault = "0";
|
---|
128 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
129 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
130 |
|
---|
131 | // "xx" is 0 normally or 1 if documents should be detached by default
|
---|
132 | arg_ainfo.shortname = "xx";
|
---|
133 | arg_ainfo.longname = "detach all doc pages";
|
---|
134 | arg_ainfo.multiplechar = false;
|
---|
135 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
136 | arg_ainfo.argdefault = "0";
|
---|
137 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
138 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
139 |
|
---|
140 |
|
---|
141 | // f arg is set to 1 if document is to
|
---|
142 | // be displayed in a frame
|
---|
143 | arg_ainfo.shortname = "f";
|
---|
144 | arg_ainfo.longname = "frame";
|
---|
145 | arg_ainfo.multiplechar = false;
|
---|
146 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
147 | arg_ainfo.argdefault = "0";
|
---|
148 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
149 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
150 |
|
---|
151 | // fc arg is "1" if search bar is to be included (i.e. if "fc" == 1
|
---|
152 | // the httpdocument macro will include "&f=1"
|
---|
153 | arg_ainfo.shortname = "fc";
|
---|
154 | arg_ainfo.longname = "include search bar";
|
---|
155 | arg_ainfo.multiplechar = false;
|
---|
156 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
157 | arg_ainfo.argdefault = "1";
|
---|
158 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
159 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
160 |
|
---|
161 | //rd is whether a document will be displayed
|
---|
162 | //with a relevant document list
|
---|
163 | arg_ainfo.shortname = "rd";
|
---|
164 | arg_ainfo.longname = "include relevant documents";
|
---|
165 | arg_ainfo.multiplechar = false;
|
---|
166 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
167 | arg_ainfo.argdefault = "0";
|
---|
168 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
169 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
170 |
|
---|
171 | //dm is the metadata that has been used for the datelist
|
---|
172 | arg_ainfo.shortname = "dm";
|
---|
173 | arg_ainfo.longname = "date metadata";
|
---|
174 | arg_ainfo.multiplechar = true;
|
---|
175 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
176 | arg_ainfo.argdefault = g_EmptyText;
|
---|
177 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
178 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
179 |
|
---|
180 | }
|
---|
181 |
|
---|
182 | documentaction::~documentaction()
|
---|
183 | {
|
---|
184 | }
|
---|
185 |
|
---|
186 | bool documentaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
|
---|
187 | recptprotolistclass *protos, ostream &logout) {
|
---|
188 |
|
---|
189 | if(!args["d"].empty())
|
---|
190 | {
|
---|
191 | text_t docTop;
|
---|
192 | get_top(args["d"],docTop);
|
---|
193 |
|
---|
194 | recptproto* collectproto = protos->getrecptproto (args["c"], logout);
|
---|
195 | if (collectproto != NULL)
|
---|
196 | {
|
---|
197 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
|
---|
198 |
|
---|
199 | if(cinfo->authenticate == "document")
|
---|
200 | {
|
---|
201 | // both are either commented out or uncomment and are empty
|
---|
202 | if (cinfo->public_documents.empty() && cinfo->private_documents.empty())
|
---|
203 | {
|
---|
204 | //deny everything
|
---|
205 | args["uan"] = "1";
|
---|
206 | args["ug"] = cinfo->auth_group;
|
---|
207 | }
|
---|
208 |
|
---|
209 | // both public_documents and private_documents are turned on !
|
---|
210 | else if (!cinfo->public_documents.empty() && !cinfo->private_documents.empty())
|
---|
211 | {
|
---|
212 | //deny everything
|
---|
213 | args["uan"] = "1";
|
---|
214 | args["ug"] = cinfo->auth_group;
|
---|
215 | }
|
---|
216 |
|
---|
217 | // if public_documents is set but this document isn't
|
---|
218 | // listed in it we need to authenticate
|
---|
219 | else if ((!cinfo->public_documents.empty()) &&
|
---|
220 | (cinfo->public_documents.find(docTop) == cinfo->public_documents.end()))
|
---|
221 | {
|
---|
222 | args["uan"] = "1";
|
---|
223 | args["ug"] = cinfo->auth_group;
|
---|
224 | }
|
---|
225 |
|
---|
226 | // if private_documents is set and this document is
|
---|
227 | // listed in it we need to authenticate
|
---|
228 | else if ((!cinfo->private_documents.empty()) &&
|
---|
229 | (cinfo->private_documents.find(docTop) != cinfo->private_documents.end()))
|
---|
230 | {
|
---|
231 | args["uan"] = "1";
|
---|
232 | args["ug"] = cinfo->auth_group;
|
---|
233 | }
|
---|
234 |
|
---|
235 | }
|
---|
236 | }
|
---|
237 | }
|
---|
238 | // check gc argument
|
---|
239 | int arg_gc = args.getintarg("gc");
|
---|
240 | if (arg_gc < 0 || arg_gc > 2) {
|
---|
241 | logout << "Warning: \"gc\" argument out of range (" << arg_gc << ")\n";
|
---|
242 | cgiarginfo *gcinfo = argsinfo.getarginfo ("gc");
|
---|
243 | if (gcinfo != NULL) args["gc"] = gcinfo->argdefault;
|
---|
244 | }
|
---|
245 |
|
---|
246 | // check gt argument (may be either 0, 1 or 2)
|
---|
247 | int arg_gt = args.getintarg("gt");
|
---|
248 | if (arg_gt != 0 && arg_gt != 1 && arg_gt != 2) {
|
---|
249 | logout << "Warning: \"gt\" argument out of range (" << arg_gt << ")\n";
|
---|
250 | cgiarginfo *gtinfo = argsinfo.getarginfo ("gt");
|
---|
251 | if (gtinfo != NULL) args["gt"] = gtinfo->argdefault;
|
---|
252 | }
|
---|
253 |
|
---|
254 | // check hl argument
|
---|
255 | int arg_hl = args.getintarg("hl");
|
---|
256 | if (arg_hl < 0 || arg_hl > 2) {
|
---|
257 | logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n";
|
---|
258 | cgiarginfo *hlinfo = argsinfo.getarginfo ("hl");
|
---|
259 | if (hlinfo != NULL) args["hl"] = hlinfo->argdefault;
|
---|
260 | }
|
---|
261 |
|
---|
262 | // check x argument
|
---|
263 | int arg_x = args.getintarg("x");
|
---|
264 | if (arg_x != 0 && arg_x != 1) {
|
---|
265 | logout << "Warning: \"x\" argument out of range (" << arg_x << ")\n";
|
---|
266 | cgiarginfo *xinfo = argsinfo.getarginfo ("x");
|
---|
267 | if (xinfo != NULL) args["x"] = xinfo->argdefault;
|
---|
268 | }
|
---|
269 |
|
---|
270 | //checks whether rd arg is valid
|
---|
271 | int arg_rd = args.getintarg("rd");
|
---|
272 | if (arg_rd != 0 && arg_rd != 1) {
|
---|
273 | logout << "Warning: \"rd\" argument out of range (" << arg_rd << ")\n";
|
---|
274 | cgiarginfo *rdinfo = argsinfo.getarginfo ("rd");
|
---|
275 | if (rdinfo != NULL) args["rd"] = rdinfo->argdefault;
|
---|
276 | }
|
---|
277 |
|
---|
278 |
|
---|
279 | return true;
|
---|
280 | }
|
---|
281 |
|
---|
282 | void documentaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
|
---|
283 | response_t &response,text_t &response_data,
|
---|
284 | ostream &logout) {
|
---|
285 |
|
---|
286 | if ((args["il"] == "w") && (!args["d"].empty())) {
|
---|
287 |
|
---|
288 | recptproto* collectproto = protos->getrecptproto (args["c"], logout);
|
---|
289 | if (collectproto != NULL) {
|
---|
290 |
|
---|
291 | text_tset metadata;
|
---|
292 | FilterResponse_t filt_response;
|
---|
293 | text_t top;
|
---|
294 |
|
---|
295 | metadata.insert ("URL");
|
---|
296 |
|
---|
297 | // get metadata for parent document
|
---|
298 | get_top (args["d"], top);
|
---|
299 | if (get_info (top, args["c"], args["l"], metadata, false, collectproto, filt_response, logout)) {
|
---|
300 | text_t url = filt_response.docInfo[0].metadata["URL"].values[0];
|
---|
301 |
|
---|
302 | response = location;
|
---|
303 | response_data = url;
|
---|
304 | return;
|
---|
305 | } else {
|
---|
306 | // error, no URL
|
---|
307 | logout << "Error: documentaction::get_cgihead_info failed on get_info" << endl;
|
---|
308 | }
|
---|
309 | }
|
---|
310 | }
|
---|
311 | response = content;
|
---|
312 | response_data = "text/html";
|
---|
313 | }
|
---|
314 |
|
---|
315 | // set_widthtspace calculates how wide the spaces in the nav bar should
|
---|
316 | // be and sets the appropriate macro
|
---|
317 | void documentaction::set_spacemacro (displayclass &disp, FilterResponse_t &response,
|
---|
318 | bool has_search_button) {
|
---|
319 |
|
---|
320 | text_t width;
|
---|
321 | int twidth, swidth, iwidth = 0;
|
---|
322 |
|
---|
323 | int numc = response.docInfo.size();
|
---|
324 | ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
|
---|
325 | ResultDocInfo_tarray::iterator docend = response.docInfo.end();
|
---|
326 |
|
---|
327 | disp.expandstring (displayclass::defaultpackage, "_pagewidth_", width);
|
---|
328 | twidth = width.getint();
|
---|
329 |
|
---|
330 | if (has_search_button) {
|
---|
331 | disp.expandstring ("query", "_searchwidth_", width);
|
---|
332 | iwidth += width.getint();
|
---|
333 | } else {
|
---|
334 | numc -= 1;
|
---|
335 | }
|
---|
336 |
|
---|
337 | while (dochere != docend) {
|
---|
338 | const text_t &title = (*dochere).metadata["Title"].values[0];
|
---|
339 |
|
---|
340 | disp.expandstring ("document", "_" + title + "width_", width);
|
---|
341 | if (width == ("_" + title + "width_")) {
|
---|
342 | disp.expandstring ("document", "_defaultwidth_", width);
|
---|
343 | }
|
---|
344 | iwidth += width.getint();
|
---|
345 | ++dochere;
|
---|
346 | }
|
---|
347 |
|
---|
348 | if ((twidth - iwidth) < numc) swidth = 2;
|
---|
349 | else {
|
---|
350 | swidth = twidth - iwidth;
|
---|
351 | if (numc > 0) swidth = swidth / numc;
|
---|
352 | }
|
---|
353 | disp.setmacro ("widthtspace", displayclass::defaultpackage, swidth);
|
---|
354 | }
|
---|
355 |
|
---|
356 | // set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros
|
---|
357 | // reponse contains 1 metadata field (Title)
|
---|
358 | void documentaction::set_navbarmacros (displayclass &disp, FilterResponse_t &response,
|
---|
359 | bool has_search_button, cgiargsclass &args,
|
---|
360 | ColInfoResponse_t &cinfo) {
|
---|
361 |
|
---|
362 |
|
---|
363 | bool use_pulldown = false;
|
---|
364 | text_tmap::iterator it = cinfo.format.find("NavigationBar");
|
---|
365 | if (it != cinfo.format.end()) {
|
---|
366 | if (it->second == "pulldown") {
|
---|
367 | use_pulldown = true;
|
---|
368 | }
|
---|
369 | }
|
---|
370 |
|
---|
371 | text_t topparent;
|
---|
372 | text_t &arg_d = args["d"];
|
---|
373 | text_t navigationbar = "<!-- Navigation Bar -->\n";
|
---|
374 |
|
---|
375 | get_top (args["cl"], topparent);
|
---|
376 | int numc = response.docInfo.size();
|
---|
377 | ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
|
---|
378 | ResultDocInfo_tarray::iterator docend = response.docInfo.end();
|
---|
379 |
|
---|
380 | if (!use_pulldown) {
|
---|
381 | if (has_search_button) {
|
---|
382 | // search uses its own navtab, as it may be suppressed based on other args
|
---|
383 | navigationbar += "_navtabsearch_";
|
---|
384 | if (args["a"] == "q") {
|
---|
385 | navigationbar += "(selected)";
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | if (has_search_button || numc == 0) navigationbar += "_navbarspacer_";
|
---|
390 |
|
---|
391 | bool first = true;
|
---|
392 | while (dochere != docend) {
|
---|
393 | if (!first) navigationbar += "_navbarspacer_";
|
---|
394 |
|
---|
395 | text_t title = (*dochere).metadata["Title"].values[0];
|
---|
396 |
|
---|
397 | navigationbar += "_navtab_(_httpbrowse"+(*dochere).OID+"_,"+title;
|
---|
398 | // if we are at this classifier
|
---|
399 | if (arg_d.empty() && ((*dochere).OID == topparent)) {
|
---|
400 | // don't link to this classifier as it is the current one
|
---|
401 | navigationbar += ",selected";
|
---|
402 | }
|
---|
403 | navigationbar += ")";
|
---|
404 |
|
---|
405 | // set the _httpbrowseCLX_ macro for this classification
|
---|
406 | disp.setmacro ("httpbrowse" + (*dochere).OID, displayclass::defaultpackage, "_httpdocument_&cl=" + (*dochere).OID);
|
---|
407 | ++dochere;
|
---|
408 | first = false;
|
---|
409 | }
|
---|
410 |
|
---|
411 | navigationbar += "\n<!-- End of Navigation Bar -->\n";
|
---|
412 |
|
---|
413 | } else {
|
---|
414 |
|
---|
415 | navigationbar = "<form method=\"get\" name=\"navform\">\n";
|
---|
416 | navigationbar += "<select name=\"navbar\" onChange=\"location.href=";
|
---|
417 | navigationbar += "document.navform.navbar.options[document.navform.navbar.selectedIndex].value\">\n";
|
---|
418 |
|
---|
419 | if (args["a"] != "q" && args["cl"].empty()) {
|
---|
420 | navigationbar += "<option value=\"\" selected>_textselectpage_</option>\n";
|
---|
421 | }
|
---|
422 |
|
---|
423 | if (has_search_button) {
|
---|
424 | navigationbar += "<option value=\"_httpquery_\"";
|
---|
425 | if (args["a"] == "q") {
|
---|
426 | navigationbar += " selected";
|
---|
427 | }
|
---|
428 | navigationbar += ">_labelSearch_</option>\n";
|
---|
429 | }
|
---|
430 |
|
---|
431 | while (dochere != docend) {
|
---|
432 | text_t title = dochere->metadata["Title"].values[0];
|
---|
433 |
|
---|
434 | navigationbar += "<option value=\"_httpdocument_&cl=" + dochere->OID + "\"";
|
---|
435 | if (topparent == dochere->OID) {
|
---|
436 | navigationbar += " selected";
|
---|
437 | }
|
---|
438 | navigationbar += ">_navlinktitle_(" + title + ")</option>\n";
|
---|
439 | ++dochere;
|
---|
440 | }
|
---|
441 |
|
---|
442 | navigationbar += "</select>\n";
|
---|
443 | navigationbar += "</form>\n";
|
---|
444 | }
|
---|
445 |
|
---|
446 | disp.setmacro ("navigationbar", displayclass::defaultpackage, navigationbar);
|
---|
447 | }
|
---|
448 |
|
---|
449 | // define all the macros which might be used by other actions
|
---|
450 | // to produce pages.
|
---|
451 | void documentaction::define_external_macros (displayclass &disp, cgiargsclass &args,
|
---|
452 | recptprotolistclass *protos, ostream &logout) {
|
---|
453 |
|
---|
454 | // define_external_macros sets the following macros:
|
---|
455 |
|
---|
456 | // _navigationbar_ this is the navigation bar containing the search button
|
---|
457 | // and any classification buttons - it goes at the top of
|
---|
458 | // most pages. for now we're assuming that there'll always
|
---|
459 | // be a search button - we should probably check that there
|
---|
460 | // is a query action before making this assumption
|
---|
461 |
|
---|
462 | // _httpbrowseXXX_ the http macros for each classification (i.e. if there
|
---|
463 | // are Title and Creator classifications _httpbrowseTitle_
|
---|
464 | // and _httpbrowseCreator_ will be set
|
---|
465 |
|
---|
466 | // _widthtspace_ the width of the spacers between buttons in navigation
|
---|
467 | // bar
|
---|
468 |
|
---|
469 | // _httpdocument_ has '&f=1' added if displaying document inside a frame
|
---|
470 |
|
---|
471 | // _gsdltop_ macro to replace _top targets with
|
---|
472 |
|
---|
473 | // _httppagehome_ overridden home url if html collections have own homepage
|
---|
474 |
|
---|
475 | // _usability_ macros for remote usability reporting: if
|
---|
476 | // _usabinterface_ "format Usability [multi|textonly|stepwise]" is in
|
---|
477 | // _usabilityscript_ collect.cfg
|
---|
478 |
|
---|
479 | // _versionnnum_ greenstone version number (hard-coded)
|
---|
480 | // must have a valid collection server to continue
|
---|
481 |
|
---|
482 | text_t &collection = args["c"];
|
---|
483 | if (collection.empty()) return;
|
---|
484 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
485 | if (collectproto == NULL) return;
|
---|
486 |
|
---|
487 | if (recpt == NULL) {
|
---|
488 | logout << "ERROR (documentaction::define_external_macros): This action does not contain\n"
|
---|
489 | << " information about any receptionists. The method set_receptionist was\n"
|
---|
490 | << " probably not called from the module which instantiated this action.\n";
|
---|
491 | return;
|
---|
492 | }
|
---|
493 |
|
---|
494 | outconvertclass text_t2ascii;
|
---|
495 | comerror_t err;
|
---|
496 | InfoFiltersResponse_t filterinfo;
|
---|
497 | FilterResponse_t response;
|
---|
498 | text_tset metadata;
|
---|
499 |
|
---|
500 | // get info on current collection and load up formatinfo
|
---|
501 | // I'd prefer not to do this here as we're getting
|
---|
502 | // collection info every time (and probably also getting
|
---|
503 | // it in other places some of the time) - One day I'll
|
---|
504 | // fix it ... maybe - Stefan.
|
---|
505 | ColInfoResponse_t cinfo;
|
---|
506 |
|
---|
507 | collectproto->get_collectinfo (collection, cinfo, err, logout);
|
---|
508 | load_formatinfo (cinfo.format, args.getintarg("gt"));
|
---|
509 | // ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
|
---|
510 | // if (cinfo == NULL) {
|
---|
511 | // logout << "ERROR (documentaction::define_external_macros): get_collectinfo_ptr returned NULL\n";
|
---|
512 | // return;
|
---|
513 | // }
|
---|
514 | //load_formatinfo (cinfo->format, args.getintarg("gt"));
|
---|
515 |
|
---|
516 | if (formatinfo.DocumentUseHTML) {
|
---|
517 |
|
---|
518 | // frame stuff
|
---|
519 | if (args["fc"] == "1") {
|
---|
520 | text_t httpdocument;
|
---|
521 | disp.expandstring (displayclass::defaultpackage, "_httpdocument_", httpdocument);
|
---|
522 | httpdocument += "&f=1";
|
---|
523 | disp.setmacro ("httpdocument", displayclass::defaultpackage, httpdocument);
|
---|
524 | disp.setmacro ("gsdltop", displayclass::defaultpackage, "documenttop");
|
---|
525 | formatinfo.DocumentText = "[Text]";
|
---|
526 | }
|
---|
527 | text_tmap::iterator it = cinfo.format.find ("homepage");
|
---|
528 | if (it != cinfo.format.end()) {
|
---|
529 | text_t httppagehome;
|
---|
530 | if (get_link (args, protos, (*it).second, httppagehome, logout))
|
---|
531 | disp.setmacro ("httppagehome", displayclass::defaultpackage, httppagehome);
|
---|
532 | }
|
---|
533 | }
|
---|
534 |
|
---|
535 | // don't want navigation bar if page is 'detached'
|
---|
536 | if (!args.getintarg("x")) {
|
---|
537 |
|
---|
538 | collectproto->get_filterinfo (collection, filterinfo, err, logout);
|
---|
539 | if (err == noError) {
|
---|
540 | // check that there's a browse filter
|
---|
541 | if (filterinfo.filterNames.find ("BrowseFilter") != filterinfo.filterNames.end()) {
|
---|
542 |
|
---|
543 | metadata.insert ("Title");
|
---|
544 | bool getParents = false;
|
---|
545 | get_children ("", collection, args["l"], metadata, getParents, collectproto, response, logout);
|
---|
546 |
|
---|
547 | bool has_search_button = true;
|
---|
548 | collectproto->is_searchable(collection, has_search_button, err, logout);
|
---|
549 | if (err != noError) has_search_button = false;
|
---|
550 |
|
---|
551 | // calculate width of spacers and set _widthtspace_ macro
|
---|
552 | if (args.getintarg("v") == 0) set_spacemacro (disp, response, has_search_button);
|
---|
553 |
|
---|
554 | // set _navigationbar_ macro
|
---|
555 | set_navbarmacros (disp, response, has_search_button, args, cinfo);
|
---|
556 |
|
---|
557 | }
|
---|
558 | } else {
|
---|
559 | logout << text_t2ascii
|
---|
560 | << "Error (documentaction::define_external_macros()) in call to get_filterinfo() "
|
---|
561 | << get_comerror_string (err);
|
---|
562 | }
|
---|
563 | }
|
---|
564 |
|
---|
565 | // send feedback button and pages
|
---|
566 | text_tmap::iterator usability = cinfo.format.find("Usability");
|
---|
567 | if(usability!=cinfo.format.end()){
|
---|
568 | disp.setmacro("usability",displayclass::defaultpackage,"_usablink_");
|
---|
569 | disp.setmacro("usabinterface",displayclass::defaultpackage,("_usab"+(*usability).second+"_"));
|
---|
570 | disp.setmacro("usabilityscript", displayclass::defaultpackage, "_usabshowscript_");
|
---|
571 | }
|
---|
572 |
|
---|
573 | // version num
|
---|
574 | disp.setmacro("versionnum", displayclass::defaultpackage, GSDL_VERSION);
|
---|
575 |
|
---|
576 | }
|
---|
577 |
|
---|
578 | bool documentaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
|
---|
579 | const text_t &inlink, text_t &outlink, ostream &logout) {
|
---|
580 |
|
---|
581 | FilterResponse_t response;
|
---|
582 | text_tset metadata;
|
---|
583 | metadata.insert ("section");
|
---|
584 |
|
---|
585 | // check current collection first
|
---|
586 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
587 |
|
---|
588 | if (get_info (inlink, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
|
---|
589 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
590 | #ifndef DOCHANDLE
|
---|
591 | outlink = "_httpdocument_&d=" + response.docInfo[0].metadata["section"].values[0];
|
---|
592 | #else
|
---|
593 | outlink = "_httpdocumenthandle_("+args["c"]+","+response.docInfo[0].metadata["section"].values[0]+")";
|
---|
594 | #endif
|
---|
595 |
|
---|
596 | return true;
|
---|
597 | }
|
---|
598 | }
|
---|
599 |
|
---|
600 | // check all the other enabled collections
|
---|
601 |
|
---|
602 | if (args["ccs"] == "1" && !args["cc"].empty()) {
|
---|
603 | text_tarray collections;
|
---|
604 | splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
|
---|
605 |
|
---|
606 | text_tarray::const_iterator col_here = collections.begin();
|
---|
607 | text_tarray::const_iterator col_end = collections.end();
|
---|
608 |
|
---|
609 | while (col_here != col_end) {
|
---|
610 |
|
---|
611 | // don't need to check current collection again
|
---|
612 | if (*col_here == args["c"]) {++col_here; continue;}
|
---|
613 |
|
---|
614 | collectproto = protos->getrecptproto (*col_here, logout);
|
---|
615 |
|
---|
616 | if (get_info (inlink, *col_here, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
617 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
618 | #ifndef DOCHANDLE
|
---|
619 | outlink = "_httpdocument_&c=" + *col_here + "&d=" +
|
---|
620 | response.docInfo[0].metadata["section"].values[0];
|
---|
621 | #else
|
---|
622 | outlink = "_httpdocumenthandle_("+*col_here+","+response.docInfo[0].metadata["section"].values[0]+")";
|
---|
623 | #endif
|
---|
624 |
|
---|
625 | return true;
|
---|
626 | }
|
---|
627 | }
|
---|
628 | ++col_here;
|
---|
629 | }
|
---|
630 | }
|
---|
631 | return false;
|
---|
632 | }
|
---|
633 |
|
---|
634 | void documentaction::load_formatinfo (const text_tmap &colformat, int gt) {
|
---|
635 |
|
---|
636 | formatinfo.clear();
|
---|
637 | text_tmap::const_iterator format_here = colformat.begin();
|
---|
638 | text_tmap::const_iterator format_end = colformat.end();
|
---|
639 |
|
---|
640 | while (format_here != format_end) {
|
---|
641 | if (((*format_here).first == "DocumentImages") &&
|
---|
642 | ((*format_here).second == "true"))
|
---|
643 | formatinfo.DocumentImages = true;
|
---|
644 | else if (((*format_here).first == "DocumentTitles") &&
|
---|
645 | ((*format_here).second == "false"))
|
---|
646 | formatinfo.DocumentTitles = false;
|
---|
647 | else if ((*format_here).first == "DocumentHeading")
|
---|
648 | formatinfo.DocumentHeading = (*format_here).second;
|
---|
649 | else if (((*format_here).first == "DocumentContents") &&
|
---|
650 | ((*format_here).second == "false"))
|
---|
651 | formatinfo.DocumentContents = false;
|
---|
652 | else if (((*format_here).first == "DocumentArrowsBottom") &&
|
---|
653 | ((*format_here).second == "false"))
|
---|
654 | formatinfo.DocumentArrowsBottom = false;
|
---|
655 | else if (((*format_here).first == "DocumentArrowsTop") &&
|
---|
656 | ((*format_here).second == "true"))
|
---|
657 | formatinfo.DocumentArrowsTop = true;
|
---|
658 | else if ((*format_here).first == "DocumentButtons")
|
---|
659 | splitchar ((*format_here).second.begin(), (*format_here).second.end(),
|
---|
660 | '|', formatinfo.DocumentButtons);
|
---|
661 | else if ((*format_here).first == "DocumentText")
|
---|
662 | formatinfo.DocumentText = (*format_here).second;
|
---|
663 | else if ((*format_here).first == "RelatedDocuments")
|
---|
664 | formatinfo.RelatedDocuments = (*format_here).second;
|
---|
665 | else if (((*format_here).first == "DocumentUseHTML") &&
|
---|
666 | ((*format_here).second == "true"))
|
---|
667 | formatinfo.DocumentUseHTML = true;
|
---|
668 | else if (((*format_here).first == "AllowExtendedOptions") &&
|
---|
669 | ((*format_here).second == "true"))
|
---|
670 | formatinfo.AllowExtendedOptions = true;
|
---|
671 | else
|
---|
672 | formatinfo.formatstrings[(*format_here).first] = (*format_here).second;
|
---|
673 |
|
---|
674 | ++format_here;
|
---|
675 | }
|
---|
676 |
|
---|
677 | // never want arrows when text is expanded
|
---|
678 | if (gt) {
|
---|
679 | formatinfo.DocumentArrowsBottom = false;
|
---|
680 | formatinfo.DocumentArrowsTop = false;
|
---|
681 | }
|
---|
682 | }
|
---|
683 |
|
---|
684 |
|
---|
685 | // define all the macros which are related to pages generated
|
---|
686 | // by this action. we also load up the formatinfo structure
|
---|
687 | // here (it's used in do_action as well as here)
|
---|
688 | void documentaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
689 | recptprotolistclass *protos, ostream &logout) {
|
---|
690 |
|
---|
691 | // define_internal_macros sets the following macros:
|
---|
692 |
|
---|
693 | // _pagetitle_ the title to be displayed at the top of the browser window
|
---|
694 |
|
---|
695 | // _imagethispage_ the title image to be displayed at top right of page
|
---|
696 |
|
---|
697 | // _navarrowsbottom_ this may be overridden to "" when format option
|
---|
698 | // DocumentArrowsBottom is false
|
---|
699 |
|
---|
700 | // _navarrowstop_ likewise for DocumentArrowsTop
|
---|
701 |
|
---|
702 | // _httpprevarrow_ links to next and previous sections of document - used
|
---|
703 | // _httpnextarrow_ by DocumentArrowsBottom
|
---|
704 |
|
---|
705 | // _header_ the header macro is overridden if we're not at a top level
|
---|
706 | // classification to remove the title block
|
---|
707 |
|
---|
708 | // _thisOID_ the OID (directory) of the current document - this corresponds
|
---|
709 | // to the archivedir metadata element
|
---|
710 |
|
---|
711 | // must have a valid collection server to continue
|
---|
712 |
|
---|
713 | text_t &collection = args["c"];
|
---|
714 | if (collection.empty()) return;
|
---|
715 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
716 | if (collectproto == NULL) return;
|
---|
717 |
|
---|
718 | text_tset metadata;
|
---|
719 | FilterResponse_t response;
|
---|
720 | text_t &arg_d = args["d"];
|
---|
721 | text_t &arg_cl = args["cl"];
|
---|
722 |
|
---|
723 | if (!formatinfo.DocumentArrowsBottom) {
|
---|
724 | disp.setmacro("navarrowsbottom", "document", "");
|
---|
725 | } else if (!formatinfo.DocumentArrowsBottom) {
|
---|
726 | disp.setmacro("navarrowstop", "document", "");
|
---|
727 | }
|
---|
728 |
|
---|
729 | if (!arg_d.empty() && (formatinfo.DocumentArrowsBottom || formatinfo.DocumentArrowsTop)) {
|
---|
730 | // set _httpprevarrow_ and _httpnextarrow_
|
---|
731 | set_arrow_macros (args, collectproto, disp, logout);
|
---|
732 | }
|
---|
733 |
|
---|
734 | metadata.insert ("Title");
|
---|
735 |
|
---|
736 | bool fulltoc = false;
|
---|
737 |
|
---|
738 | if (args["cl"] != "search") {
|
---|
739 | // see if there's a FullTOC string
|
---|
740 | text_t cl_top, full_toc;
|
---|
741 | get_top (arg_cl, cl_top);
|
---|
742 | if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
|
---|
743 | if (full_toc == "true") fulltoc = true;
|
---|
744 | }
|
---|
745 |
|
---|
746 | if (!arg_d.empty() && !fulltoc) {
|
---|
747 | // we're at document level
|
---|
748 |
|
---|
749 | metadata.insert ("archivedir");
|
---|
750 |
|
---|
751 | comerror_t err;
|
---|
752 | OptionValue_tarray options;
|
---|
753 | // we need to do the query again for the z3950proto
|
---|
754 | if (collectproto->get_protocol_name(err)=="z3950proto") {
|
---|
755 | OptionValue_t opt;
|
---|
756 | opt.name="Term";opt.value=args["q"];options.push_back(opt);
|
---|
757 | opt.name="QueryType";
|
---|
758 | opt.value=(args.getintarg("t")) ? "ranked" : "boolean";
|
---|
759 | options.push_back(opt);
|
---|
760 | opt.name="Index";opt.value=args["h"];options.push_back(opt);
|
---|
761 | }
|
---|
762 |
|
---|
763 | //do not display relation metadata
|
---|
764 | disp.setmacro ("relateddoc", "document", "");
|
---|
765 |
|
---|
766 | //if preferences indicate relevant docs should be collected
|
---|
767 | //and there is no particular format specified then display
|
---|
768 | //this default format.
|
---|
769 | if(args["rd"] == "1" && formatinfo.RelatedDocuments.empty()){
|
---|
770 |
|
---|
771 | text_t relation = g_EmptyText; //string for displaying relation metadata
|
---|
772 |
|
---|
773 | //call function in formattools.cpp which will return the text of the
|
---|
774 | //related documents in a vertical list. This is the default format.
|
---|
775 |
|
---|
776 | if (get_info (arg_d, collection, args["l"], metadata, options, false, collectproto, response, logout))
|
---|
777 | relation += get_related_docs(collection, collectproto, response.docInfo[0], logout);
|
---|
778 |
|
---|
779 | //set macro to be the related document string
|
---|
780 |
|
---|
781 | disp.setmacro ("relateddoc", "document", relation);
|
---|
782 | }
|
---|
783 |
|
---|
784 |
|
---|
785 | // get metadata for this document and it's parents
|
---|
786 | if (get_info (arg_d, collection, args["l"], metadata, options,
|
---|
787 | true, collectproto, response, logout)) {
|
---|
788 |
|
---|
789 | disp.setmacro ("header", "document", "_textheader_");
|
---|
790 |
|
---|
791 | text_tarray pagetitlearray;
|
---|
792 | if (!response.docInfo[0].metadata["Title"].values[0].empty())
|
---|
793 | pagetitlearray.push_back (response.docInfo[0].metadata["Title"].values[0]);
|
---|
794 |
|
---|
795 | if (args["gt"] != "1") {
|
---|
796 | MetadataInfo_t *parenttitle = response.docInfo[0].metadata["Title"].parent;
|
---|
797 | while (parenttitle != NULL) {
|
---|
798 | if (!parenttitle->values[0].empty())
|
---|
799 | pagetitlearray.push_back (parenttitle->values[0]);
|
---|
800 | parenttitle = parenttitle->parent;
|
---|
801 | }
|
---|
802 | }
|
---|
803 | reverse (pagetitlearray.begin(), pagetitlearray.end());
|
---|
804 | text_t pagetitle;
|
---|
805 | joinchar (pagetitlearray, ": ", pagetitle);
|
---|
806 | // remove html tags from the title
|
---|
807 | text_t::iterator open_tag=pagetitle.begin();
|
---|
808 | while (open_tag < pagetitle.end()) {
|
---|
809 | if (*open_tag == '<') {
|
---|
810 | text_t::iterator close_tag=open_tag+1;
|
---|
811 | text_t::iterator donechar=pagetitle.end();
|
---|
812 | while (close_tag < donechar) {
|
---|
813 | if (*close_tag == '>')
|
---|
814 | break;
|
---|
815 | ++close_tag;
|
---|
816 | }
|
---|
817 | if (close_tag < donechar) // remove this html tag, replace with space
|
---|
818 | *close_tag=' ';
|
---|
819 | pagetitle.erase(open_tag, close_tag);
|
---|
820 | }
|
---|
821 | ++open_tag;
|
---|
822 | }
|
---|
823 | disp.setmacro ("pagetitle", "document", pagetitle);
|
---|
824 |
|
---|
825 | if (is_top (arg_d))
|
---|
826 | disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(response.docInfo[0].metadata["archivedir"].values[0]));
|
---|
827 | else {
|
---|
828 | MetadataInfo_t *parentad = response.docInfo[0].metadata["archivedir"].parent;
|
---|
829 | text_t thisOID;
|
---|
830 | while (parentad != NULL) {
|
---|
831 | thisOID = parentad->values[0];
|
---|
832 | parentad = parentad->parent;
|
---|
833 | }
|
---|
834 | disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(thisOID));
|
---|
835 | }
|
---|
836 | }
|
---|
837 | } else {
|
---|
838 | if (!arg_cl.empty()) {
|
---|
839 |
|
---|
840 | // create the currentnodevalue macro - this is the value of the node
|
---|
841 | // in the hierarchy that is currently open.
|
---|
842 | if (get_info (arg_cl, collection, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
843 | text_t &title = response.docInfo[0].metadata["Title"].values[0];
|
---|
844 | disp.setmacro ("currentnodevalue", "document", title);
|
---|
845 | }
|
---|
846 | // get metadata for top level classification
|
---|
847 | text_t classtop;
|
---|
848 | get_top (arg_cl, classtop);
|
---|
849 | metadata.insert ("childtype");
|
---|
850 | metadata.insert ("parameters");
|
---|
851 |
|
---|
852 | if (get_info (classtop, collection, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
853 |
|
---|
854 | text_t &title = response.docInfo[0].metadata["Title"].values[0];
|
---|
855 | bool unknown = false;
|
---|
856 |
|
---|
857 | // test if we have macros defined for this classification's
|
---|
858 | // metadata name - if not we'll just display the name
|
---|
859 | text_t tmp;
|
---|
860 | text_t macroname="_label" + title + "_";
|
---|
861 | disp.expandstring ("Global", macroname, tmp);
|
---|
862 | if (tmp == macroname) unknown = true; // it wasn't expanded
|
---|
863 |
|
---|
864 | if (unknown) {
|
---|
865 | disp.setmacro ("pagetitle", "document", title);
|
---|
866 | } else {
|
---|
867 | disp.setmacro ("pagetitle", "document", macroname);
|
---|
868 | }
|
---|
869 | /* for ns4/image layout compatibility. when this is no longer
|
---|
870 | * needed, set imagethispage to _label+title+_ */
|
---|
871 | text_t titlemacroname="_titleimage" + title + "_";
|
---|
872 | disp.expandstring ("Global", titlemacroname, tmp);
|
---|
873 | if (tmp == titlemacroname) { /* _titleimage$META_ isn't defined */
|
---|
874 | if (!unknown) /* _label$META_ is defined */
|
---|
875 | disp.setmacro ("imagethispage", "document", macroname);
|
---|
876 | else
|
---|
877 | disp.setmacro ("imagethispage", "document", title);
|
---|
878 | } else { /* _titleimage$META_ is defined */
|
---|
879 | disp.setmacro ("imagethispage", "document", titlemacroname);
|
---|
880 | }
|
---|
881 |
|
---|
882 | //if the document is not a document from a collection
|
---|
883 | //we must set the macro to be an empty string
|
---|
884 | disp.setmacro ("relateddoc", "document", "");
|
---|
885 |
|
---|
886 | // Add macros specific to the Collage/Phind classifiers
|
---|
887 | text_t &childtype = response.docInfo[0].metadata["childtype"].values[0];
|
---|
888 | if (childtype == "Collage") {
|
---|
889 |
|
---|
890 | text_t::iterator a = arg_cl.begin();
|
---|
891 | text_t::iterator b = arg_cl.end();
|
---|
892 |
|
---|
893 | bool collage = true;
|
---|
894 | while (a != b) {
|
---|
895 | if (*a == 46) collage = false;
|
---|
896 | ++a;
|
---|
897 | }
|
---|
898 |
|
---|
899 | if (collage) {
|
---|
900 | disp.setmacro ("collageclassifier", "document", "_collageapplet_");
|
---|
901 |
|
---|
902 | // Next, macros that control the way the classifier is displayed
|
---|
903 | text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
|
---|
904 |
|
---|
905 | // extract key=value pairs and set as macros
|
---|
906 | text_t::iterator here = parameters.begin();
|
---|
907 | text_t::iterator end = parameters.end();
|
---|
908 | text_t key, value;
|
---|
909 |
|
---|
910 | while (here != end) {
|
---|
911 | // get the next key and value pair
|
---|
912 | here = getdelimitstr (here, end, '=', key);
|
---|
913 | here = getdelimitstr (here, end, ';', value);
|
---|
914 |
|
---|
915 | // store this key=value pair
|
---|
916 | if (!key.empty() && !value.empty()) {
|
---|
917 | disp.setmacro ("collage"+key, "document", value);
|
---|
918 | }
|
---|
919 | }
|
---|
920 |
|
---|
921 |
|
---|
922 | }
|
---|
923 | }
|
---|
924 |
|
---|
925 | if (childtype == "Phind") {
|
---|
926 |
|
---|
927 | // First, a macro to display the phind classifier
|
---|
928 | disp.setmacro ("phindclassifier", "document", "_phindapplet_");
|
---|
929 |
|
---|
930 | // Next, macros that control the way the classifier is displayed
|
---|
931 | text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
|
---|
932 |
|
---|
933 | // extract key=value pairs and set as macros
|
---|
934 | text_t::iterator here = parameters.begin();
|
---|
935 | text_t::iterator end = parameters.end();
|
---|
936 | text_t key, value;
|
---|
937 |
|
---|
938 | while (here != end) {
|
---|
939 | // get the next key and value pair
|
---|
940 | here = getdelimitstr (here, end, '=', key);
|
---|
941 | here = getdelimitstr (here, end, ';', value);
|
---|
942 |
|
---|
943 | // store this key=value pair
|
---|
944 | if (!key.empty() && !value.empty()) {
|
---|
945 | disp.setmacro (key, "document", value);
|
---|
946 | }
|
---|
947 | }
|
---|
948 | } // end if (childtype == "Phind")
|
---|
949 | }
|
---|
950 | } // end if (!arg_cl.empty()) {
|
---|
951 | }
|
---|
952 | }
|
---|
953 |
|
---|
954 |
|
---|
955 | bool documentaction::do_action(cgiargsclass &args, recptprotolistclass *protos,
|
---|
956 | browsermapclass *browsers, displayclass &disp,
|
---|
957 | outconvertclass &outconvert, ostream &textout,
|
---|
958 | ostream &logout)
|
---|
959 | {
|
---|
960 | // must have a valid collection server
|
---|
961 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
962 | if (collectproto == NULL) {
|
---|
963 | logout << "documentaction::do_action called with NULL collectproto\n";
|
---|
964 | textout << outconvert << disp << "_document:header_\n"
|
---|
965 | << "Error: Attempt to get document without setting collection\n"
|
---|
966 | << "_document:footer_\n";
|
---|
967 | } else {
|
---|
968 |
|
---|
969 | text_t OID = args["d"];
|
---|
970 | if (OID.empty()) OID = args["cl"];
|
---|
971 | if (OID.empty()) {
|
---|
972 | textout << outconvert << disp << "Document contains no data_document:footer_\n";
|
---|
973 | return true;
|
---|
974 | }
|
---|
975 |
|
---|
976 |
|
---|
977 | if (formatinfo.DocumentUseHTML && !args["d"].empty()) {
|
---|
978 |
|
---|
979 | if (args["f"] == "1") {
|
---|
980 | textout << outconvert << disp
|
---|
981 | << "<html><head></head>\n"
|
---|
982 | << "<frameset rows=\"68,*\" noresize border=0>\n"
|
---|
983 | << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
|
---|
984 | #ifndef DOCHANDLE
|
---|
985 | << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d="
|
---|
986 | << args["d"] << "\">"
|
---|
987 | #else
|
---|
988 | << "<frame name=\"documenttop\" frameborder=0 src=\"_httpdocumenthandle_("
|
---|
989 | << args["c"] << "," << args["d"] << ")\">"
|
---|
990 | #endif
|
---|
991 | << "<noframes>\n"
|
---|
992 | << "<p>You must have a frame enabled browser to view this.</p>\n"
|
---|
993 | << "</noframes>\n"
|
---|
994 | << "</frameset>\n"
|
---|
995 | << "</html>\n";
|
---|
996 | } else {
|
---|
997 | output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
|
---|
998 | }
|
---|
999 | return true;
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 |
|
---|
1003 | textout << outconvert << disp << "_document:header_\n"
|
---|
1004 | << "_document:content_\n";
|
---|
1005 |
|
---|
1006 | // output the table of contents
|
---|
1007 | browsetoolsclass b;
|
---|
1008 | b.output_toc(args, browsers, formatinfo, collectproto,
|
---|
1009 | disp, outconvert, textout, logout);
|
---|
1010 |
|
---|
1011 | if (formatinfo.DocumentArrowsTop && !args["d"].empty()) {
|
---|
1012 | textout << outconvert << disp << "_document:navarrowstop_\n";
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | //output the related documents (may be the empty string)
|
---|
1016 | //will not output the docs if a format string is specified
|
---|
1017 | textout << outconvert << disp << "_document:relateddoc_\n";
|
---|
1018 |
|
---|
1019 | // output the document text
|
---|
1020 | if (!args["d"].empty()) {
|
---|
1021 | textout << outconvert << "<p>\n";
|
---|
1022 | output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
|
---|
1023 | }
|
---|
1024 |
|
---|
1025 | textout << outconvert << disp << "_document:footer_\n";
|
---|
1026 | }
|
---|
1027 | return true;
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | void documentaction::output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
|
---|
1031 | const TermInfo_tarray &terminfo, const text_t &OID,
|
---|
1032 | bool highlight, int hastxt, int wanttext,
|
---|
1033 | text_t &collection, recptproto *collectproto,
|
---|
1034 | browsermapclass *browsers, displayclass &disp,
|
---|
1035 | outconvertclass &outconvert, ostream &textout,
|
---|
1036 | ostream &logout, cgiargsclass &args) {
|
---|
1037 |
|
---|
1038 | DocumentRequest_t docrequest;
|
---|
1039 | DocumentResponse_t docresponse;
|
---|
1040 | comerror_t err;
|
---|
1041 | if (hastxt == 1) {
|
---|
1042 |
|
---|
1043 | if (wanttext) {
|
---|
1044 | // get the text
|
---|
1045 | docrequest.OID = OID;
|
---|
1046 | collectproto->get_document (collection, docrequest, docresponse, err, logout);
|
---|
1047 |
|
---|
1048 | // cut down on overhead by not using formattools if we only want the text
|
---|
1049 | // (wanttext will equal 2 if we want text and other stuff too)
|
---|
1050 | if (wanttext == 1)
|
---|
1051 | if (highlight) {
|
---|
1052 | highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout);
|
---|
1053 | } else {
|
---|
1054 | textout << outconvert << disp << docresponse.doc;
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | if (wanttext != 1) {
|
---|
1059 | text_tmap options;
|
---|
1060 | options["text"] = docresponse.doc;
|
---|
1061 |
|
---|
1062 | if (formatinfo.AllowExtendedOptions) {
|
---|
1063 | browsetoolsclass b;
|
---|
1064 | b.load_extended_options(options, args, browsers, formatinfo,
|
---|
1065 | collectproto, disp, outconvert, logout);
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | text_t doctext
|
---|
1069 | = get_formatted_string (collection, collectproto, docinfo, disp,
|
---|
1070 | formatlistptr, options, logout);
|
---|
1071 |
|
---|
1072 | if (highlight) {
|
---|
1073 | highlighttext(doctext, args, terminfo, disp, outconvert, textout);
|
---|
1074 | } else {
|
---|
1075 | textout << outconvert << disp << doctext;
|
---|
1076 | }
|
---|
1077 | }
|
---|
1078 | }
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 |
|
---|
1082 | void documentaction::output_document (const text_t &OID, cgiargsclass &args,
|
---|
1083 | recptproto *collectproto, browsermapclass *browsers,
|
---|
1084 | displayclass &disp, outconvertclass &outconvert,
|
---|
1085 | ostream &textout, ostream &logout) {
|
---|
1086 | FilterResponse_t inforesponse;
|
---|
1087 | FilterResponse_t queryresponse;
|
---|
1088 | text_tset metadata;
|
---|
1089 | bool getParents = false;
|
---|
1090 | bool highlight = false;
|
---|
1091 | int wanttext = 0;
|
---|
1092 | int arg_gt = args.getintarg("gt");
|
---|
1093 | text_t &collection = args["c"];
|
---|
1094 |
|
---|
1095 | // if we have a query string and highlighting is turned on we need
|
---|
1096 | // to redo the query to get the terms for highlighting
|
---|
1097 |
|
---|
1098 | if (!args["q"].empty() && args.getintarg("hl")) {
|
---|
1099 |
|
---|
1100 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
|
---|
1101 | bool segment = false;
|
---|
1102 | if (cinfo != NULL) {
|
---|
1103 | segment = cinfo->isSegmented;
|
---|
1104 | }
|
---|
1105 | FilterRequest_t request;
|
---|
1106 | comerror_t err;
|
---|
1107 | request.filterResultOptions = FRmatchTerms;
|
---|
1108 | text_t formattedstring = args["q"];
|
---|
1109 | format_querystring (formattedstring, args.getintarg("b"), segment);
|
---|
1110 | set_queryfilter_options (request, formattedstring, args);
|
---|
1111 | args["q"] = formattedstring; // need to set this here for phrase
|
---|
1112 | // highlighting, where we look at the querystring
|
---|
1113 | collectproto->filter (args["c"], request, queryresponse, err, logout);
|
---|
1114 | if (err != noError) {
|
---|
1115 | outconvertclass text_t2ascii;
|
---|
1116 | logout << text_t2ascii
|
---|
1117 | << "documentaction::output_document: call to QueryFilter failed "
|
---|
1118 | << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
|
---|
1119 | highlight = false;
|
---|
1120 | } else {
|
---|
1121 | highlight = true;
|
---|
1122 | }
|
---|
1123 | }
|
---|
1124 |
|
---|
1125 | format_t *formatlistptr = new format_t();
|
---|
1126 | parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
|
---|
1127 |
|
---|
1128 | metadata.insert ("hastxt");
|
---|
1129 | metadata.insert ("haschildren");
|
---|
1130 |
|
---|
1131 | if (formatinfo.DocumentText == "[Text]")
|
---|
1132 | wanttext = 1;
|
---|
1133 | else {
|
---|
1134 | char *docformat = formatinfo.DocumentText.getcstr();
|
---|
1135 | if (strstr (docformat, "[Text]") != NULL)
|
---|
1136 | wanttext = 2;
|
---|
1137 | delete []docformat;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | textout << outconvert << "<div class=\"documenttext\">\n";
|
---|
1141 |
|
---|
1142 | if (get_info (OID, collection, args["l"], metadata, getParents, collectproto, inforesponse, logout)) {
|
---|
1143 | int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
|
---|
1144 | int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
|
---|
1145 |
|
---|
1146 | if (arg_gt == 0) {
|
---|
1147 | output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
|
---|
1148 | OID, highlight, hastxt, wanttext, collection, collectproto,
|
---|
1149 | browsers, disp, outconvert, textout, logout, args);
|
---|
1150 |
|
---|
1151 | } else {
|
---|
1152 |
|
---|
1153 | ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
|
---|
1154 |
|
---|
1155 | // text is to be expanded
|
---|
1156 | text_t exOID = OID;
|
---|
1157 | if (haschildren != 1) exOID = get_parent (OID);
|
---|
1158 | if (exOID.empty()) exOID = OID;
|
---|
1159 |
|
---|
1160 | // if we're not in a document (i.e. we're in a top level classification)
|
---|
1161 | // we need to pass "is_classify = true" to get_contents so that it
|
---|
1162 | // doesn't recurse all the way through each document in the classification
|
---|
1163 | bool is_classify = false;
|
---|
1164 | if (args["d"].empty()) is_classify = true;
|
---|
1165 |
|
---|
1166 | get_contents (exOID, is_classify, metadata, collection, args["l"],
|
---|
1167 | collectproto, inforesponse, logout);
|
---|
1168 |
|
---|
1169 | ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
|
---|
1170 | ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
|
---|
1171 |
|
---|
1172 | if (arg_gt == 1) {
|
---|
1173 | // check if there are more than 10 sections containing text to be expanded -
|
---|
1174 | // if there are output warning message - this isn't a great way to do this
|
---|
1175 | // since the sections may be very large or very small - one day I'll fix it
|
---|
1176 | // -- Stefan.
|
---|
1177 | int seccount = 0;
|
---|
1178 | while (sechere != secend) {
|
---|
1179 | int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
|
---|
1180 | if (shastxt == 1) ++seccount;
|
---|
1181 | if (seccount > 10) break;
|
---|
1182 | ++sechere;
|
---|
1183 | }
|
---|
1184 | if (seccount > 10) {
|
---|
1185 | // more than 10 sections so output warning message and text
|
---|
1186 | // for current section only
|
---|
1187 | textout << outconvert << disp << "<div class=\"warning\">_document:textltwarning_</div>\n";
|
---|
1188 |
|
---|
1189 | output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
|
---|
1190 | OID, highlight, hastxt, wanttext, collection,
|
---|
1191 | collectproto, browsers, disp, outconvert, textout, logout, args);
|
---|
1192 |
|
---|
1193 | }
|
---|
1194 | else arg_gt = 2;
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | if (arg_gt == 2) {
|
---|
1198 | // get the text for each section
|
---|
1199 | sechere = inforesponse.docInfo.begin();
|
---|
1200 | int count = 0;
|
---|
1201 | while (sechere != secend) {
|
---|
1202 | textout << outconvert << disp << "\n<p><a name=" << (*sechere).OID << "></a>\n";
|
---|
1203 |
|
---|
1204 | int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
|
---|
1205 |
|
---|
1206 | output_text (*sechere, formatlistptr, queryresponse.termInfo,
|
---|
1207 | (*sechere).OID, highlight, shastxt, wanttext, collection,
|
---|
1208 | collectproto, browsers, disp, outconvert, textout, logout, args);
|
---|
1209 | ++count;
|
---|
1210 | ++sechere;
|
---|
1211 | }
|
---|
1212 | }
|
---|
1213 | }
|
---|
1214 | }
|
---|
1215 | textout << outconvert << "</div>\n";
|
---|
1216 | delete formatlistptr;
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | void documentaction::set_arrow_macros (cgiargsclass &args, recptproto *collectproto,
|
---|
1220 | displayclass &disp, ostream &logout) {
|
---|
1221 |
|
---|
1222 | text_tset metadata;
|
---|
1223 | FilterResponse_t response;
|
---|
1224 | FilterResponse_t presponse;
|
---|
1225 |
|
---|
1226 | int haschildren = 0;
|
---|
1227 | text_tarray next_siblings;
|
---|
1228 | text_t previous_sibling;
|
---|
1229 | text_t &arg_d = args["d"];
|
---|
1230 |
|
---|
1231 | // get info on current section
|
---|
1232 | metadata.insert("haschildren");
|
---|
1233 | if (!get_info(arg_d, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
|
---|
1234 | logout << "error 1 in documentaction::set_arrow_macros\n";
|
---|
1235 | return;
|
---|
1236 | }
|
---|
1237 | haschildren = response.docInfo[0].metadata["haschildren"].values[0].getint();
|
---|
1238 |
|
---|
1239 | // get OIDs of next and previous siblings of current section and
|
---|
1240 | // all it's parents
|
---|
1241 | int parentcount = countchar(arg_d.begin(), arg_d.end(), '.');
|
---|
1242 | text_t thisoid = arg_d;
|
---|
1243 | while (parentcount > 0) {
|
---|
1244 | get_children (get_parent(thisoid), args["c"], args["l"], metadata, false,
|
---|
1245 | collectproto, response, logout);
|
---|
1246 | ResultDocInfo_tarray::iterator this_sibling = response.docInfo.begin();
|
---|
1247 | ResultDocInfo_tarray::iterator last_sibling = response.docInfo.end();
|
---|
1248 | bool first = true;
|
---|
1249 | while (this_sibling != last_sibling) {
|
---|
1250 | if ((*this_sibling).OID == thisoid) {
|
---|
1251 | if (!first && next_siblings.empty()) {
|
---|
1252 | previous_sibling = (*(this_sibling-1)).OID;
|
---|
1253 | int section_has_children = (*(this_sibling-1)).metadata["haschildren"].values[0].getint();
|
---|
1254 | // if previous sibling has children we need to recurse
|
---|
1255 | // down to the last descendant
|
---|
1256 | while (section_has_children) {
|
---|
1257 | get_children (previous_sibling, args["c"], args["l"], metadata, false,
|
---|
1258 | collectproto, presponse, logout);
|
---|
1259 | if (!presponse.docInfo.empty()) {
|
---|
1260 | ResultDocInfo_tarray::iterator it = presponse.docInfo.end() - 1;
|
---|
1261 | previous_sibling = (*it).OID;
|
---|
1262 | section_has_children = (*it).metadata["haschildren"].values[0].getint();
|
---|
1263 | } else {
|
---|
1264 | section_has_children = 0; // this should never happen
|
---|
1265 | }
|
---|
1266 | }
|
---|
1267 | }
|
---|
1268 |
|
---|
1269 | if ((this_sibling+1) != last_sibling) {
|
---|
1270 | next_siblings.push_back((*(this_sibling+1)).OID);
|
---|
1271 | } else {
|
---|
1272 | next_siblings.push_back("");
|
---|
1273 | }
|
---|
1274 | break;
|
---|
1275 | }
|
---|
1276 | ++this_sibling;
|
---|
1277 | first = false;
|
---|
1278 | }
|
---|
1279 | thisoid = get_parent(thisoid);
|
---|
1280 | --parentcount;
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | // work out values for next link
|
---|
1284 | if (haschildren) {
|
---|
1285 | #ifndef DOCHANLE
|
---|
1286 | disp.setmacro ("httpnextarrow", "document", "_httpdocument_&cl=" + args["cl"] +
|
---|
1287 | "&d=" + arg_d + ".fc");
|
---|
1288 | #else
|
---|
1289 | disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+arg_d + ".fc)";
|
---|
1290 |
|
---|
1291 | #endif
|
---|
1292 |
|
---|
1293 | } else {
|
---|
1294 | text_tarray::const_iterator h = next_siblings.begin();
|
---|
1295 | text_tarray::const_iterator e = next_siblings.end();
|
---|
1296 | while (h != e) {
|
---|
1297 | if (!(*h).empty()) {
|
---|
1298 | #ifndef DOCHANLE
|
---|
1299 | disp.setmacro ("httpnextarrow", "document", "_httpdocument_&cl=" + args["cl"] +
|
---|
1300 | "&d=" + *h);
|
---|
1301 | #else
|
---|
1302 | disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+*h+")";
|
---|
1303 |
|
---|
1304 | #endif
|
---|
1305 |
|
---|
1306 | break;
|
---|
1307 | }
|
---|
1308 | ++h;
|
---|
1309 | }
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | // work out value for previous link
|
---|
1313 | if (!previous_sibling.empty()) {
|
---|
1314 | #ifndef DOCHANDLE
|
---|
1315 | disp.setmacro ("httpprevarrow", "document", "_httpdocument_&cl=" + args["cl"] +
|
---|
1316 | "&d=" + previous_sibling);
|
---|
1317 | #else
|
---|
1318 | disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+ previous_sibling+")");
|
---|
1319 |
|
---|
1320 | #endif
|
---|
1321 |
|
---|
1322 | } else {
|
---|
1323 | if (countchar(arg_d.begin(), arg_d.end(), '.')) {
|
---|
1324 | #ifndef DOCHANDLE
|
---|
1325 | disp.setmacro ("httpprevarrow", "document", "_httpdocument_&cl=" + args["cl"] +
|
---|
1326 | "&d=" + get_parent(arg_d));
|
---|
1327 | #else
|
---|
1328 | disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+get_parent(arg_d)+")");
|
---|
1329 |
|
---|
1330 | #endif
|
---|
1331 |
|
---|
1332 | }
|
---|
1333 | }
|
---|
1334 | }
|
---|