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 "recptprototools.h"
|
---|
30 | #include "OIDtools.h"
|
---|
31 | #include "querytools.h"
|
---|
32 | #include "unitool.h"
|
---|
33 | #include "gsdltools.h"
|
---|
34 | #include "highlighttext.h"
|
---|
35 | #include "browsetoolsclass.h"
|
---|
36 |
|
---|
37 | documentaction::documentaction () {
|
---|
38 | recpt = NULL;
|
---|
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 |
|
---|
187 | bool documentaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
|
---|
188 | recptprotolistclass *protos, ostream &logout) {
|
---|
189 |
|
---|
190 | if(!args["d"].empty())
|
---|
191 | {
|
---|
192 | text_t docTop;
|
---|
193 | get_top(args["d"],docTop);
|
---|
194 |
|
---|
195 | recptproto* collectproto = protos->getrecptproto (args["c"], logout);
|
---|
196 | if (collectproto != NULL)
|
---|
197 | {
|
---|
198 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
|
---|
199 |
|
---|
200 | if(cinfo->authenticate == "document")
|
---|
201 | {
|
---|
202 | // both are either commented out or uncomment and are empty
|
---|
203 | if (cinfo->public_documents.empty() && cinfo->private_documents.empty())
|
---|
204 | {
|
---|
205 | //deny everything
|
---|
206 | args["uan"] = "1";
|
---|
207 | args["ug"] = cinfo->auth_group;
|
---|
208 | }
|
---|
209 |
|
---|
210 | // both public_documents and private_documents are turned on !
|
---|
211 | else if (!cinfo->public_documents.empty() && !cinfo->private_documents.empty())
|
---|
212 | {
|
---|
213 | //deny everything
|
---|
214 | args["uan"] = "1";
|
---|
215 | args["ug"] = cinfo->auth_group;
|
---|
216 | }
|
---|
217 |
|
---|
218 | // if public_documents is set but this document isn't
|
---|
219 | // listed in it we need to authenticate
|
---|
220 | else if ((!cinfo->public_documents.empty()) &&
|
---|
221 | (cinfo->public_documents.find(docTop) == cinfo->public_documents.end()))
|
---|
222 | {
|
---|
223 | args["uan"] = "1";
|
---|
224 | args["ug"] = cinfo->auth_group;
|
---|
225 | }
|
---|
226 |
|
---|
227 | // if private_documents is set and this document is
|
---|
228 | // listed in it we need to authenticate
|
---|
229 | else if ((!cinfo->private_documents.empty()) &&
|
---|
230 | (cinfo->private_documents.find(docTop) != cinfo->private_documents.end()))
|
---|
231 | {
|
---|
232 | args["uan"] = "1";
|
---|
233 | args["ug"] = cinfo->auth_group;
|
---|
234 | }
|
---|
235 |
|
---|
236 | }
|
---|
237 | }
|
---|
238 | }
|
---|
239 | // check gc argument
|
---|
240 | int arg_gc = args.getintarg("gc");
|
---|
241 | if (arg_gc < 0 || arg_gc > 2) {
|
---|
242 | logout << "Warning: \"gc\" argument out of range (" << arg_gc << ")\n";
|
---|
243 | cgiarginfo *gcinfo = argsinfo.getarginfo ("gc");
|
---|
244 | if (gcinfo != NULL) args["gc"] = gcinfo->argdefault;
|
---|
245 | }
|
---|
246 |
|
---|
247 | // check gt argument (may be either 0, 1 or 2)
|
---|
248 | int arg_gt = args.getintarg("gt");
|
---|
249 | if (arg_gt != 0 && arg_gt != 1 && arg_gt != 2) {
|
---|
250 | logout << "Warning: \"gt\" argument out of range (" << arg_gt << ")\n";
|
---|
251 | cgiarginfo *gtinfo = argsinfo.getarginfo ("gt");
|
---|
252 | if (gtinfo != NULL) args["gt"] = gtinfo->argdefault;
|
---|
253 | }
|
---|
254 |
|
---|
255 | // check hl argument
|
---|
256 | int arg_hl = args.getintarg("hl");
|
---|
257 | if (arg_hl < 0 || arg_hl > 2) {
|
---|
258 | logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n";
|
---|
259 | cgiarginfo *hlinfo = argsinfo.getarginfo ("hl");
|
---|
260 | if (hlinfo != NULL) args["hl"] = hlinfo->argdefault;
|
---|
261 | }
|
---|
262 |
|
---|
263 | // check x argument
|
---|
264 | int arg_x = args.getintarg("x");
|
---|
265 | if (arg_x != 0 && arg_x != 1) {
|
---|
266 | logout << "Warning: \"x\" argument out of range (" << arg_x << ")\n";
|
---|
267 | cgiarginfo *xinfo = argsinfo.getarginfo ("x");
|
---|
268 | if (xinfo != NULL) args["x"] = xinfo->argdefault;
|
---|
269 | }
|
---|
270 |
|
---|
271 | //checks whether rd arg is valid
|
---|
272 | int arg_rd = args.getintarg("rd");
|
---|
273 | if (arg_rd != 0 && arg_rd != 1) {
|
---|
274 | logout << "Warning: \"rd\" argument out of range (" << arg_rd << ")\n";
|
---|
275 | cgiarginfo *rdinfo = argsinfo.getarginfo ("rd");
|
---|
276 | if (rdinfo != NULL) args["rd"] = rdinfo->argdefault;
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 | return true;
|
---|
281 | }
|
---|
282 |
|
---|
283 | void documentaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
|
---|
284 | response_t &response,text_t &response_data,
|
---|
285 | ostream &logout) {
|
---|
286 |
|
---|
287 | if ((args["il"] == "w") && (!args["d"].empty())) {
|
---|
288 |
|
---|
289 | recptproto* collectproto = protos->getrecptproto (args["c"], logout);
|
---|
290 | if (collectproto != NULL) {
|
---|
291 |
|
---|
292 | text_tset metadata;
|
---|
293 | FilterResponse_t filt_response;
|
---|
294 | text_t top;
|
---|
295 |
|
---|
296 | metadata.insert ("URL");
|
---|
297 |
|
---|
298 | // get metadata for parent document
|
---|
299 | get_top (args["d"], top);
|
---|
300 | if (get_info (top, args["c"], args["l"], metadata, false, collectproto, filt_response, logout)) {
|
---|
301 | text_t url = filt_response.docInfo[0].metadata["URL"].values[0];
|
---|
302 |
|
---|
303 | response = location;
|
---|
304 | response_data = url;
|
---|
305 | return;
|
---|
306 | } else {
|
---|
307 | // error, no URL
|
---|
308 | logout << "Error: documentaction::get_cgihead_info failed on get_info" << endl;
|
---|
309 | }
|
---|
310 | }
|
---|
311 | }
|
---|
312 | response = content;
|
---|
313 | response_data = "text/html";
|
---|
314 | }
|
---|
315 |
|
---|
316 | // set_widthtspace calculates how wide the spaces in the nav bar should
|
---|
317 | // be and sets the appropriate macro
|
---|
318 | void documentaction::set_spacemacro (displayclass &disp, FilterResponse_t &response,
|
---|
319 | bool has_search_button) {
|
---|
320 |
|
---|
321 | text_t width;
|
---|
322 | int twidth, swidth, iwidth = 0;
|
---|
323 |
|
---|
324 | int numc = response.docInfo.size();
|
---|
325 | ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
|
---|
326 | ResultDocInfo_tarray::iterator docend = response.docInfo.end();
|
---|
327 |
|
---|
328 | disp.expandstring (displayclass::defaultpackage, "_pagewidth_", width);
|
---|
329 | twidth = width.getint();
|
---|
330 |
|
---|
331 | if (has_search_button) {
|
---|
332 | disp.expandstring ("query", "_searchwidth_", width);
|
---|
333 | iwidth += width.getint();
|
---|
334 | } else {
|
---|
335 | numc -= 1;
|
---|
336 | }
|
---|
337 |
|
---|
338 | while (dochere != docend) {
|
---|
339 | const text_t &title = (*dochere).metadata["Title"].values[0];
|
---|
340 |
|
---|
341 | disp.expandstring ("document", "_" + title + "width_", width);
|
---|
342 | if (width == ("_" + title + "width_")) {
|
---|
343 | disp.expandstring ("document", "_defaultwidth_", width);
|
---|
344 | }
|
---|
345 | iwidth += width.getint();
|
---|
346 | ++dochere;
|
---|
347 | }
|
---|
348 |
|
---|
349 | if ((twidth - iwidth) < numc) swidth = 2;
|
---|
350 | else {
|
---|
351 | swidth = twidth - iwidth;
|
---|
352 | if (numc > 0) swidth = swidth / numc;
|
---|
353 | }
|
---|
354 | disp.setmacro ("widthtspace", displayclass::defaultpackage, swidth);
|
---|
355 | }
|
---|
356 |
|
---|
357 | // set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros
|
---|
358 | // reponse contains 1 metadata field (Title)
|
---|
359 | void documentaction::set_navbarmacros (displayclass &disp, FilterResponse_t &response,
|
---|
360 | bool has_search_button, cgiargsclass &args,
|
---|
361 | ColInfoResponse_t &cinfo) {
|
---|
362 |
|
---|
363 |
|
---|
364 | bool use_pulldown = false;
|
---|
365 | text_tmap::iterator it = cinfo.format.find("NavigationBar");
|
---|
366 | if (it != cinfo.format.end()) {
|
---|
367 | if (it->second == "pulldown") {
|
---|
368 | use_pulldown = true;
|
---|
369 | }
|
---|
370 | }
|
---|
371 |
|
---|
372 | text_t topparent;
|
---|
373 | text_t &arg_d = args["d"];
|
---|
374 | text_t navigationbar = "<!-- Navigation Bar -->\n";
|
---|
375 |
|
---|
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 | if (has_search_button) {
|
---|
383 | // search uses its own navtab, as it may be suppressed based on other args
|
---|
384 | navigationbar += "_navtabsearch_";
|
---|
385 | if (args["a"] == "q") {
|
---|
386 | navigationbar += "(selected)";
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | if (has_search_button || numc == 0) navigationbar += "_navbarspacer_";
|
---|
391 |
|
---|
392 | bool first = true;
|
---|
393 | while (dochere != docend) {
|
---|
394 | if (!first) navigationbar += "_navbarspacer_";
|
---|
395 |
|
---|
396 | text_t title = (*dochere).metadata["Title"].values[0];
|
---|
397 |
|
---|
398 | navigationbar += "_navtab_(_httpbrowse"+(*dochere).OID+"_,"+title;
|
---|
399 | // if we are at this classifier
|
---|
400 | if (arg_d.empty() && ((*dochere).OID == topparent)) {
|
---|
401 | // don't link to this classifier as it is the current one
|
---|
402 | navigationbar += ",selected";
|
---|
403 | }
|
---|
404 | navigationbar += ")";
|
---|
405 |
|
---|
406 | // set the _httpbrowseCLX_ macro for this classification
|
---|
407 | disp.setmacro ("httpbrowse" + (*dochere).OID, displayclass::defaultpackage, "_httpdocument_&cl=" + (*dochere).OID);
|
---|
408 | ++dochere;
|
---|
409 | first = false;
|
---|
410 | }
|
---|
411 |
|
---|
412 | navigationbar += "_dynamicclassifiernavbarentries_";
|
---|
413 | navigationbar += "\n<!-- End of Navigation Bar -->\n";
|
---|
414 |
|
---|
415 | } else {
|
---|
416 |
|
---|
417 | navigationbar = "<form method=\"get\" name=\"navform\">\n";
|
---|
418 | navigationbar += "<select name=\"navbar\" onChange=\"location.href=";
|
---|
419 | navigationbar += "document.navform.navbar.options[document.navform.navbar.selectedIndex].value\">\n";
|
---|
420 |
|
---|
421 | if (args["a"] != "q" && args["cl"].empty()) {
|
---|
422 | navigationbar += "<option value=\"\" selected>_textselectpage_</option>\n";
|
---|
423 | }
|
---|
424 |
|
---|
425 | if (has_search_button) {
|
---|
426 | navigationbar += "<option value=\"_httpquery_\"";
|
---|
427 | if (args["a"] == "q") {
|
---|
428 | navigationbar += " selected";
|
---|
429 | }
|
---|
430 | navigationbar += ">_labelSearch_</option>\n";
|
---|
431 | }
|
---|
432 |
|
---|
433 | while (dochere != docend) {
|
---|
434 | text_t title = dochere->metadata["Title"].values[0];
|
---|
435 |
|
---|
436 | navigationbar += "<option value=\"_httpdocument_&cl=" + dochere->OID + "\"";
|
---|
437 | if (topparent == dochere->OID) {
|
---|
438 | navigationbar += " selected";
|
---|
439 | }
|
---|
440 | navigationbar += ">_navlinktitle_(" + title + ")</option>\n";
|
---|
441 | ++dochere;
|
---|
442 | }
|
---|
443 |
|
---|
444 | navigationbar += "</select>\n";
|
---|
445 | navigationbar += "</form>\n";
|
---|
446 | }
|
---|
447 |
|
---|
448 | disp.setmacro ("navigationbar", displayclass::defaultpackage, navigationbar);
|
---|
449 | }
|
---|
450 |
|
---|
451 | // define all the macros which might be used by other actions
|
---|
452 | // to produce pages.
|
---|
453 | void documentaction::define_external_macros (displayclass &disp, cgiargsclass &args,
|
---|
454 | recptprotolistclass *protos, ostream &logout) {
|
---|
455 |
|
---|
456 | // define_external_macros sets the following macros:
|
---|
457 |
|
---|
458 | // _navigationbar_ this is the navigation bar containing the search button
|
---|
459 | // and any classification buttons - it goes at the top of
|
---|
460 | // most pages. for now we're assuming that there'll always
|
---|
461 | // be a search button - we should probably check that there
|
---|
462 | // is a query action before making this assumption
|
---|
463 |
|
---|
464 | // _httpbrowseXXX_ the http macros for each classification (i.e. if there
|
---|
465 | // are Title and Creator classifications _httpbrowseTitle_
|
---|
466 | // and _httpbrowseCreator_ will be set
|
---|
467 |
|
---|
468 | // _widthtspace_ the width of the spacers between buttons in navigation
|
---|
469 | // bar
|
---|
470 |
|
---|
471 | // _httpdocument_ has '&f=1' added if displaying document inside a frame
|
---|
472 |
|
---|
473 | // _gsdltop_ macro to replace _top targets with
|
---|
474 |
|
---|
475 | // _httppagehome_ overridden home url if html collections have own homepage
|
---|
476 |
|
---|
477 | // _usability_ macros for remote usability reporting: if
|
---|
478 | // _usabinterface_ "format Usability [multi|textonly|stepwise]" is in
|
---|
479 | // _usabilityscript_ collect.cfg
|
---|
480 |
|
---|
481 | // _versionnnum_ greenstone version number (hard-coded)
|
---|
482 | // must have a valid collection server to continue
|
---|
483 |
|
---|
484 | text_t &collection = args["c"];
|
---|
485 | if (collection.empty()) return;
|
---|
486 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
487 | if (collectproto == NULL) return;
|
---|
488 |
|
---|
489 | if (recpt == NULL) {
|
---|
490 | logout << "ERROR (documentaction::define_external_macros): This action does not contain\n"
|
---|
491 | << " information about any receptionists. The method set_receptionist was\n"
|
---|
492 | << " probably not called from the module which instantiated this action.\n";
|
---|
493 | return;
|
---|
494 | }
|
---|
495 |
|
---|
496 | outconvertclass text_t2ascii;
|
---|
497 | comerror_t err;
|
---|
498 | InfoFiltersResponse_t filterinfo;
|
---|
499 | FilterResponse_t response;
|
---|
500 | text_tset metadata;
|
---|
501 |
|
---|
502 | // get info on current collection and load up formatinfo
|
---|
503 | // I'd prefer not to do this here as we're getting
|
---|
504 | // collection info every time (and probably also getting
|
---|
505 | // it in other places some of the time) - One day I'll
|
---|
506 | // fix it ... maybe - Stefan.
|
---|
507 | ColInfoResponse_t cinfo;
|
---|
508 |
|
---|
509 | collectproto->get_collectinfo (collection, cinfo, err, logout);
|
---|
510 | load_formatinfo (cinfo.format, args.getintarg("gt"));
|
---|
511 | // ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
|
---|
512 | // if (cinfo == NULL) {
|
---|
513 | // logout << "ERROR (documentaction::define_external_macros): get_collectinfo_ptr returned NULL\n";
|
---|
514 | // return;
|
---|
515 | // }
|
---|
516 | //load_formatinfo (cinfo->format, args.getintarg("gt"));
|
---|
517 |
|
---|
518 | if (formatinfo.DocumentUseHTML) {
|
---|
519 |
|
---|
520 | // frame stuff
|
---|
521 | if (args["fc"] == "1") {
|
---|
522 | text_t httpdocument;
|
---|
523 | disp.expandstring (displayclass::defaultpackage, "_httpdocument_", httpdocument);
|
---|
524 | httpdocument += "&f=1";
|
---|
525 | disp.setmacro ("httpdocument", displayclass::defaultpackage, httpdocument);
|
---|
526 | disp.setmacro ("gsdltop", displayclass::defaultpackage, "documenttop");
|
---|
527 | formatinfo.DocumentText = "[Text]";
|
---|
528 | }
|
---|
529 | text_tmap::iterator it = cinfo.format.find ("homepage");
|
---|
530 | if (it != cinfo.format.end()) {
|
---|
531 | text_t httppagehome;
|
---|
532 | if (get_link (args, protos, (*it).second, httppagehome, logout))
|
---|
533 | disp.setmacro ("httppagehome", displayclass::defaultpackage, httppagehome);
|
---|
534 | }
|
---|
535 | }
|
---|
536 |
|
---|
537 | // don't want navigation bar if page is 'detached'
|
---|
538 | if (!args.getintarg("x")) {
|
---|
539 |
|
---|
540 | collectproto->get_filterinfo (collection, filterinfo, err, logout);
|
---|
541 | if (err == noError) {
|
---|
542 | // check that there's a browse filter
|
---|
543 | if (filterinfo.filterNames.find ("BrowseFilter") != filterinfo.filterNames.end()) {
|
---|
544 |
|
---|
545 | metadata.insert ("Title");
|
---|
546 | bool getParents = false;
|
---|
547 | get_children ("", collection, args["l"], metadata, getParents, collectproto, response, logout);
|
---|
548 |
|
---|
549 | bool has_search_button = true;
|
---|
550 | collectproto->is_searchable(collection, has_search_button, err, logout);
|
---|
551 | if (err != noError) has_search_button = false;
|
---|
552 |
|
---|
553 | // calculate width of spacers and set _widthtspace_ macro
|
---|
554 | if (args.getintarg("v") == 0) set_spacemacro (disp, response, has_search_button);
|
---|
555 |
|
---|
556 | // set _navigationbar_ macro
|
---|
557 | set_navbarmacros (disp, response, has_search_button, args, cinfo);
|
---|
558 |
|
---|
559 | }
|
---|
560 | } else {
|
---|
561 | logout << text_t2ascii
|
---|
562 | << "Error (documentaction::define_external_macros()) in call to get_filterinfo() "
|
---|
563 | << get_comerror_string (err);
|
---|
564 | }
|
---|
565 | }
|
---|
566 |
|
---|
567 | // send feedback button and pages
|
---|
568 | text_tmap::iterator usability = cinfo.format.find("Usability");
|
---|
569 | if(usability!=cinfo.format.end()){
|
---|
570 | disp.setmacro("usability",displayclass::defaultpackage,"_usablink_");
|
---|
571 | disp.setmacro("usabinterface",displayclass::defaultpackage,("_usab"+(*usability).second+"_"));
|
---|
572 | disp.setmacro("usabilityscript", displayclass::defaultpackage, "_usabshowscript_");
|
---|
573 | }
|
---|
574 |
|
---|
575 | // version num
|
---|
576 | disp.setmacro("versionnum", displayclass::defaultpackage, GSDL_VERSION);
|
---|
577 |
|
---|
578 | }
|
---|
579 |
|
---|
580 | bool documentaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
|
---|
581 | const text_t &inlink, text_t &outlink, ostream &logout) {
|
---|
582 |
|
---|
583 | FilterResponse_t response;
|
---|
584 | text_tset metadata;
|
---|
585 | metadata.insert ("section");
|
---|
586 |
|
---|
587 | // check current collection first
|
---|
588 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
589 |
|
---|
590 | if (get_info (inlink, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
|
---|
591 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
592 | #ifndef DOCHANDLE
|
---|
593 | outlink = "_httpdocument_&d=" + response.docInfo[0].metadata["section"].values[0];
|
---|
594 | #else
|
---|
595 | outlink = "_httpdocumenthandle_("+args["c"]+","+response.docInfo[0].metadata["section"].values[0]+")";
|
---|
596 | #endif
|
---|
597 |
|
---|
598 | return true;
|
---|
599 | }
|
---|
600 | }
|
---|
601 |
|
---|
602 | // check all the other enabled collections
|
---|
603 |
|
---|
604 | if (args["ccs"] == "1" && !args["cc"].empty()) {
|
---|
605 | text_tarray collections;
|
---|
606 | splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
|
---|
607 |
|
---|
608 | text_tarray::const_iterator col_here = collections.begin();
|
---|
609 | text_tarray::const_iterator col_end = collections.end();
|
---|
610 |
|
---|
611 | while (col_here != col_end) {
|
---|
612 |
|
---|
613 | // don't need to check current collection again
|
---|
614 | if (*col_here == args["c"]) {++col_here; continue;}
|
---|
615 |
|
---|
616 | collectproto = protos->getrecptproto (*col_here, logout);
|
---|
617 |
|
---|
618 | if (get_info (inlink, *col_here, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
619 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
620 | #ifndef DOCHANDLE
|
---|
621 | outlink = "_httpdocument_&c=" + *col_here + "&d=" +
|
---|
622 | response.docInfo[0].metadata["section"].values[0];
|
---|
623 | #else
|
---|
624 | outlink = "_httpdocumenthandle_("+*col_here+","+response.docInfo[0].metadata["section"].values[0]+")";
|
---|
625 | #endif
|
---|
626 |
|
---|
627 | return true;
|
---|
628 | }
|
---|
629 | }
|
---|
630 | ++col_here;
|
---|
631 | }
|
---|
632 | }
|
---|
633 | return false;
|
---|
634 | }
|
---|
635 |
|
---|
636 | void documentaction::load_formatinfo (const text_tmap &colformat, int gt) {
|
---|
637 |
|
---|
638 | formatinfo.clear();
|
---|
639 | text_tmap::const_iterator format_here = colformat.begin();
|
---|
640 | text_tmap::const_iterator format_end = colformat.end();
|
---|
641 |
|
---|
642 | while (format_here != format_end) {
|
---|
643 | if (((*format_here).first == "DocumentImages") &&
|
---|
644 | ((*format_here).second == "true"))
|
---|
645 | formatinfo.DocumentImages = true;
|
---|
646 | else if (((*format_here).first == "DocumentTitles") &&
|
---|
647 | ((*format_here).second == "false"))
|
---|
648 | formatinfo.DocumentTitles = false;
|
---|
649 | else if ((*format_here).first == "DocumentHeading")
|
---|
650 | formatinfo.DocumentHeading = (*format_here).second;
|
---|
651 | else if (((*format_here).first == "DocumentContents") &&
|
---|
652 | ((*format_here).second == "false"))
|
---|
653 | formatinfo.DocumentContents = false;
|
---|
654 | else if (((*format_here).first == "DocumentArrowsBottom") &&
|
---|
655 | ((*format_here).second == "false"))
|
---|
656 | formatinfo.DocumentArrowsBottom = false;
|
---|
657 | else if (((*format_here).first == "DocumentArrowsTop") &&
|
---|
658 | ((*format_here).second == "true"))
|
---|
659 | formatinfo.DocumentArrowsTop = true;
|
---|
660 | else if ((*format_here).first == "DocumentButtons")
|
---|
661 | splitchar ((*format_here).second.begin(), (*format_here).second.end(),
|
---|
662 | '|', formatinfo.DocumentButtons);
|
---|
663 | else if ((*format_here).first == "DocumentText")
|
---|
664 | formatinfo.DocumentText = (*format_here).second;
|
---|
665 | else if ((*format_here).first == "RelatedDocuments")
|
---|
666 | formatinfo.RelatedDocuments = (*format_here).second;
|
---|
667 | else if (((*format_here).first == "DocumentUseHTML") &&
|
---|
668 | ((*format_here).second == "true"))
|
---|
669 | formatinfo.DocumentUseHTML = true;
|
---|
670 | else if (((*format_here).first == "AllowExtendedOptions") &&
|
---|
671 | ((*format_here).second == "true"))
|
---|
672 | formatinfo.AllowExtendedOptions = true;
|
---|
673 | else
|
---|
674 | formatinfo.formatstrings[(*format_here).first] = (*format_here).second;
|
---|
675 |
|
---|
676 | ++format_here;
|
---|
677 | }
|
---|
678 |
|
---|
679 | // never want arrows when text is expanded
|
---|
680 | if (gt) {
|
---|
681 | formatinfo.DocumentArrowsBottom = false;
|
---|
682 | formatinfo.DocumentArrowsTop = false;
|
---|
683 | }
|
---|
684 | }
|
---|
685 |
|
---|
686 |
|
---|
687 | // define all the macros which are related to pages generated
|
---|
688 | // by this action. we also load up the formatinfo structure
|
---|
689 | // here (it's used in do_action as well as here)
|
---|
690 | void documentaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
691 | recptprotolistclass *protos, ostream &logout) {
|
---|
692 |
|
---|
693 | // define_internal_macros sets the following macros:
|
---|
694 |
|
---|
695 | // _pagetitle_ the title to be displayed at the top of the browser window
|
---|
696 |
|
---|
697 | // _imagethispage_ the title image to be displayed at top right of page
|
---|
698 |
|
---|
699 | // _navarrowsbottom_ this may be overridden to "" when format option
|
---|
700 | // DocumentArrowsBottom is false
|
---|
701 |
|
---|
702 | // _navarrowstop_ likewise for DocumentArrowsTop
|
---|
703 |
|
---|
704 | // _httpprevarrow_ links to next and previous sections of document - used
|
---|
705 | // _httpnextarrow_ by DocumentArrowsBottom
|
---|
706 |
|
---|
707 | // _header_ the header macro is overridden if we're not at a top level
|
---|
708 | // classification to remove the title block
|
---|
709 |
|
---|
710 | // _thisOID_ the OID (directory) of the current document - this corresponds
|
---|
711 | // to the archivedir metadata element
|
---|
712 |
|
---|
713 | // _documentheader_ Custom header info for the specified document
|
---|
714 | // must have a valid collection server to continue
|
---|
715 |
|
---|
716 | text_t &collection = args["c"];
|
---|
717 | if (collection.empty()) return;
|
---|
718 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
719 | if (collectproto == NULL) return;
|
---|
720 |
|
---|
721 | text_tset metadata;
|
---|
722 | FilterResponse_t response;
|
---|
723 | text_t &arg_d = args["d"];
|
---|
724 | text_t &arg_cl = args["cl"];
|
---|
725 |
|
---|
726 | if (!formatinfo.DocumentArrowsBottom) {
|
---|
727 | disp.setmacro("navarrowsbottom", "document", "");
|
---|
728 | } else if (!formatinfo.DocumentArrowsBottom) {
|
---|
729 | disp.setmacro("navarrowstop", "document", "");
|
---|
730 | }
|
---|
731 |
|
---|
732 | if (!arg_d.empty() && (formatinfo.DocumentArrowsBottom || formatinfo.DocumentArrowsTop)) {
|
---|
733 | // set _httpprevarrow_ and _httpnextarrow_
|
---|
734 | set_arrow_macros (args, collectproto, disp, logout);
|
---|
735 | }
|
---|
736 |
|
---|
737 | metadata.insert ("Title");
|
---|
738 | metadata.insert ("gs.DocumentHeader");
|
---|
739 | metadata.insert ("DocumentHeader");
|
---|
740 |
|
---|
741 | bool fulltoc = false;
|
---|
742 |
|
---|
743 | if (args["cl"] != "search") {
|
---|
744 | // see if there's a FullTOC string
|
---|
745 | text_t cl_top, full_toc;
|
---|
746 | get_top (arg_cl, cl_top);
|
---|
747 | if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
|
---|
748 | if (full_toc == "true") fulltoc = true;
|
---|
749 | }
|
---|
750 |
|
---|
751 | if (!arg_d.empty() && !fulltoc) {
|
---|
752 | // we're at document level
|
---|
753 |
|
---|
754 | metadata.insert ("archivedir");
|
---|
755 |
|
---|
756 | comerror_t err;
|
---|
757 | OptionValue_tarray options;
|
---|
758 | // we need to do the query again for the z3950proto
|
---|
759 | if (collectproto->get_protocol_name(err)=="z3950proto") {
|
---|
760 | OptionValue_t opt;
|
---|
761 | opt.name="Term";opt.value=args["q"];options.push_back(opt);
|
---|
762 | opt.name="QueryType";
|
---|
763 | opt.value=(args.getintarg("t")) ? "ranked" : "boolean";
|
---|
764 | options.push_back(opt);
|
---|
765 | opt.name="Index";opt.value=args["h"];options.push_back(opt);
|
---|
766 | }
|
---|
767 |
|
---|
768 | //do not display relation metadata
|
---|
769 | disp.setmacro ("relateddoc", "document", "");
|
---|
770 |
|
---|
771 | //if preferences indicate relevant docs should be collected
|
---|
772 | //and there is no particular format specified then display
|
---|
773 | //this default format.
|
---|
774 | if(args["rd"] == "1" && formatinfo.RelatedDocuments.empty()){
|
---|
775 |
|
---|
776 | text_t relation = g_EmptyText; //string for displaying relation metadata
|
---|
777 |
|
---|
778 | //call function in formattools.cpp which will return the text of the
|
---|
779 | //related documents in a vertical list. This is the default format.
|
---|
780 |
|
---|
781 | if (get_info (arg_d, collection, args["l"], metadata, options, false, collectproto, response, logout))
|
---|
782 | relation += get_related_docs(collection, collectproto, response.docInfo[0], logout);
|
---|
783 |
|
---|
784 | //set macro to be the related document string
|
---|
785 |
|
---|
786 | disp.setmacro ("relateddoc", "document", relation);
|
---|
787 | }
|
---|
788 |
|
---|
789 |
|
---|
790 | // get metadata for this document and it's parents
|
---|
791 | if (get_info (arg_d, collection, args["l"], metadata, options,
|
---|
792 | true, collectproto, response, logout)) {
|
---|
793 |
|
---|
794 | disp.setmacro ("header", "document", "_textheader_");
|
---|
795 | text_tarray pagetitlearray;
|
---|
796 | if (!response.docInfo[0].metadata["Title"].values[0].empty())
|
---|
797 | pagetitlearray.push_back (response.docInfo[0].metadata["Title"].values[0]);
|
---|
798 |
|
---|
799 | if (args["gt"] != "1") {
|
---|
800 | MetadataInfo_t *parenttitle = response.docInfo[0].metadata["Title"].parent;
|
---|
801 | while (parenttitle != NULL) {
|
---|
802 | if (!parenttitle->values[0].empty())
|
---|
803 | pagetitlearray.push_back (parenttitle->values[0]);
|
---|
804 | parenttitle = parenttitle->parent;
|
---|
805 | }
|
---|
806 | }
|
---|
807 | reverse (pagetitlearray.begin(), pagetitlearray.end());
|
---|
808 | text_t pagetitle;
|
---|
809 | joinchar (pagetitlearray, ": ", pagetitle);
|
---|
810 | // remove html tags from the title
|
---|
811 | text_t::iterator open_tag=pagetitle.begin();
|
---|
812 | while (open_tag < pagetitle.end()) {
|
---|
813 | if (*open_tag == '<') {
|
---|
814 | text_t::iterator close_tag=open_tag+1;
|
---|
815 | text_t::iterator donechar=pagetitle.end();
|
---|
816 | while (close_tag < donechar) {
|
---|
817 | if (*close_tag == '>')
|
---|
818 | break;
|
---|
819 | ++close_tag;
|
---|
820 | }
|
---|
821 | if (close_tag < donechar) // remove this html tag, replace with space
|
---|
822 | *close_tag=' ';
|
---|
823 | pagetitle.erase(open_tag, close_tag);
|
---|
824 | }
|
---|
825 | ++open_tag;
|
---|
826 | }
|
---|
827 | disp.setmacro ("pagetitle", "document", pagetitle);
|
---|
828 |
|
---|
829 | // custom header info
|
---|
830 | text_t custom_header;
|
---|
831 | if (is_top (arg_d)) {
|
---|
832 | custom_header = response.docInfo[0].metadata["gs.DocumentHeader"].values[0];
|
---|
833 | if (custom_header.empty()) {
|
---|
834 | // try ex header
|
---|
835 | custom_header = response.docInfo[0].metadata["DocumentHeader"].values[0];
|
---|
836 | }
|
---|
837 | } else {
|
---|
838 | MetadataInfo_t *parentch = response.docInfo[0].metadata["gs.DocumentHeader"].parent;
|
---|
839 | while (parentch != NULL) {
|
---|
840 | custom_header = parentch->values[0];
|
---|
841 | parentch = parentch->parent;
|
---|
842 | }
|
---|
843 | if (custom_header.empty()) {
|
---|
844 | // try ex header
|
---|
845 | MetadataInfo_t *parentch = response.docInfo[0].metadata["DocumentHeader"].parent;
|
---|
846 | while (parentch != NULL) {
|
---|
847 | custom_header = parentch->values[0];
|
---|
848 | parentch = parentch->parent;
|
---|
849 | }
|
---|
850 | }
|
---|
851 | }
|
---|
852 | if (!custom_header.empty()) {
|
---|
853 | disp.setmacro("documentheader", "document", custom_header);
|
---|
854 | }
|
---|
855 |
|
---|
856 | if (is_top (arg_d))
|
---|
857 | disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(response.docInfo[0].metadata["archivedir"].values[0]));
|
---|
858 | else {
|
---|
859 | MetadataInfo_t *parentad = response.docInfo[0].metadata["archivedir"].parent;
|
---|
860 | text_t thisOID;
|
---|
861 | while (parentad != NULL) {
|
---|
862 | thisOID = parentad->values[0];
|
---|
863 | parentad = parentad->parent;
|
---|
864 | }
|
---|
865 | disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(thisOID));
|
---|
866 | }
|
---|
867 | }
|
---|
868 | } else {
|
---|
869 | if (!arg_cl.empty()) {
|
---|
870 |
|
---|
871 | // create the currentnodevalue macro - this is the value of the node
|
---|
872 | // in the hierarchy that is currently open.
|
---|
873 | if (get_info (arg_cl, collection, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
874 | text_t &title = response.docInfo[0].metadata["Title"].values[0];
|
---|
875 | disp.setmacro ("currentnodevalue", "document", title);
|
---|
876 | }
|
---|
877 | // get metadata for top level classification
|
---|
878 | text_t classtop;
|
---|
879 | get_top (arg_cl, classtop);
|
---|
880 | metadata.insert ("childtype");
|
---|
881 | metadata.insert ("parameters");
|
---|
882 |
|
---|
883 | if (get_info (classtop, collection, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
884 |
|
---|
885 | text_t &title = response.docInfo[0].metadata["Title"].values[0];
|
---|
886 | bool unknown = false;
|
---|
887 |
|
---|
888 | // test if we have macros defined for this classification's
|
---|
889 | // metadata name - if not we'll just display the name
|
---|
890 | text_t tmp;
|
---|
891 | text_t macroname="_label" + title + "_";
|
---|
892 | disp.expandstring ("Global", macroname, tmp);
|
---|
893 | if (tmp == macroname) unknown = true; // it wasn't expanded
|
---|
894 |
|
---|
895 | if (unknown) {
|
---|
896 | disp.setmacro ("pagetitle", "document", title);
|
---|
897 | } else {
|
---|
898 | disp.setmacro ("pagetitle", "document", macroname);
|
---|
899 | }
|
---|
900 | /* for ns4/image layout compatibility. when this is no longer
|
---|
901 | * needed, set imagethispage to _label+title+_ */
|
---|
902 | text_t titlemacroname="_titleimage" + title + "_";
|
---|
903 | disp.expandstring ("Global", titlemacroname, tmp);
|
---|
904 | if (tmp == titlemacroname) { /* _titleimage$META_ isn't defined */
|
---|
905 | if (!unknown) /* _label$META_ is defined */
|
---|
906 | disp.setmacro ("imagethispage", "document", macroname);
|
---|
907 | else
|
---|
908 | disp.setmacro ("imagethispage", "document", title);
|
---|
909 | } else { /* _titleimage$META_ is defined */
|
---|
910 | disp.setmacro ("imagethispage", "document", titlemacroname);
|
---|
911 | }
|
---|
912 |
|
---|
913 | //if the document is not a document from a collection
|
---|
914 | //we must set the macro to be an empty string
|
---|
915 | disp.setmacro ("relateddoc", "document", "");
|
---|
916 |
|
---|
917 | // Add macros specific to the Collage/Phind classifiers
|
---|
918 | text_t &childtype = response.docInfo[0].metadata["childtype"].values[0];
|
---|
919 | if (childtype == "Collage") {
|
---|
920 |
|
---|
921 | text_t::iterator a = arg_cl.begin();
|
---|
922 | text_t::iterator b = arg_cl.end();
|
---|
923 |
|
---|
924 | bool collage = true;
|
---|
925 | while (a != b) {
|
---|
926 | if (*a == 46) collage = false;
|
---|
927 | ++a;
|
---|
928 | }
|
---|
929 |
|
---|
930 | if (collage) {
|
---|
931 | disp.setmacro ("collageclassifier", "document", "_collageapplet_");
|
---|
932 |
|
---|
933 | // Next, macros that control the way the classifier is displayed
|
---|
934 | text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
|
---|
935 |
|
---|
936 | // extract key=value pairs and set as macros
|
---|
937 | text_t::iterator here = parameters.begin();
|
---|
938 | text_t::iterator end = parameters.end();
|
---|
939 | text_t key, value;
|
---|
940 |
|
---|
941 | while (here != end) {
|
---|
942 | // get the next key and value pair
|
---|
943 | here = getdelimitstr (here, end, '=', key);
|
---|
944 | here = getdelimitstr (here, end, ';', value);
|
---|
945 |
|
---|
946 | // store this key=value pair
|
---|
947 | if (!key.empty() && !value.empty()) {
|
---|
948 | disp.setmacro ("collage"+key, "document", value);
|
---|
949 | }
|
---|
950 | }
|
---|
951 |
|
---|
952 |
|
---|
953 | }
|
---|
954 | }
|
---|
955 |
|
---|
956 | if (childtype == "Phind") {
|
---|
957 |
|
---|
958 | // First, a macro to display the phind classifier
|
---|
959 | disp.setmacro ("phindclassifier", "document", "_phindapplet_");
|
---|
960 |
|
---|
961 | // Next, macros that control the way the classifier is displayed
|
---|
962 | text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
|
---|
963 |
|
---|
964 | // extract key=value pairs and set as macros
|
---|
965 | text_t::iterator here = parameters.begin();
|
---|
966 | text_t::iterator end = parameters.end();
|
---|
967 | text_t key, value;
|
---|
968 |
|
---|
969 | while (here != end) {
|
---|
970 | // get the next key and value pair
|
---|
971 | here = getdelimitstr (here, end, '=', key);
|
---|
972 | here = getdelimitstr (here, end, ';', value);
|
---|
973 |
|
---|
974 | // store this key=value pair
|
---|
975 | if (!key.empty() && !value.empty()) {
|
---|
976 | disp.setmacro (key, "document", value);
|
---|
977 | }
|
---|
978 | }
|
---|
979 | } // end if (childtype == "Phind")
|
---|
980 | }
|
---|
981 | } // end if (!arg_cl.empty()) {
|
---|
982 | }
|
---|
983 | }
|
---|
984 |
|
---|
985 |
|
---|
986 | bool documentaction::do_action(cgiargsclass &args, recptprotolistclass *protos,
|
---|
987 | browsermapclass *browsers, displayclass &disp,
|
---|
988 | outconvertclass &outconvert, ostream &textout,
|
---|
989 | ostream &logout)
|
---|
990 | {
|
---|
991 | if ((args["book"] == "flashxml") && (!args["d"].empty()))
|
---|
992 | {
|
---|
993 | return do_action_flashxml(args,protos,browsers,disp,outconvert,textout,logout);
|
---|
994 | }
|
---|
995 | else if ((args["book"] == "on") && (!args["d"].empty()))
|
---|
996 | {
|
---|
997 | return do_action_book(args,protos,browsers,disp,outconvert,textout,logout);
|
---|
998 | }
|
---|
999 | else
|
---|
1000 | {
|
---|
1001 | return do_action_html(args,protos,browsers,disp,outconvert,textout,logout);
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | //displaying the normal display when bookswitch=0(html)
|
---|
1007 | bool documentaction::do_action_html(cgiargsclass &args, recptprotolistclass *protos,
|
---|
1008 | browsermapclass *browsers, displayclass &disp,
|
---|
1009 | outconvertclass &outconvert, ostream &textout,
|
---|
1010 | ostream &logout)
|
---|
1011 | {
|
---|
1012 | // must have a valid collection server
|
---|
1013 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
1014 | if (collectproto == NULL) {
|
---|
1015 | logout << "documentaction::do_action called with NULL collectproto\n";
|
---|
1016 | textout << outconvert << disp << "_document:header_\n"
|
---|
1017 | << "Error: Attempt to get document without setting collection\n"
|
---|
1018 | << "_document:footer_\n";
|
---|
1019 | } else {
|
---|
1020 |
|
---|
1021 | text_t OID = args["d"];
|
---|
1022 | if (OID.empty()) OID = args["cl"];
|
---|
1023 | if (OID.empty()) {
|
---|
1024 | textout << outconvert << disp << "Document contains no data_document:footer_\n";
|
---|
1025 | return true;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 |
|
---|
1029 | if (formatinfo.DocumentUseHTML && !args["d"].empty()) {
|
---|
1030 |
|
---|
1031 | if (args["f"] == "1") {
|
---|
1032 | textout << outconvert << disp
|
---|
1033 | << "<html><head></head>\n"
|
---|
1034 | << "<frameset rows=\"68,*\" noresize border=0>\n"
|
---|
1035 | << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
|
---|
1036 | #ifndef DOCHANDLE
|
---|
1037 | << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d="
|
---|
1038 | << args["d"] << "\">"
|
---|
1039 | #else
|
---|
1040 | << "<frame name=\"documenttop\" frameborder=0 src=\"_httpdocumenthandle_("
|
---|
1041 | << args["c"] << "," << args["d"] << ")\">"
|
---|
1042 | #endif
|
---|
1043 | << "<noframes>\n"
|
---|
1044 | << "<p>You must have a frame enabled browser to view this.</p>\n"
|
---|
1045 | << "</noframes>\n"
|
---|
1046 | << "</frameset>\n"
|
---|
1047 | << "</html>\n";
|
---|
1048 | } else {
|
---|
1049 | output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
|
---|
1050 | }
|
---|
1051 | return true;
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 |
|
---|
1055 | textout << outconvert << disp << "_document:header_\n"
|
---|
1056 | << "_document:content_\n";
|
---|
1057 |
|
---|
1058 | // output the table of contents
|
---|
1059 | browsetoolsclass b;
|
---|
1060 | b.output_toc(args, browsers, formatinfo, collectproto,
|
---|
1061 | disp, outconvert, textout, logout);
|
---|
1062 |
|
---|
1063 | if (formatinfo.DocumentArrowsTop && !args["d"].empty()) {
|
---|
1064 | textout << outconvert << disp << "_document:navarrowstop_\n";
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | //output the related documents (may be the empty string)
|
---|
1068 | //will not output the docs if a format string is specified
|
---|
1069 | textout << outconvert << disp << "_document:relateddoc_\n";
|
---|
1070 |
|
---|
1071 | // output the document text
|
---|
1072 | if (!args["d"].empty()) {
|
---|
1073 | output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | textout << outconvert << disp << "_document:footer_\n";
|
---|
1077 | }
|
---|
1078 | return true;
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 | //displaying the book display when bookswitch=on
|
---|
1082 | bool documentaction::do_action_book(cgiargsclass &args, recptprotolistclass *protos,
|
---|
1083 | browsermapclass *browsers, displayclass &disp,
|
---|
1084 | outconvertclass &outconvert, ostream &textout,
|
---|
1085 | ostream &logout)
|
---|
1086 | {
|
---|
1087 | // must have a valid collection server
|
---|
1088 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
1089 | if (collectproto == NULL)
|
---|
1090 | {
|
---|
1091 | logout << "documentaction::do_action called with NULL collectproto\n";
|
---|
1092 | textout << outconvert << disp << "_document:header_\n"
|
---|
1093 | << "Error: Attempt to get document without setting collection\n";
|
---|
1094 | }
|
---|
1095 | else
|
---|
1096 | {
|
---|
1097 | text_t OID = args["d"];
|
---|
1098 | if (OID.empty()) OID = args["cl"];
|
---|
1099 | if (OID.empty())
|
---|
1100 | {
|
---|
1101 | textout << outconvert << disp << "Document contains no data\n";
|
---|
1102 | return true;
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | if (formatinfo.DocumentUseHTML && !args["d"].empty())
|
---|
1106 | {
|
---|
1107 | if (args["f"] == "1")
|
---|
1108 | {
|
---|
1109 | textout << outconvert << disp
|
---|
1110 | << "<html><head></head>\n"
|
---|
1111 | << "<frameset rows=\"68,*\" noresize border=0>\n"
|
---|
1112 | << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
|
---|
1113 | #ifndef DOCHANDLE
|
---|
1114 | << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d="
|
---|
1115 | << args["d"] << "\">"
|
---|
1116 | #else
|
---|
1117 | << "<frame name=\"documenttop\" frameborder=0 src=\"_httpdocumenthandle_("
|
---|
1118 | << args["c"] << "," << args["d"] << ")\">"
|
---|
1119 | #endif
|
---|
1120 | << "<noframes>\n"
|
---|
1121 | << "<p>You must have a frame enabled browser to view this.</p>\n"
|
---|
1122 | << "</noframes>\n"
|
---|
1123 | << "</frameset>\n"
|
---|
1124 | << "</html>\n";
|
---|
1125 | }
|
---|
1126 | else
|
---|
1127 | {
|
---|
1128 | output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | return true;
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 |
|
---|
1135 | //the header bit and the navigation button
|
---|
1136 | textout << outconvert << disp << "_document:header_\n" << "_document:content_\n";
|
---|
1137 |
|
---|
1138 | //display the book
|
---|
1139 | textout << outconvert << disp << "_document:flashbook_\n";
|
---|
1140 |
|
---|
1141 | //the footer bit without the document arrow
|
---|
1142 | textout << outconvert << disp << "</div> <!-- id=document -->\n";
|
---|
1143 | textout << outconvert << disp << "_endspacer__htmlfooter_\n";
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | return true;
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | //Displaying the xml when bookswitch=flashxml
|
---|
1150 | bool documentaction::do_action_flashxml(cgiargsclass &args, recptprotolistclass *protos,
|
---|
1151 | browsermapclass *browsers, displayclass &disp,
|
---|
1152 | outconvertclass &outconvert, ostream &textout,
|
---|
1153 | ostream &logout)
|
---|
1154 | {
|
---|
1155 | // must have a valid collection server
|
---|
1156 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
1157 | if (collectproto == NULL)
|
---|
1158 | {
|
---|
1159 | logout << "documentaction::do_action called with NULL collectproto\n";
|
---|
1160 | textout << outconvert << disp
|
---|
1161 | << "<Message>\n"
|
---|
1162 | << " Error: Attempt to get document without setting collection\n"
|
---|
1163 | << "</Message>\n";
|
---|
1164 | }
|
---|
1165 | else
|
---|
1166 | {
|
---|
1167 | text_t OID = args["d"];
|
---|
1168 | if (OID.empty()) OID = args["cl"];
|
---|
1169 | if (OID.empty())
|
---|
1170 | {
|
---|
1171 | textout << outconvert << disp
|
---|
1172 | << "<Message>\n"
|
---|
1173 | << " Document contains no data\n"
|
---|
1174 | << "</Message>\n";
|
---|
1175 | return true;
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 | if (formatinfo.DocumentUseHTML && !args["d"].empty())
|
---|
1179 | {
|
---|
1180 | if (args["f"] == "1")
|
---|
1181 | {
|
---|
1182 | textout << outconvert << disp
|
---|
1183 | << "<Message>\n"
|
---|
1184 | << " Using frames makes no sense for XML output\n"
|
---|
1185 | << "</Message>\n";
|
---|
1186 | }
|
---|
1187 | else
|
---|
1188 | {
|
---|
1189 | output_document_flashxml (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | return true;
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | // output the document text
|
---|
1196 | if (!args["d"].empty())
|
---|
1197 | {
|
---|
1198 | output_document_flashxml (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
|
---|
1199 | }
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | return true;
|
---|
1203 | }
|
---|
1204 |
|
---|
1205 |
|
---|
1206 |
|
---|
1207 | void documentaction::output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
|
---|
1208 | const TermInfo_tarray &terminfo, const text_t &OID,
|
---|
1209 | bool highlight, int hastxt, int wanttext,
|
---|
1210 | text_t &collection, recptproto *collectproto,
|
---|
1211 | browsermapclass *browsers, displayclass &disp,
|
---|
1212 | outconvertclass &outconvert, ostream &textout,
|
---|
1213 | ostream &logout, cgiargsclass &args) {
|
---|
1214 |
|
---|
1215 | DocumentRequest_t docrequest;
|
---|
1216 | DocumentResponse_t docresponse;
|
---|
1217 | comerror_t err;
|
---|
1218 | if (hastxt == 1) {
|
---|
1219 |
|
---|
1220 | if (wanttext) {
|
---|
1221 | // get the text
|
---|
1222 | docrequest.OID = OID;
|
---|
1223 | collectproto->get_document (collection, docrequest, docresponse, err, logout);
|
---|
1224 |
|
---|
1225 | // cut down on overhead by not using formattools if we only want the text
|
---|
1226 | // (wanttext will equal 2 if we want text and other stuff too)
|
---|
1227 | if (wanttext == 1)
|
---|
1228 | if (highlight) {
|
---|
1229 | highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout);
|
---|
1230 | } else {
|
---|
1231 | textout << outconvert << disp << docresponse.doc;
|
---|
1232 | }
|
---|
1233 | }
|
---|
1234 |
|
---|
1235 | if (wanttext != 1) {
|
---|
1236 | text_tmap options;
|
---|
1237 | options["text"] = docresponse.doc;
|
---|
1238 |
|
---|
1239 | if (formatinfo.AllowExtendedOptions) {
|
---|
1240 | browsetoolsclass b;
|
---|
1241 | b.load_extended_options(options, args, browsers, formatinfo,
|
---|
1242 | collectproto, disp, outconvert, logout);
|
---|
1243 | }
|
---|
1244 |
|
---|
1245 | text_t doctext
|
---|
1246 | = get_formatted_string (collection, collectproto, docinfo, disp,
|
---|
1247 | formatlistptr, options, logout);
|
---|
1248 |
|
---|
1249 | if (highlight) {
|
---|
1250 | highlighttext(doctext, args, terminfo, disp, outconvert, textout);
|
---|
1251 | } else {
|
---|
1252 | textout << outconvert << disp << doctext;
|
---|
1253 | }
|
---|
1254 | }
|
---|
1255 | }
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 |
|
---|
1259 | void documentaction::output_document (const text_t &OID, cgiargsclass &args,
|
---|
1260 | recptproto *collectproto, browsermapclass *browsers,
|
---|
1261 | displayclass &disp, outconvertclass &outconvert,
|
---|
1262 | ostream &textout, ostream &logout) {
|
---|
1263 | FilterResponse_t inforesponse;
|
---|
1264 | FilterResponse_t queryresponse;
|
---|
1265 | text_tset metadata;
|
---|
1266 | bool getParents = false;
|
---|
1267 | bool highlight = false;
|
---|
1268 | int wanttext = 0;
|
---|
1269 | int arg_gt = args.getintarg("gt");
|
---|
1270 | text_t &collection = args["c"];
|
---|
1271 |
|
---|
1272 | // if we have a query string and highlighting is turned on we need
|
---|
1273 | // to redo the query to get the terms for highlighting
|
---|
1274 |
|
---|
1275 | if (!args["q"].empty() && args.getintarg("hl")) {
|
---|
1276 |
|
---|
1277 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
|
---|
1278 | bool segment = false;
|
---|
1279 | if (cinfo != NULL) {
|
---|
1280 | segment = cinfo->isSegmented;
|
---|
1281 | }
|
---|
1282 | FilterRequest_t request;
|
---|
1283 | comerror_t err;
|
---|
1284 | request.filterResultOptions = FRmatchTerms;
|
---|
1285 | text_t formattedstring = args["q"];
|
---|
1286 | format_querystring (formattedstring, args.getintarg("b"), segment);
|
---|
1287 | set_queryfilter_options (request, formattedstring, args);
|
---|
1288 | args["q"] = formattedstring; // need to set this here for phrase
|
---|
1289 | // highlighting, where we look at the querystring
|
---|
1290 | collectproto->filter (args["c"], request, queryresponse, err, logout);
|
---|
1291 | if (err != noError) {
|
---|
1292 | outconvertclass text_t2ascii;
|
---|
1293 | logout << text_t2ascii
|
---|
1294 | << "documentaction::output_document: call to QueryFilter failed "
|
---|
1295 | << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
|
---|
1296 | highlight = false;
|
---|
1297 | } else {
|
---|
1298 | highlight = true;
|
---|
1299 | }
|
---|
1300 | }
|
---|
1301 |
|
---|
1302 | format_t *formatlistptr = new format_t();
|
---|
1303 | parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
|
---|
1304 |
|
---|
1305 | metadata.insert ("hastxt");
|
---|
1306 | metadata.insert ("haschildren");
|
---|
1307 |
|
---|
1308 | if (formatinfo.DocumentText == "[Text]")
|
---|
1309 | wanttext = 1;
|
---|
1310 | else {
|
---|
1311 | char *docformat = formatinfo.DocumentText.getcstr();
|
---|
1312 | if (strstr (docformat, "[Text]") != NULL)
|
---|
1313 | wanttext = 2;
|
---|
1314 | delete []docformat;
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | textout << outconvert << "<div class=\"documenttext\">\n";
|
---|
1318 |
|
---|
1319 | if (get_info (OID, collection, args["l"], metadata, getParents, collectproto, inforesponse, logout)) {
|
---|
1320 | int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
|
---|
1321 | int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
|
---|
1322 |
|
---|
1323 | if (arg_gt == 0) {
|
---|
1324 | output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
|
---|
1325 | OID, highlight, hastxt, wanttext, collection, collectproto,
|
---|
1326 | browsers, disp, outconvert, textout, logout, args);
|
---|
1327 |
|
---|
1328 | } else {
|
---|
1329 |
|
---|
1330 | ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
|
---|
1331 |
|
---|
1332 | // text is to be expanded
|
---|
1333 | text_t exOID = OID;
|
---|
1334 | if (haschildren != 1) exOID = get_parent (OID);
|
---|
1335 | if (exOID.empty()) exOID = OID;
|
---|
1336 |
|
---|
1337 | // if we're not in a document (i.e. we're in a top level classification)
|
---|
1338 | // we need to pass "is_classify = true" to get_contents so that it
|
---|
1339 | // doesn't recurse all the way through each document in the classification
|
---|
1340 | bool is_classify = false;
|
---|
1341 | if (args["d"].empty()) is_classify = true;
|
---|
1342 |
|
---|
1343 | get_contents (exOID, is_classify, metadata, collection, args["l"],
|
---|
1344 | collectproto, inforesponse, logout);
|
---|
1345 |
|
---|
1346 | ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
|
---|
1347 | ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
|
---|
1348 |
|
---|
1349 | if (arg_gt == 1) {
|
---|
1350 | // check if there are more than 10 sections containing text to be expanded -
|
---|
1351 | // if there are output warning message - this isn't a great way to do this
|
---|
1352 | // since the sections may be very large or very small - one day I'll fix it
|
---|
1353 | // -- Stefan.
|
---|
1354 | int seccount = 0;
|
---|
1355 | while (sechere != secend) {
|
---|
1356 | int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
|
---|
1357 | if (shastxt == 1) ++seccount;
|
---|
1358 | if (seccount > 10) break;
|
---|
1359 | ++sechere;
|
---|
1360 | }
|
---|
1361 | if (seccount > 10) {
|
---|
1362 | // more than 10 sections so output warning message and text
|
---|
1363 | // for current section only
|
---|
1364 | textout << outconvert << disp << "<div class=\"warning\">_document:textltwarning_</div>\n";
|
---|
1365 |
|
---|
1366 | output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
|
---|
1367 | OID, highlight, hastxt, wanttext, collection,
|
---|
1368 | collectproto, browsers, disp, outconvert, textout, logout, args);
|
---|
1369 |
|
---|
1370 | }
|
---|
1371 | else arg_gt = 2;
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | if (arg_gt == 2) {
|
---|
1375 | // get the text for each section
|
---|
1376 | sechere = inforesponse.docInfo.begin();
|
---|
1377 | int count = 0;
|
---|
1378 | while (sechere != secend) {
|
---|
1379 | textout << outconvert << disp << "\n<p><a name=" << (*sechere).OID << "></a>\n";
|
---|
1380 |
|
---|
1381 | int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
|
---|
1382 |
|
---|
1383 | output_text (*sechere, formatlistptr, queryresponse.termInfo,
|
---|
1384 | (*sechere).OID, highlight, shastxt, wanttext, collection,
|
---|
1385 | collectproto, browsers, disp, outconvert, textout, logout, args);
|
---|
1386 | ++count;
|
---|
1387 | ++sechere;
|
---|
1388 | }
|
---|
1389 | }
|
---|
1390 | }
|
---|
1391 | }
|
---|
1392 | textout << outconvert << "</div>\n";
|
---|
1393 | delete formatlistptr;
|
---|
1394 | }
|
---|
1395 |
|
---|
1396 | void documentaction::output_document_flashxml(const text_t &OID, cgiargsclass &args,
|
---|
1397 | recptproto *collectproto, browsermapclass *browsermap,
|
---|
1398 | displayclass &disp, outconvertclass &outconvert,
|
---|
1399 | ostream &textout, ostream &logout) {
|
---|
1400 | //if this is not at the document level --> do Nothing!!
|
---|
1401 | if (args["d"].empty())
|
---|
1402 | return;
|
---|
1403 |
|
---|
1404 | //if we have a query string and highlighting is turned on we need
|
---|
1405 | //to redo the query to get the terms for highlighting
|
---|
1406 | FilterResponse_t queryresponse;
|
---|
1407 | bool highlight = false;
|
---|
1408 | if (!args["q"].empty() && args.getintarg("hl"))
|
---|
1409 | {
|
---|
1410 | text_t &collection = args["c"];
|
---|
1411 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
|
---|
1412 | bool segment = false;
|
---|
1413 | if (cinfo != NULL)
|
---|
1414 | {
|
---|
1415 | segment = cinfo->isSegmented;
|
---|
1416 | }
|
---|
1417 | FilterRequest_t request;
|
---|
1418 | comerror_t err;
|
---|
1419 | request.filterResultOptions = FRmatchTerms;
|
---|
1420 | text_t formattedstring = args["q"];
|
---|
1421 | format_querystring (formattedstring, args.getintarg("b"), segment);
|
---|
1422 | set_queryfilter_options (request, formattedstring, args);
|
---|
1423 | args["q"] = formattedstring; //need to set this here for phrase
|
---|
1424 | //highlighting, where we look at the querystring
|
---|
1425 | collectproto->filter (args["c"], request, queryresponse, err, logout);
|
---|
1426 | if (err != noError)
|
---|
1427 | {
|
---|
1428 | outconvertclass text_t2ascii;
|
---|
1429 | logout << text_t2ascii
|
---|
1430 | << "documentaction::output_document: call to QueryFilter failed "
|
---|
1431 | << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
|
---|
1432 | highlight = false;
|
---|
1433 | }
|
---|
1434 | else
|
---|
1435 | {
|
---|
1436 | highlight = true;
|
---|
1437 | }
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | FilterResponse_t response;
|
---|
1441 | bool getParents = false;
|
---|
1442 | text_tset metadata;
|
---|
1443 | text_t classifytype, classification, formatstring;
|
---|
1444 |
|
---|
1445 | //metadata elements needed by recurse_contents
|
---|
1446 | metadata.insert ("Title");
|
---|
1447 | metadata.insert ("haschildren");
|
---|
1448 |
|
---|
1449 | //protocol call
|
---|
1450 | if (!get_info (OID, args["c"], args["l"], metadata, getParents, collectproto, response, logout))
|
---|
1451 | return;
|
---|
1452 |
|
---|
1453 | recurse_contents (response.docInfo[0], args, metadata,
|
---|
1454 | getParents, collectproto, disp, outconvert, textout, logout, highlight, queryresponse.termInfo);
|
---|
1455 | }
|
---|
1456 |
|
---|
1457 | void documentaction::recurse_contents(ResultDocInfo_t §ion, cgiargsclass &args,
|
---|
1458 | text_tset &metadata, bool &getParents,
|
---|
1459 | recptproto *collectproto, displayclass &disp,
|
---|
1460 | outconvertclass &outconvert, ostream &textout, ostream &logout,
|
---|
1461 | bool highlight, const TermInfo_tarray &terminfo)
|
---|
1462 | {
|
---|
1463 | text_t formatstring;
|
---|
1464 |
|
---|
1465 | bool is_classify = false;
|
---|
1466 |
|
---|
1467 | //output this section
|
---|
1468 | text_t classification = "Document";
|
---|
1469 |
|
---|
1470 | textout << outconvert << disp << "<Section>\n";
|
---|
1471 |
|
---|
1472 | //get the title
|
---|
1473 | textout << outconvert << disp << "<Description>\n<Metadata name=\"Title\">";
|
---|
1474 | text_t t_title = section.metadata["Title"].values[0];
|
---|
1475 | //if it is highlighted
|
---|
1476 | /*if (highlight == true)
|
---|
1477 | {
|
---|
1478 | highlighttext(t_title, args, terminfo, disp, outconvert, textout);
|
---|
1479 | }
|
---|
1480 | else
|
---|
1481 | {*/
|
---|
1482 | textout << outconvert << disp << t_title;
|
---|
1483 | //}
|
---|
1484 | textout << outconvert << disp << "</Metadata>\n</Description>\n";
|
---|
1485 |
|
---|
1486 | //get the text
|
---|
1487 | DocumentRequest_t docrequest;
|
---|
1488 | DocumentResponse_t docresponse;
|
---|
1489 | comerror_t err;
|
---|
1490 | docrequest.OID = section.OID;
|
---|
1491 | text_t &collection = args["c"];
|
---|
1492 | collectproto->get_document(collection, docrequest, docresponse, err, logout);
|
---|
1493 | //if it is highlighted
|
---|
1494 | if (highlight == true)
|
---|
1495 | {
|
---|
1496 | highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout);
|
---|
1497 | }
|
---|
1498 | else
|
---|
1499 | {
|
---|
1500 | textout << outconvert << disp << docresponse.doc;
|
---|
1501 | }
|
---|
1502 | textout << outconvert << disp << "\n";
|
---|
1503 |
|
---|
1504 | int haschildren = section.metadata["haschildren"].values[0].getint();
|
---|
1505 |
|
---|
1506 | // recurse through children
|
---|
1507 | if (haschildren == 1)
|
---|
1508 | {
|
---|
1509 | FilterResponse_t tmp;
|
---|
1510 | get_children (section.OID, args["c"], args["l"], metadata, getParents, collectproto, tmp, logout);
|
---|
1511 | ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
|
---|
1512 | ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
|
---|
1513 |
|
---|
1514 | while (thisdoc != lastdoc)
|
---|
1515 | {
|
---|
1516 | recurse_contents (*thisdoc, args, metadata, getParents, collectproto, disp, outconvert, textout, logout, highlight, terminfo);
|
---|
1517 | ++thisdoc;
|
---|
1518 | }
|
---|
1519 | }
|
---|
1520 |
|
---|
1521 | textout << outconvert << disp << "</Section>\n";
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | void documentaction::set_arrow_macros (cgiargsclass &args, recptproto *collectproto,
|
---|
1525 | displayclass &disp, ostream &logout) {
|
---|
1526 |
|
---|
1527 | text_tset metadata;
|
---|
1528 | FilterResponse_t response;
|
---|
1529 | FilterResponse_t presponse;
|
---|
1530 |
|
---|
1531 | int haschildren = 0;
|
---|
1532 | text_tarray next_siblings;
|
---|
1533 | text_t previous_sibling;
|
---|
1534 | text_t &arg_d = args["d"];
|
---|
1535 |
|
---|
1536 | // get info on current section
|
---|
1537 | metadata.insert("haschildren");
|
---|
1538 | if (!get_info(arg_d, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
|
---|
1539 | logout << "error 1 in documentaction::set_arrow_macros\n";
|
---|
1540 | return;
|
---|
1541 | }
|
---|
1542 | haschildren = response.docInfo[0].metadata["haschildren"].values[0].getint();
|
---|
1543 |
|
---|
1544 | // get OIDs of next and previous siblings of current section and
|
---|
1545 | // all it's parents
|
---|
1546 | int parentcount = countchar(arg_d.begin(), arg_d.end(), '.');
|
---|
1547 | text_t thisoid = arg_d;
|
---|
1548 | while (parentcount > 0) {
|
---|
1549 | get_children (get_parent(thisoid), args["c"], args["l"], metadata, false,
|
---|
1550 | collectproto, response, logout);
|
---|
1551 | ResultDocInfo_tarray::iterator this_sibling = response.docInfo.begin();
|
---|
1552 | ResultDocInfo_tarray::iterator last_sibling = response.docInfo.end();
|
---|
1553 | bool first = true;
|
---|
1554 | while (this_sibling != last_sibling) {
|
---|
1555 | if ((*this_sibling).OID == thisoid) {
|
---|
1556 | if (!first && next_siblings.empty()) {
|
---|
1557 | previous_sibling = (*(this_sibling-1)).OID;
|
---|
1558 | int section_has_children = (*(this_sibling-1)).metadata["haschildren"].values[0].getint();
|
---|
1559 | // if previous sibling has children we need to recurse
|
---|
1560 | // down to the last descendant
|
---|
1561 | while (section_has_children) {
|
---|
1562 | get_children (previous_sibling, args["c"], args["l"], metadata, false,
|
---|
1563 | collectproto, presponse, logout);
|
---|
1564 | if (!presponse.docInfo.empty()) {
|
---|
1565 | ResultDocInfo_tarray::iterator it = presponse.docInfo.end() - 1;
|
---|
1566 | previous_sibling = (*it).OID;
|
---|
1567 | section_has_children = (*it).metadata["haschildren"].values[0].getint();
|
---|
1568 | } else {
|
---|
1569 | section_has_children = 0; // this should never happen
|
---|
1570 | }
|
---|
1571 | }
|
---|
1572 | }
|
---|
1573 |
|
---|
1574 | if ((this_sibling+1) != last_sibling) {
|
---|
1575 | next_siblings.push_back((*(this_sibling+1)).OID);
|
---|
1576 | } else {
|
---|
1577 | next_siblings.push_back("");
|
---|
1578 | }
|
---|
1579 | break;
|
---|
1580 | }
|
---|
1581 | ++this_sibling;
|
---|
1582 | first = false;
|
---|
1583 | }
|
---|
1584 | thisoid = get_parent(thisoid);
|
---|
1585 | --parentcount;
|
---|
1586 | }
|
---|
1587 |
|
---|
1588 | // work out values for next link
|
---|
1589 | if (haschildren) {
|
---|
1590 | #ifndef DOCHANLE
|
---|
1591 | disp.setmacro ("httpnextarrow", "document", "_httpdocument_&cl=" + args["cl"] +
|
---|
1592 | "&d=" + arg_d + ".fc");
|
---|
1593 | #else
|
---|
1594 | disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+arg_d + ".fc)";
|
---|
1595 |
|
---|
1596 | #endif
|
---|
1597 |
|
---|
1598 | } else {
|
---|
1599 | text_tarray::const_iterator h = next_siblings.begin();
|
---|
1600 | text_tarray::const_iterator e = next_siblings.end();
|
---|
1601 | while (h != e) {
|
---|
1602 | if (!(*h).empty()) {
|
---|
1603 | #ifndef DOCHANLE
|
---|
1604 | disp.setmacro ("httpnextarrow", "document", "_httpdocument_&cl=" + args["cl"] +
|
---|
1605 | "&d=" + *h);
|
---|
1606 | #else
|
---|
1607 | disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+*h+")";
|
---|
1608 |
|
---|
1609 | #endif
|
---|
1610 |
|
---|
1611 | break;
|
---|
1612 | }
|
---|
1613 | ++h;
|
---|
1614 | }
|
---|
1615 | }
|
---|
1616 |
|
---|
1617 | // work out value for previous link
|
---|
1618 | if (!previous_sibling.empty()) {
|
---|
1619 | #ifndef DOCHANDLE
|
---|
1620 | disp.setmacro ("httpprevarrow", "document", "_httpdocument_&cl=" + args["cl"] +
|
---|
1621 | "&d=" + previous_sibling);
|
---|
1622 | #else
|
---|
1623 | disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+ previous_sibling+")");
|
---|
1624 |
|
---|
1625 | #endif
|
---|
1626 |
|
---|
1627 | } else {
|
---|
1628 | if (countchar(arg_d.begin(), arg_d.end(), '.')) {
|
---|
1629 | #ifndef DOCHANDLE
|
---|
1630 | disp.setmacro ("httpprevarrow", "document", "_httpdocument_&cl=" + args["cl"] +
|
---|
1631 | "&d=" + get_parent(arg_d));
|
---|
1632 | #else
|
---|
1633 | disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+get_parent(arg_d)+")");
|
---|
1634 |
|
---|
1635 | #endif
|
---|
1636 |
|
---|
1637 | }
|
---|
1638 | }
|
---|
1639 | }
|
---|