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 | #include "documentaction.h"
|
---|
28 | #include "browsetools.h"
|
---|
29 | #include "OIDtools.h"
|
---|
30 | #include "querytools.h"
|
---|
31 | #include "unitool.h"
|
---|
32 | #include "gsdltools.h"
|
---|
33 |
|
---|
34 | documentaction::documentaction () {
|
---|
35 | recpt = NULL;
|
---|
36 |
|
---|
37 |
|
---|
38 | // this action uses cgi variables "a", "d", "cl",
|
---|
39 | // "x", "gc", "gt", "gp", and "hl"
|
---|
40 | cgiarginfo arg_ainfo;
|
---|
41 | arg_ainfo.shortname = "a";
|
---|
42 | arg_ainfo.longname = "action";
|
---|
43 | arg_ainfo.multiplechar = true;
|
---|
44 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
45 | arg_ainfo.argdefault = "p";
|
---|
46 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
47 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
48 |
|
---|
49 | arg_ainfo.shortname = "d";
|
---|
50 | arg_ainfo.longname = "document OID";
|
---|
51 | arg_ainfo.multiplechar = true;
|
---|
52 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
53 | arg_ainfo.argdefault = "";
|
---|
54 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
55 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
56 |
|
---|
57 | // whether or not a document should be retrieved from the
|
---|
58 | // library or the Web.
|
---|
59 | arg_ainfo.shortname = "il";
|
---|
60 | arg_ainfo.longname = "internal link preference";
|
---|
61 | arg_ainfo.multiplechar = false;
|
---|
62 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
63 | arg_ainfo.argdefault = "l";
|
---|
64 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
65 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
66 |
|
---|
67 | arg_ainfo.shortname = "cl";
|
---|
68 | arg_ainfo.longname = "classification OID";
|
---|
69 | arg_ainfo.multiplechar = true;
|
---|
70 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
71 | arg_ainfo.argdefault = "";
|
---|
72 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
73 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
74 |
|
---|
75 | // in this action "gc" controls the expand/contract
|
---|
76 | // contents function
|
---|
77 | arg_ainfo.shortname = "gc";
|
---|
78 | arg_ainfo.longname = "expand contents";
|
---|
79 | arg_ainfo.multiplechar = false;
|
---|
80 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
81 | arg_ainfo.argdefault = "0";
|
---|
82 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
83 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
84 |
|
---|
85 | // in this action "gt" controls the expand/contract
|
---|
86 | // text function 0 = not expanded, 1 = expand unless
|
---|
87 | // there are more than 10 sections containing text,
|
---|
88 | // 2 = expand all
|
---|
89 | arg_ainfo.shortname = "gt";
|
---|
90 | arg_ainfo.longname = "expand text";
|
---|
91 | arg_ainfo.multiplechar = false;
|
---|
92 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
93 | arg_ainfo.argdefault = "0";
|
---|
94 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
95 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
96 |
|
---|
97 | // in this action "gp" is the "go to page" control
|
---|
98 | // used by the Book type of toc
|
---|
99 | arg_ainfo.shortname = "gp";
|
---|
100 | arg_ainfo.longname = "go to page";
|
---|
101 | arg_ainfo.multiplechar = true;
|
---|
102 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
103 | arg_ainfo.argdefault = "";
|
---|
104 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
105 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
106 |
|
---|
107 | // in this action "hl" is the "highlighting on/
|
---|
108 | // highlighting off control
|
---|
109 | arg_ainfo.shortname = "hl";
|
---|
110 | arg_ainfo.longname = "highlighting on/off";
|
---|
111 | arg_ainfo.multiplechar = false;
|
---|
112 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
113 | arg_ainfo.argdefault = "1";
|
---|
114 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
115 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
116 |
|
---|
117 | // "x" is 0 normally or 1 if page
|
---|
118 | // has been "detached"
|
---|
119 | arg_ainfo.shortname = "x";
|
---|
120 | arg_ainfo.longname = "detached page";
|
---|
121 | arg_ainfo.multiplechar = false;
|
---|
122 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
123 | arg_ainfo.argdefault = "0";
|
---|
124 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
125 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
126 |
|
---|
127 | // f arg is set to 1 if document is to
|
---|
128 | // be displayed in a frame
|
---|
129 | arg_ainfo.shortname = "f";
|
---|
130 | arg_ainfo.longname = "frame";
|
---|
131 | arg_ainfo.multiplechar = false;
|
---|
132 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
133 | arg_ainfo.argdefault = "0";
|
---|
134 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
135 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
136 |
|
---|
137 | // fc arg is "1" if search bar is to be included (i.e. if "fc" == 1
|
---|
138 | // the httpdocument macro will include "&f=1"
|
---|
139 | arg_ainfo.shortname = "fc";
|
---|
140 | arg_ainfo.longname = "include search bar";
|
---|
141 | arg_ainfo.multiplechar = false;
|
---|
142 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
143 | arg_ainfo.argdefault = "1";
|
---|
144 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
145 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
146 |
|
---|
147 | //rd is whether a document will be displayed
|
---|
148 | //with a relevant document list
|
---|
149 | arg_ainfo.shortname = "rd";
|
---|
150 | arg_ainfo.longname = "include relevant documents";
|
---|
151 | arg_ainfo.multiplechar = false;
|
---|
152 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
153 | arg_ainfo.argdefault = "0";
|
---|
154 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
155 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
156 |
|
---|
157 | }
|
---|
158 |
|
---|
159 | documentaction::~documentaction () {
|
---|
160 | }
|
---|
161 |
|
---|
162 | bool documentaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
|
---|
163 | ostream &logout) {
|
---|
164 |
|
---|
165 | // check gc argument
|
---|
166 | int arg_gc = args.getintarg("gc");
|
---|
167 | if (arg_gc < 0 || arg_gc > 2) {
|
---|
168 | logout << "Warning: \"gc\" argument out of range (" << arg_gc << ")\n";
|
---|
169 | cgiarginfo *gcinfo = argsinfo.getarginfo ("gc");
|
---|
170 | if (gcinfo != NULL) args["gc"] = gcinfo->argdefault;
|
---|
171 | }
|
---|
172 |
|
---|
173 | // check gt argument (may be either 0, 1 or 2)
|
---|
174 | int arg_gt = args.getintarg("gt");
|
---|
175 | if (arg_gt != 0 && arg_gt != 1 && arg_gt != 2) {
|
---|
176 | logout << "Warning: \"gt\" argument out of range (" << arg_gt << ")\n";
|
---|
177 | cgiarginfo *gtinfo = argsinfo.getarginfo ("gt");
|
---|
178 | if (gtinfo != NULL) args["gt"] = gtinfo->argdefault;
|
---|
179 | }
|
---|
180 |
|
---|
181 | // check hl argument
|
---|
182 | int arg_hl = args.getintarg("hl");
|
---|
183 | if (arg_hl != 0 && arg_hl != 1) {
|
---|
184 | logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n";
|
---|
185 | cgiarginfo *hlinfo = argsinfo.getarginfo ("hl");
|
---|
186 | if (hlinfo != NULL) args["hl"] = hlinfo->argdefault;
|
---|
187 | }
|
---|
188 |
|
---|
189 | // check x argument
|
---|
190 | int arg_x = args.getintarg("x");
|
---|
191 | if (arg_x != 0 && arg_x != 1) {
|
---|
192 | logout << "Warning: \"x\" argument out of range (" << arg_x << ")\n";
|
---|
193 | cgiarginfo *xinfo = argsinfo.getarginfo ("x");
|
---|
194 | if (xinfo != NULL) args["x"] = xinfo->argdefault;
|
---|
195 | }
|
---|
196 |
|
---|
197 | //checks whether rd arg is valid
|
---|
198 | int arg_rd = args.getintarg("rd");
|
---|
199 | if (arg_rd != 0 && arg_rd != 1) {
|
---|
200 | logout << "Warning: \"rd\" argument out of range (" << arg_rd << ")\n";
|
---|
201 | cgiarginfo *rdinfo = argsinfo.getarginfo ("rd");
|
---|
202 | if (rdinfo != NULL) args["rd"] = rdinfo->argdefault;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | return true;
|
---|
207 | }
|
---|
208 |
|
---|
209 | void documentaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
|
---|
210 | response_t &response,text_t &response_data,
|
---|
211 | ostream &logout) {
|
---|
212 |
|
---|
213 | if ((args["il"] == "w") && (!args["d"].empty())) {
|
---|
214 |
|
---|
215 | recptproto* collectproto = protos->getrecptproto (args["c"], logout);
|
---|
216 | if (collectproto != NULL) {
|
---|
217 |
|
---|
218 | text_tset metadata;
|
---|
219 | FilterResponse_t filt_response;
|
---|
220 | text_t top;
|
---|
221 |
|
---|
222 | metadata.insert ("URL");
|
---|
223 |
|
---|
224 | // get metadata for parent document
|
---|
225 | get_top (args["d"], top);
|
---|
226 | if (get_info (top, args["c"], metadata, false, collectproto, filt_response, logout)) {
|
---|
227 | text_t url = filt_response.docInfo[0].metadata["URL"].values[0];
|
---|
228 |
|
---|
229 | response = location;
|
---|
230 | response_data = url;
|
---|
231 | return;
|
---|
232 | } else {
|
---|
233 | // error, no URL
|
---|
234 | logout << "Error: documentaction::get_cgihead_info failed on get_info" << endl;
|
---|
235 | }
|
---|
236 | }
|
---|
237 | }
|
---|
238 | response = content;
|
---|
239 | response_data = "text/html";
|
---|
240 | }
|
---|
241 |
|
---|
242 | // set_widthtspace calculates how wide the spaces in the nav bar should
|
---|
243 | // be and sets the appropriate macro
|
---|
244 | void documentaction::set_spacemacro (displayclass &disp, FilterResponse_t &response) {
|
---|
245 |
|
---|
246 | text_t width;
|
---|
247 | int twidth, swidth, iwidth = 0;
|
---|
248 |
|
---|
249 | int numc = response.docInfo.size();
|
---|
250 | ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
|
---|
251 | ResultDocInfo_tarray::iterator docend = response.docInfo.end();
|
---|
252 |
|
---|
253 | disp.expandstring ("Global", "_pagewidth_", width);
|
---|
254 | twidth = width.getint();
|
---|
255 |
|
---|
256 | disp.expandstring ("query", "_searchwidth_", width);
|
---|
257 | iwidth += width.getint();
|
---|
258 |
|
---|
259 |
|
---|
260 |
|
---|
261 | while (dochere != docend) {
|
---|
262 | const text_t &title = (*dochere).metadata["Title"].values[0];
|
---|
263 |
|
---|
264 | disp.expandstring ("document", "_" + title + "width_", width);
|
---|
265 | if (width == ("_" + title + "width_"))
|
---|
266 | disp.expandstring ("document", "_defaultwidth_", width);
|
---|
267 | iwidth += width.getint();
|
---|
268 | dochere ++;
|
---|
269 | }
|
---|
270 | if ((twidth - iwidth) < numc) swidth = 2;
|
---|
271 | else {
|
---|
272 | swidth = twidth - iwidth;
|
---|
273 | if (numc > 0) swidth = swidth / numc;
|
---|
274 | }
|
---|
275 | disp.setmacro ("widthtspace", "Global", swidth);
|
---|
276 | }
|
---|
277 |
|
---|
278 | // set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros
|
---|
279 | // reponse contains 1 metadata field (Title)
|
---|
280 | void documentaction::set_navbarmacros (displayclass &disp, FilterResponse_t &response,
|
---|
281 | cgiargsclass &args) {
|
---|
282 |
|
---|
283 | text_t topparent;
|
---|
284 | text_t &arg_d = args["d"];
|
---|
285 | text_t navigationbar = "<!-- Navigation Bar -->\n";
|
---|
286 |
|
---|
287 | get_top (args["cl"], topparent);
|
---|
288 | int numc = response.docInfo.size();
|
---|
289 | ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
|
---|
290 | ResultDocInfo_tarray::iterator docend = response.docInfo.end();
|
---|
291 |
|
---|
292 | navigationbar += "<nobr>\n";
|
---|
293 | if (args["a"] == "q") {
|
---|
294 | navigationbar += "_icontabsearchgreen_";
|
---|
295 | } else {
|
---|
296 | navigationbar += "_imagesearch_";
|
---|
297 | }
|
---|
298 |
|
---|
299 |
|
---|
300 | if (numc == 0) navigationbar += "_imagespacer_";
|
---|
301 |
|
---|
302 | while (dochere != docend) {
|
---|
303 | text_t title = (*dochere).metadata["Title"].values[0];
|
---|
304 |
|
---|
305 | bool unknown = false;
|
---|
306 |
|
---|
307 | // test the _XXXwidth_ macro to see if image macros are
|
---|
308 | // defined for this type of classification - if not we'll
|
---|
309 | // just display the text
|
---|
310 | text_t tmpwidth;
|
---|
311 | disp.expandstring ("document", "_" + title + "width_", tmpwidth);
|
---|
312 | if (tmpwidth == ("_" + title + "width_")) unknown = true;
|
---|
313 |
|
---|
314 | // if we're inside a document all the classification buttons should be enabled
|
---|
315 | if (arg_d.empty() && ((*dochere).OID == topparent)) {
|
---|
316 | if (unknown) navigationbar += "_imagespacer_ " + title + " ";
|
---|
317 | else navigationbar += "_imagespacer__icontab" + title + "green_";
|
---|
318 | } else {
|
---|
319 |
|
---|
320 | // set the _httpbrowseXXX_ macro for this classification
|
---|
321 | if (unknown) navigationbar += "_imagespacer_ <a href=\"_httpdocument_&cl=" +
|
---|
322 | (*dochere).OID + "\">" + title + "</a> ";
|
---|
323 | else {
|
---|
324 | navigationbar += "_imagespacer__image" + title + "_";
|
---|
325 | disp.setmacro ("httpbrowse" + title, "Global", "_httpdocument_&cl=" + (*dochere).OID);
|
---|
326 | }
|
---|
327 | }
|
---|
328 | dochere ++;
|
---|
329 | }
|
---|
330 | navigationbar += "\n</nobr>\n";
|
---|
331 | navigationbar += "<!-- End of Navigation Bar -->\n";
|
---|
332 | disp.setmacro ("navigationbar", "Global", navigationbar);
|
---|
333 | }
|
---|
334 |
|
---|
335 | // define all the macros which might be used by other actions
|
---|
336 | // to produce pages.
|
---|
337 | void documentaction::define_external_macros (displayclass &disp, cgiargsclass &args,
|
---|
338 | recptprotolistclass *protos, ostream &logout) {
|
---|
339 |
|
---|
340 | // define_external_macros sets the following macros:
|
---|
341 |
|
---|
342 | // _navigationbar_ this is the navigation bar containing the search button
|
---|
343 | // and any classification buttons - it goes at the top of
|
---|
344 | // most pages. for now we're assuming that there'll always
|
---|
345 | // be a search button - we should probably check that there
|
---|
346 | // is a query action before making this assumption
|
---|
347 |
|
---|
348 | // _httpbrowseXXX_ the http macros for each classification (i.e. if there
|
---|
349 | // are Title and Creator classifications _httpbrowseTitle_
|
---|
350 | // and _httpbrowseCreator_ will be set
|
---|
351 |
|
---|
352 | // _widthtspace_ the width of the spacers between buttons in navigation
|
---|
353 | // bar
|
---|
354 |
|
---|
355 | // _httpdocument_ has '&f=1' added if displaying document inside a frame
|
---|
356 |
|
---|
357 | // _gsdltop_ macro to replace _top targets with
|
---|
358 |
|
---|
359 | // _httppagehome_ overridden home url if html collections have own homepage
|
---|
360 |
|
---|
361 | // must have a valid collection server to continue
|
---|
362 | text_t &collection = args["c"];
|
---|
363 | if (collection.empty()) return;
|
---|
364 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
365 | if (collectproto == NULL) return;
|
---|
366 |
|
---|
367 | if (recpt == NULL) {
|
---|
368 | logout << "ERROR (documentaction::define_external_macros): This action does not contain\n"
|
---|
369 | << " information about any receptionists. The method set_receptionist was\n"
|
---|
370 | << " probably not called from the module which instantiated this action.\n";
|
---|
371 | return;
|
---|
372 | }
|
---|
373 |
|
---|
374 | outconvertclass text_t2ascii;
|
---|
375 | comerror_t err;
|
---|
376 | InfoFiltersResponse_t filterinfo;
|
---|
377 | FilterResponse_t response;
|
---|
378 | text_tset metadata;
|
---|
379 |
|
---|
380 | // get info on current collection and load up formatinfo
|
---|
381 | // I'd prefer not to do this here as we're getting
|
---|
382 | // collection info every time (and probably also getting
|
---|
383 | // it in other places some of the time) - One day I'll
|
---|
384 | // fix it ... maybe - Stefan.
|
---|
385 | ColInfoResponse_t cinfo;
|
---|
386 |
|
---|
387 | collectproto->get_collectinfo (collection, cinfo, err, logout);
|
---|
388 | load_formatinfo (cinfo.format, args.getintarg("gt"));
|
---|
389 | // ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
|
---|
390 | // if (cinfo == NULL) {
|
---|
391 | // logout << "ERROR (documentaction::define_external_macros): get_collectinfo_ptr returned NULL\n";
|
---|
392 | // return;
|
---|
393 | // }
|
---|
394 | //load_formatinfo (cinfo->format, args.getintarg("gt"));
|
---|
395 |
|
---|
396 | if (formatinfo.DocumentUseHTML) {
|
---|
397 |
|
---|
398 | // frame stuff
|
---|
399 | if (args["fc"] == "1") {
|
---|
400 | text_t httpdocument;
|
---|
401 | disp.expandstring ("Global", "_httpdocument_", httpdocument);
|
---|
402 | httpdocument += "&f=1";
|
---|
403 | disp.setmacro ("httpdocument", "Global", httpdocument);
|
---|
404 | disp.setmacro ("gsdltop", "Global", "documenttop");
|
---|
405 | formatinfo.DocumentText = "[Text]";
|
---|
406 | }
|
---|
407 | text_tmap::iterator it = cinfo.format.find ("homepage");
|
---|
408 | if (it != cinfo.format.end()) {
|
---|
409 | text_t httppagehome;
|
---|
410 | if (get_link (args, protos, (*it).second, httppagehome, logout))
|
---|
411 | disp.setmacro ("httppagehome", "Global", httppagehome);
|
---|
412 | }
|
---|
413 | }
|
---|
414 |
|
---|
415 | // don't want navigation bar if page is 'detached'
|
---|
416 | if (!args.getintarg("x")) {
|
---|
417 |
|
---|
418 | collectproto->get_filterinfo (collection, filterinfo, err, logout);
|
---|
419 | if (err == noError) {
|
---|
420 | // check that there's a browse filter
|
---|
421 | if (filterinfo.filterNames.find ("BrowseFilter") != filterinfo.filterNames.end()) {
|
---|
422 |
|
---|
423 | metadata.insert ("Title");
|
---|
424 | bool getParents = false;
|
---|
425 | get_children ("", collection, metadata, getParents, collectproto, response, logout);
|
---|
426 |
|
---|
427 | // calculate width of spacers and set _widthtspace_ macro
|
---|
428 | if (args.getintarg("v") == 0) set_spacemacro (disp, response);
|
---|
429 |
|
---|
430 | // set _navigationbar_ macro
|
---|
431 | set_navbarmacros (disp, response, args);
|
---|
432 |
|
---|
433 | }
|
---|
434 | } else {
|
---|
435 | logout << text_t2ascii
|
---|
436 | << "Error (documentaction::define_external_macros()) in call to get_filterinfo() "
|
---|
437 | << get_comerror_string (err);
|
---|
438 | }
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 | bool documentaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
|
---|
443 | const text_t &inlink, text_t &outlink, ostream &logout) {
|
---|
444 |
|
---|
445 | FilterResponse_t response;
|
---|
446 | text_tset metadata;
|
---|
447 | metadata.insert ("section");
|
---|
448 |
|
---|
449 | // check current collection first
|
---|
450 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
451 |
|
---|
452 | if (get_info (inlink, args["c"], metadata, false, collectproto, response, logout)) {
|
---|
453 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
454 | outlink = "_httpdocument_&d=" + response.docInfo[0].metadata["section"].values[0];
|
---|
455 | return true;
|
---|
456 | }
|
---|
457 | }
|
---|
458 |
|
---|
459 | // check all the other enabled collections
|
---|
460 |
|
---|
461 | if (args["ccs"] == "1" && !args["cc"].empty()) {
|
---|
462 | text_tarray collections;
|
---|
463 | splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
|
---|
464 |
|
---|
465 | text_tarray::const_iterator col_here = collections.begin();
|
---|
466 | text_tarray::const_iterator col_end = collections.end();
|
---|
467 |
|
---|
468 | while (col_here != col_end) {
|
---|
469 |
|
---|
470 | // don't need to check current collection again
|
---|
471 | if (*col_here == args["c"]) {col_here ++; continue;}
|
---|
472 |
|
---|
473 | collectproto = protos->getrecptproto (*col_here, logout);
|
---|
474 |
|
---|
475 | if (get_info (inlink, *col_here, metadata, false, collectproto, response, logout)) {
|
---|
476 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
477 | outlink = "_httpdocument_&c=" + *col_here + "&d=" +
|
---|
478 | response.docInfo[0].metadata["section"].values[0];
|
---|
479 | return true;
|
---|
480 | }
|
---|
481 | }
|
---|
482 | col_here ++;
|
---|
483 | }
|
---|
484 | }
|
---|
485 | return false;
|
---|
486 | }
|
---|
487 |
|
---|
488 | void documentaction::load_formatinfo (const text_tmap &colformat, int gt) {
|
---|
489 |
|
---|
490 | formatinfo.clear();
|
---|
491 | text_tmap::const_iterator format_here = colformat.begin();
|
---|
492 | text_tmap::const_iterator format_end = colformat.end();
|
---|
493 |
|
---|
494 | while (format_here != format_end) {
|
---|
495 | if (((*format_here).first == "DocumentImages") &&
|
---|
496 | ((*format_here).second == "true"))
|
---|
497 | formatinfo.DocumentImages = true;
|
---|
498 | else if (((*format_here).first == "DocumentTitles") &&
|
---|
499 | ((*format_here).second == "false"))
|
---|
500 | formatinfo.DocumentTitles = false;
|
---|
501 | else if ((*format_here).first == "DocumentHeading")
|
---|
502 | formatinfo.DocumentHeading = (*format_here).second;
|
---|
503 | else if (((*format_here).first == "DocumentContents") &&
|
---|
504 | ((*format_here).second == "false"))
|
---|
505 | formatinfo.DocumentContents = false;
|
---|
506 | else if (((*format_here).first == "DocumentArrowsBottom") &&
|
---|
507 | ((*format_here).second == "false"))
|
---|
508 | formatinfo.DocumentArrowsBottom = false;
|
---|
509 | else if ((*format_here).first == "DocumentButtons")
|
---|
510 | splitchar ((*format_here).second.begin(), (*format_here).second.end(),
|
---|
511 | '|', formatinfo.DocumentButtons);
|
---|
512 | else if ((*format_here).first == "DocumentText")
|
---|
513 | formatinfo.DocumentText = (*format_here).second;
|
---|
514 | else if ((*format_here).first == "RelatedDocuments")
|
---|
515 | formatinfo.RelatedDocuments = (*format_here).second;
|
---|
516 | else if (((*format_here).first == "DocumentUseHTML") &&
|
---|
517 | ((*format_here).second == "true"))
|
---|
518 | formatinfo.DocumentUseHTML = true;
|
---|
519 | else
|
---|
520 | formatinfo.formatstrings[(*format_here).first] = (*format_here).second;
|
---|
521 |
|
---|
522 | format_here ++;
|
---|
523 | }
|
---|
524 |
|
---|
525 | // never want arrows when text is expanded
|
---|
526 | if (gt) formatinfo.DocumentArrowsBottom = false;
|
---|
527 | }
|
---|
528 |
|
---|
529 |
|
---|
530 | // define all the macros which are related to pages generated
|
---|
531 | // by this action. we also load up the formatinfo structure
|
---|
532 | // here (it's used in do_action as well as here)
|
---|
533 | void documentaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
534 | recptprotolistclass *protos, ostream &logout) {
|
---|
535 |
|
---|
536 | // define_internal_macros sets the following macros:
|
---|
537 |
|
---|
538 | // _pagetitle_ the title to be displayed at the top of the browser window
|
---|
539 |
|
---|
540 | // _imagethispage_ the title image to be displayed at top right of page
|
---|
541 |
|
---|
542 | // _navarrows_ this may be overridden to "" when format option
|
---|
543 | // DocumentArrowsBottom is false
|
---|
544 |
|
---|
545 | // _header_ the header macro is overridden if we're not at a top level
|
---|
546 | // classification to remove the title block
|
---|
547 |
|
---|
548 | // _thisOID_ the OID (directory) of the current document - this corresponds
|
---|
549 | // to the archivedir metadata element
|
---|
550 |
|
---|
551 | // must have a valid collection server to continue
|
---|
552 | text_t &collection = args["c"];
|
---|
553 | if (collection.empty()) return;
|
---|
554 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
555 | if (collectproto == NULL) return;
|
---|
556 |
|
---|
557 | text_tset metadata;
|
---|
558 | FilterResponse_t response;
|
---|
559 | text_t &arg_d = args["d"];
|
---|
560 | text_t &arg_cl = args["cl"];
|
---|
561 |
|
---|
562 | if (!formatinfo.DocumentArrowsBottom)
|
---|
563 | disp.setmacro("navarrows", "document", "");
|
---|
564 |
|
---|
565 | metadata.insert ("Title");
|
---|
566 |
|
---|
567 | bool fulltoc = false;
|
---|
568 |
|
---|
569 | if (args["cl"] != "search") {
|
---|
570 | // see if there's a FullTOC string
|
---|
571 | text_t cl_top, full_toc;
|
---|
572 | get_top (arg_cl, cl_top);
|
---|
573 | if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
|
---|
574 | if (full_toc == "true") fulltoc = true;
|
---|
575 | }
|
---|
576 |
|
---|
577 | if (!arg_d.empty() && !fulltoc) {
|
---|
578 | // we're at document level
|
---|
579 |
|
---|
580 | metadata.insert ("archivedir");
|
---|
581 |
|
---|
582 | comerror_t err;
|
---|
583 | OptionValue_tarray options;
|
---|
584 | // we need to do the query again for the z3950proto
|
---|
585 | if (collectproto->get_protocol_name(err)=="z3950proto") {
|
---|
586 | OptionValue_t opt;
|
---|
587 | opt.name="Term";opt.value=args["q"];options.push_back(opt);
|
---|
588 | opt.name="QueryType";
|
---|
589 | opt.value=(args.getintarg("t")) ? "ranked" : "boolean";
|
---|
590 | options.push_back(opt);
|
---|
591 | opt.name="Index";opt.value=args["h"];options.push_back(opt);
|
---|
592 | }
|
---|
593 |
|
---|
594 | //do not display relation metadata
|
---|
595 | disp.setmacro ("relateddoc", "document", "");
|
---|
596 |
|
---|
597 | //if preferences indicate relevant docs should be collected
|
---|
598 | //and there is no particular format specified then display
|
---|
599 | //this default format.
|
---|
600 | if(args["rd"] == "1" && formatinfo.RelatedDocuments.empty()){
|
---|
601 |
|
---|
602 | text_t relation = ""; //string for displaying relation metadata
|
---|
603 |
|
---|
604 | //call function in formattools.cpp which will return the text of the
|
---|
605 | //related documents in a vertical list. This is the default format.
|
---|
606 | if (get_info (arg_d, collection, metadata, options, false, collectproto, response, logout))
|
---|
607 | relation += get_related_docs(collection, collectproto, response.docInfo[0], logout);
|
---|
608 |
|
---|
609 | //set macro to be the related document string
|
---|
610 | disp.setmacro ("relateddoc", "document", relation);
|
---|
611 | }
|
---|
612 |
|
---|
613 |
|
---|
614 | // get metadata for this document and it's parents
|
---|
615 | if (get_info (arg_d, collection, metadata, options,
|
---|
616 | true, collectproto, response, logout)) {
|
---|
617 |
|
---|
618 | disp.setmacro ("header", "document", "_textheader_");
|
---|
619 |
|
---|
620 | text_tarray pagetitlearray;
|
---|
621 | if (!response.docInfo[0].metadata["Title"].values[0].empty())
|
---|
622 | pagetitlearray.push_back (response.docInfo[0].metadata["Title"].values[0]);
|
---|
623 |
|
---|
624 | if (args["gt"] != "1") {
|
---|
625 | MetadataInfo_t *parenttitle = response.docInfo[0].metadata["Title"].parent;
|
---|
626 | while (parenttitle != NULL) {
|
---|
627 | if (!parenttitle->values[0].empty())
|
---|
628 | pagetitlearray.push_back (parenttitle->values[0]);
|
---|
629 | parenttitle = parenttitle->parent;
|
---|
630 | }
|
---|
631 | }
|
---|
632 | reverse (pagetitlearray.begin(), pagetitlearray.end());
|
---|
633 | text_t pagetitle;
|
---|
634 | joinchar (pagetitlearray, ": ", pagetitle);
|
---|
635 | disp.setmacro ("pagetitle", "document", pagetitle);
|
---|
636 |
|
---|
637 | if (is_top (arg_d))
|
---|
638 | disp.setmacro ("thisOID", "Global", dm_safe(response.docInfo[0].metadata["archivedir"].values[0]));
|
---|
639 | else {
|
---|
640 | MetadataInfo_t *parentad = response.docInfo[0].metadata["archivedir"].parent;
|
---|
641 | text_t thisOID;
|
---|
642 | while (parentad != NULL) {
|
---|
643 | thisOID = parentad->values[0];
|
---|
644 | parentad = parentad->parent;
|
---|
645 | }
|
---|
646 | disp.setmacro ("thisOID", "Global", dm_safe(thisOID));
|
---|
647 | }
|
---|
648 | }
|
---|
649 | } else {
|
---|
650 | if (!arg_cl.empty()) {
|
---|
651 |
|
---|
652 | // get metadata for top level classification
|
---|
653 | text_t classtop;
|
---|
654 | get_top (arg_cl, classtop);
|
---|
655 | metadata.insert ("childtype");
|
---|
656 | metadata.insert ("parameters");
|
---|
657 |
|
---|
658 | if (get_info (classtop, collection, metadata, false, collectproto, response, logout)) {
|
---|
659 |
|
---|
660 | text_t &title = response.docInfo[0].metadata["Title"].values[0];
|
---|
661 | bool unknown = false;
|
---|
662 |
|
---|
663 | // test the _XXXwidth_ macro to see if image macros are
|
---|
664 | // defined for this type of classification - if not we'll
|
---|
665 | // just display the text
|
---|
666 | text_t tmp;
|
---|
667 | disp.expandstring ("document", "_" + title + "width_", tmp);
|
---|
668 | if (tmp == ("_" + title + "width_")) unknown = true;
|
---|
669 |
|
---|
670 | if (unknown) {
|
---|
671 | disp.setmacro ("pagetitle", "document", title);
|
---|
672 | disp.setmacro ("imagethispage", "document", "<h2>" + title + "</h2>");
|
---|
673 | } else {
|
---|
674 | disp.setmacro ("pagetitle", "document", "_text" + title + "page_");
|
---|
675 | disp.setmacro ("imagethispage", "document", "_icon" + title + "page_");
|
---|
676 | }
|
---|
677 |
|
---|
678 | //if the document is not a document from a collection
|
---|
679 | //we must set the macro to be an empty string
|
---|
680 | disp.setmacro ("relateddoc", "document", "");
|
---|
681 |
|
---|
682 | // Add macros specific to the Phind lassifier
|
---|
683 | text_t &childtype = response.docInfo[0].metadata["childtype"].values[0];
|
---|
684 | if (childtype == "Phind") {
|
---|
685 |
|
---|
686 | // First, a macro to display the phind classifier
|
---|
687 | disp.setmacro ("phindclassifier", "document", "_phindapplet_");
|
---|
688 |
|
---|
689 | // Next, macros that control the way the classifier is displayed
|
---|
690 | text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
|
---|
691 |
|
---|
692 | // extract key=value pairs and set as macros
|
---|
693 | text_t::iterator here = parameters.begin();
|
---|
694 | text_t::iterator end = parameters.end();
|
---|
695 | text_t key, value;
|
---|
696 |
|
---|
697 | while (here != end) {
|
---|
698 | // get the next key and value pair
|
---|
699 | here = getdelimitstr (here, end, '=', key);
|
---|
700 | here = getdelimitstr (here, end, ';', value);
|
---|
701 |
|
---|
702 | // store this key=value pair
|
---|
703 | if (!key.empty() && !value.empty()) {
|
---|
704 | disp.setmacro (key, "document", value);
|
---|
705 | }
|
---|
706 | }
|
---|
707 | } // end if (childtype == "Phind")
|
---|
708 | }
|
---|
709 | } // end if (!arg_cl.empty()) {
|
---|
710 | }
|
---|
711 | }
|
---|
712 |
|
---|
713 |
|
---|
714 | bool documentaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
|
---|
715 | browsermapclass *browsers, displayclass &disp,
|
---|
716 | outconvertclass &outconvert, ostream &textout,
|
---|
717 | ostream &logout) {
|
---|
718 |
|
---|
719 | // must have a valid collection server
|
---|
720 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
721 | if (collectproto == NULL) {
|
---|
722 | logout << "documentaction::do_action called with NULL collectproto\n";
|
---|
723 | textout << outconvert << disp << "_document:header_\n"
|
---|
724 | << "Error: Attempt to get document without setting collection\n"
|
---|
725 | << "_document:footer_\n";
|
---|
726 | } else {
|
---|
727 |
|
---|
728 | text_t OID = args["d"];
|
---|
729 | if (OID.empty()) OID = args["cl"];
|
---|
730 | if (OID.empty()) {
|
---|
731 | textout << outconvert << disp << "Document contains no data_document:footer_\n";
|
---|
732 | return true;
|
---|
733 | }
|
---|
734 |
|
---|
735 |
|
---|
736 | if (formatinfo.DocumentUseHTML && !args["d"].empty()) {
|
---|
737 |
|
---|
738 | if (args["f"] == "1") {
|
---|
739 | textout << outconvert << disp
|
---|
740 | << "<html><head></head>\n"
|
---|
741 | << "<frameset rows=\"68,*\" noresize border=0>\n"
|
---|
742 | << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
|
---|
743 | << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d="
|
---|
744 | << args["d"] << "\">"
|
---|
745 | << "<noframes>\n"
|
---|
746 | << "<p>You must have a frame enabled browser to view this.</p>\n"
|
---|
747 | << "</noframes>\n"
|
---|
748 | << "</frameset>\n"
|
---|
749 | << "</html>\n";
|
---|
750 | } else {
|
---|
751 | output_document (OID, args, collectproto, disp, outconvert, textout, logout);
|
---|
752 | }
|
---|
753 | return true;
|
---|
754 | }
|
---|
755 |
|
---|
756 |
|
---|
757 | textout << outconvert << disp << "_document:header_\n"
|
---|
758 | << "_document:content_\n";
|
---|
759 |
|
---|
760 | // output the table of contents
|
---|
761 | output_toc (args, browsers, formatinfo, collectproto,
|
---|
762 | disp, outconvert, textout, logout);
|
---|
763 |
|
---|
764 | //output the related documents (may be the empty string)
|
---|
765 | //will not output the docs if a format string is specified
|
---|
766 | textout << outconvert << disp << "_document:relateddoc_\n";
|
---|
767 |
|
---|
768 | // output the document text
|
---|
769 | if (!args["d"].empty()) {
|
---|
770 | textout << "<p>\n";
|
---|
771 | output_document (OID, args, collectproto, disp, outconvert, textout, logout);
|
---|
772 | }
|
---|
773 |
|
---|
774 | textout << outconvert << disp << "_document:footer_\n";
|
---|
775 | }
|
---|
776 | return true;
|
---|
777 | }
|
---|
778 |
|
---|
779 | void documentaction::output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
|
---|
780 | const TermInfo_tarray &terminfo, const text_t &OID,
|
---|
781 | bool highlight, int hastxt, int wanttext,
|
---|
782 | text_t &collection, recptproto *collectproto,
|
---|
783 | displayclass &disp, outconvertclass &outconvert,
|
---|
784 | ostream &textout, ostream &logout) {
|
---|
785 |
|
---|
786 | DocumentRequest_t docrequest;
|
---|
787 | DocumentResponse_t docresponse;
|
---|
788 | comerror_t err;
|
---|
789 |
|
---|
790 | if (hastxt == 1) {
|
---|
791 |
|
---|
792 | if (wanttext) {
|
---|
793 | // get the text
|
---|
794 | docrequest.OID = OID;
|
---|
795 | collectproto->get_document (collection, docrequest, docresponse, err, logout);
|
---|
796 |
|
---|
797 | // cut down on overhead by not using formattools if we only want the text
|
---|
798 | // (wanttext will equal 2 if we want text and other stuff too)
|
---|
799 | if (wanttext == 1)
|
---|
800 | if (highlight)
|
---|
801 | highlighttext(docresponse.doc, terminfo, disp, outconvert, textout, logout);
|
---|
802 | else
|
---|
803 | textout << outconvert << disp << docresponse.doc;
|
---|
804 | }
|
---|
805 |
|
---|
806 | if (wanttext != 1) {
|
---|
807 | text_t doctext
|
---|
808 | = get_formatted_string (collection, collectproto,
|
---|
809 | docinfo, disp, formatlistptr, docresponse.doc,
|
---|
810 | logout);
|
---|
811 |
|
---|
812 | if (highlight)
|
---|
813 | highlighttext(doctext, terminfo, disp, outconvert, textout, logout);
|
---|
814 | else
|
---|
815 | textout << outconvert << disp << doctext;
|
---|
816 | }
|
---|
817 | }
|
---|
818 | }
|
---|
819 |
|
---|
820 |
|
---|
821 | void documentaction::output_document (const text_t &OID, cgiargsclass &args,
|
---|
822 | recptproto *collectproto, displayclass &disp,
|
---|
823 | outconvertclass &outconvert, ostream &textout,
|
---|
824 | ostream &logout) {
|
---|
825 | FilterResponse_t inforesponse;
|
---|
826 | FilterResponse_t queryresponse;
|
---|
827 | text_tset metadata;
|
---|
828 | bool getParents = false;
|
---|
829 | bool highlight = false;
|
---|
830 | int wanttext = 0;
|
---|
831 | int arg_gt = args.getintarg("gt");
|
---|
832 | text_t &collection = args["c"];
|
---|
833 |
|
---|
834 | // if we have a query string and highlighting is turned on we need
|
---|
835 | // to redo the query to get the terms for highlighting
|
---|
836 | if (!args["q"].empty() && args.getintarg("hl")) {
|
---|
837 | FilterRequest_t request;
|
---|
838 | comerror_t err;
|
---|
839 | request.filterResultOptions = FRmatchTerms;
|
---|
840 | text_t formattedstring = args["q"];
|
---|
841 | format_querystring (formattedstring, args.getintarg("b"));
|
---|
842 | set_queryfilter_options (request, formattedstring, args);
|
---|
843 | collectproto->filter (args["c"], request, queryresponse, err, logout);
|
---|
844 | if (err != noError) {
|
---|
845 | outconvertclass text_t2ascii;
|
---|
846 | logout << text_t2ascii
|
---|
847 | << "documentaction::output_document: call to QueryFilter failed "
|
---|
848 | << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
|
---|
849 | highlight = false;
|
---|
850 | } else {
|
---|
851 | highlight = true;
|
---|
852 | }
|
---|
853 | }
|
---|
854 |
|
---|
855 |
|
---|
856 | format_t *formatlistptr = new format_t();
|
---|
857 | parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
|
---|
858 |
|
---|
859 | metadata.insert ("hastxt");
|
---|
860 | metadata.insert ("haschildren");
|
---|
861 |
|
---|
862 | if (formatinfo.DocumentText == "[Text]")
|
---|
863 | wanttext = 1;
|
---|
864 | else {
|
---|
865 | char *docformat = formatinfo.DocumentText.getcstr();
|
---|
866 | if (strstr (docformat, "[Text]") != NULL)
|
---|
867 | wanttext = 2;
|
---|
868 | delete docformat;
|
---|
869 | }
|
---|
870 |
|
---|
871 | if (get_info (OID, collection, metadata, getParents, collectproto, inforesponse, logout)) {
|
---|
872 | int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
|
---|
873 | int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
|
---|
874 |
|
---|
875 | if (arg_gt == 0) {
|
---|
876 | output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
|
---|
877 | OID, highlight, hastxt, wanttext, collection, collectproto,
|
---|
878 | disp, outconvert, textout, logout);
|
---|
879 |
|
---|
880 |
|
---|
881 | } else {
|
---|
882 |
|
---|
883 | ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
|
---|
884 |
|
---|
885 | // text is to be expanded
|
---|
886 | text_t exOID = OID;
|
---|
887 | if (haschildren != 1) exOID = get_parent (OID);
|
---|
888 | if (exOID.empty()) exOID = OID;
|
---|
889 |
|
---|
890 | // if we're not in a document (i.e. we're in a top level classification)
|
---|
891 | // we need to pass "is_classify = true" to get_contents so that it
|
---|
892 | // doesn't recurse all the way through each document in the classification
|
---|
893 | bool is_classify = false;
|
---|
894 | if (args["d"].empty()) is_classify = true;
|
---|
895 |
|
---|
896 | get_contents (exOID, is_classify, metadata, collection,
|
---|
897 | collectproto, inforesponse, logout);
|
---|
898 |
|
---|
899 | ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
|
---|
900 | ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
|
---|
901 |
|
---|
902 | if (arg_gt == 1) {
|
---|
903 | // check if there are more than 10 sections containing text to be expanded -
|
---|
904 | // if there are output warning message - this isn't a great way to do this
|
---|
905 | // since the sections may be very large or very small - one day I'll fix it
|
---|
906 | // -- Stefan.
|
---|
907 | int seccount = 0;
|
---|
908 | while (sechere != secend) {
|
---|
909 | int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
|
---|
910 | if (shastxt == 1) seccount ++;
|
---|
911 | if (seccount > 10) break;
|
---|
912 | sechere ++;
|
---|
913 | }
|
---|
914 | if (seccount > 10) {
|
---|
915 | // more than 10 sections so output warning message and text
|
---|
916 | // for current section only
|
---|
917 | textout << outconvert << disp << "_document:textltwarning_";
|
---|
918 |
|
---|
919 | output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
|
---|
920 | OID, highlight, hastxt, wanttext, collection,
|
---|
921 | collectproto, disp, outconvert, textout, logout);
|
---|
922 |
|
---|
923 | }
|
---|
924 | else arg_gt = 2;
|
---|
925 | }
|
---|
926 |
|
---|
927 | if (arg_gt == 2) {
|
---|
928 | // get the text for each section
|
---|
929 | sechere = inforesponse.docInfo.begin();
|
---|
930 | int count = 0;
|
---|
931 | while (sechere != secend) {
|
---|
932 | textout << outconvert << disp << "\n<p><a name=" << (*sechere).OID << "></a>\n";
|
---|
933 |
|
---|
934 | int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
|
---|
935 |
|
---|
936 | output_text (*sechere, formatlistptr, queryresponse.termInfo,
|
---|
937 | (*sechere).OID, highlight, shastxt, wanttext, collection,
|
---|
938 | collectproto, disp, outconvert, textout, logout);
|
---|
939 | count ++;
|
---|
940 | sechere ++;
|
---|
941 | }
|
---|
942 | }
|
---|
943 | }
|
---|
944 | }
|
---|
945 | delete formatlistptr;
|
---|
946 | }
|
---|
947 |
|
---|
948 | // highlighttext highlights query terms in text string and outputs the resulting text string
|
---|
949 | void documentaction::highlighttext(text_t &text, const TermInfo_tarray &terms,
|
---|
950 | displayclass &disp, outconvertclass &outconvert,
|
---|
951 | ostream &textout, ostream &/*logout*/) {
|
---|
952 |
|
---|
953 | text_tmap allterms;
|
---|
954 | text_tmap::const_iterator it;
|
---|
955 |
|
---|
956 | // first load all the term variations into a map
|
---|
957 | TermInfo_tarray::const_iterator this_term = terms.begin();
|
---|
958 | TermInfo_tarray::const_iterator last_term = terms.end();
|
---|
959 | while (this_term != last_term) {
|
---|
960 | text_tarray::const_iterator this_var = (*this_term).matchTerms.begin();
|
---|
961 | text_tarray::const_iterator last_var = (*this_term).matchTerms.end();
|
---|
962 | while (this_var != last_var) {
|
---|
963 | allterms[*this_var] = 1;
|
---|
964 | this_var ++;
|
---|
965 | }
|
---|
966 | this_term ++;
|
---|
967 | }
|
---|
968 |
|
---|
969 | // get the text to start and end a hightlight
|
---|
970 | text_t starthighlight = "<b><u>";
|
---|
971 | text_t endhighlight = "</u></b>";
|
---|
972 | if (disp.isdefaultmacro("Global", "starthighlight"))
|
---|
973 | disp.expandstring("Global", "_starthighlight_", starthighlight);
|
---|
974 | if (disp.isdefaultmacro("Global", "endhighlight"))
|
---|
975 | disp.expandstring("Global", "_endhighlight_", endhighlight);
|
---|
976 |
|
---|
977 |
|
---|
978 | text_t::iterator here = text.begin();
|
---|
979 | text_t::iterator end = text.end();
|
---|
980 | text_t word, buffer;
|
---|
981 | while (here != end) {
|
---|
982 | if (is_unicode_letdig(*here)) {
|
---|
983 | // not word boundary
|
---|
984 | word.push_back(*here);
|
---|
985 | here++;
|
---|
986 |
|
---|
987 | } else {
|
---|
988 | // found word boundary
|
---|
989 | // add last word if there was one
|
---|
990 | if (!word.empty()) {
|
---|
991 | it = allterms.find(word);
|
---|
992 | if (it != allterms.end()) {
|
---|
993 | word = starthighlight + word + endhighlight;
|
---|
994 | }
|
---|
995 | buffer += word;
|
---|
996 | word.clear();
|
---|
997 | }
|
---|
998 |
|
---|
999 | if (*here == '<') {
|
---|
1000 | // skip over rest of html tag
|
---|
1001 | while ((here != end) && (*here != '>')) {
|
---|
1002 | buffer.push_back(*here);
|
---|
1003 | here++;
|
---|
1004 | }
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 | buffer.push_back(*here);
|
---|
1008 | here++;
|
---|
1009 |
|
---|
1010 | if (buffer.size() > 1024) {
|
---|
1011 | textout << outconvert << disp << buffer;
|
---|
1012 | buffer.clear();
|
---|
1013 | }
|
---|
1014 | }
|
---|
1015 | }
|
---|
1016 | textout << outconvert << disp << buffer;
|
---|
1017 | }
|
---|