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