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