[2369] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * browseaction.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 |
|
---|
[7371] | 26 | #include "gsdl_modules_cfg.h"
|
---|
| 27 | #ifdef GSDL_USE_BROWSE_ACTION
|
---|
| 28 |
|
---|
[2369] | 29 | #include "browseaction.h"
|
---|
[2449] | 30 | #include "querytools.h"
|
---|
[2456] | 31 | #include "browseactiontools.h"
|
---|
[15418] | 32 | #include "recptprototools.h"
|
---|
[2369] | 33 |
|
---|
[2387] | 34 | browseaction::browseaction(){
|
---|
[2369] | 35 |
|
---|
[2461] | 36 |
|
---|
[2398] | 37 |
|
---|
[2387] | 38 | cgiarginfo arg_ainfo;
|
---|
| 39 | arg_ainfo.shortname = "a";
|
---|
| 40 | arg_ainfo.longname = "action";
|
---|
| 41 | arg_ainfo.multiplechar = true;
|
---|
[22984] | 42 | arg_ainfo.multiplevalue = false;
|
---|
[2387] | 43 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 44 | arg_ainfo.argdefault = "br";
|
---|
| 45 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 46 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 47 |
|
---|
| 48 | //the first browsing criterion -- collection metadata types
|
---|
| 49 | arg_ainfo.shortname = "b1";
|
---|
| 50 | arg_ainfo.longname = "browse criterion 1";
|
---|
| 51 | arg_ainfo.multiplechar = false;
|
---|
[22984] | 52 | arg_ainfo.multiplevalue = false;
|
---|
[2404] | 53 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[2387] | 54 | arg_ainfo.argdefault = "0";
|
---|
| 55 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 56 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 57 |
|
---|
| 58 | //the second browsing criterion -- collection metadata types + none - meaning
|
---|
| 59 | //only one browsing criterion. None is the default.
|
---|
| 60 | arg_ainfo.shortname = "b2";
|
---|
| 61 | arg_ainfo.longname = "browse criterion 2";
|
---|
| 62 | arg_ainfo.multiplechar = false;
|
---|
[22984] | 63 | arg_ainfo.multiplevalue = false;
|
---|
[2404] | 64 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[2387] | 65 | arg_ainfo.argdefault = "0";
|
---|
| 66 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 67 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 68 |
|
---|
| 69 | //the number of documents to show per page -- if the box is empty then
|
---|
| 70 | //only the most basic divisions are made (so, first letter for A-Z, year
|
---|
| 71 | //for date).
|
---|
| 72 | arg_ainfo.shortname = "bnu";
|
---|
| 73 | arg_ainfo.longname = "browse docs per page";
|
---|
| 74 | arg_ainfo.multiplechar = true;
|
---|
[22984] | 75 | arg_ainfo.multiplevalue = false;
|
---|
[2387] | 76 | arg_ainfo.defaultstatus = cgiarginfo::good;
|
---|
[7426] | 77 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[2387] | 78 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 79 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 80 |
|
---|
| 81 | //The text to filter documents for browsing (only documents containing these
|
---|
| 82 | //words will be browsed).
|
---|
| 83 | arg_ainfo.shortname = "bft";
|
---|
| 84 | arg_ainfo.longname = "browse filter text";
|
---|
| 85 | arg_ainfo.multiplechar = true;
|
---|
[22984] | 86 | arg_ainfo.multiplevalue = false;
|
---|
[2387] | 87 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7426] | 88 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[2387] | 89 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 90 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 91 |
|
---|
[2404] | 92 |
|
---|
| 93 | //Whether all or just some of the words in the filter box have to be present
|
---|
| 94 | //0 - any 1- all
|
---|
| 95 | arg_ainfo.shortname = "bt";
|
---|
| 96 | arg_ainfo.longname = "browse all or any";
|
---|
| 97 | arg_ainfo.multiplechar = false;
|
---|
[22984] | 98 | arg_ainfo.multiplevalue = false;
|
---|
[2404] | 99 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 100 | arg_ainfo.argdefault = "0";
|
---|
| 101 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
[22984] | 102 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[2398] | 103 |
|
---|
[2387] | 104 | }
|
---|
| 105 |
|
---|
[2369] | 106 | browseaction::~browseaction(){}
|
---|
| 107 |
|
---|
| 108 | bool browseaction::init (ostream &logout){
|
---|
| 109 | return true;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | void browseaction::configure (const text_t &key, const text_tarray &cfgline){
|
---|
[2449] | 113 | action::configure(key, cfgline);
|
---|
[2369] | 114 | }
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | bool browseaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
|
---|
[3546] | 119 | recptprotolistclass * /*protos*/, ostream &/*logout*/) {
|
---|
[2369] | 120 | // don't want to check anything yet.
|
---|
[2461] | 121 |
|
---|
[2369] | 122 | return true;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | void browseaction::get_cgihead_info (cgiargsclass &args,
|
---|
| 127 | recptprotolistclass *protos,
|
---|
| 128 | response_t &response,
|
---|
| 129 | text_t &response_data,
|
---|
| 130 | ostream &logout){
|
---|
[2398] | 131 | response = content;
|
---|
| 132 | response_data = "text/html";
|
---|
[2404] | 133 |
|
---|
[2461] | 134 |
|
---|
[2369] | 135 | }
|
---|
| 136 |
|
---|
| 137 | void browseaction::define_internal_macros (displayclass &disp,
|
---|
| 138 | cgiargsclass &args,
|
---|
| 139 | recptprotolistclass *protos,
|
---|
| 140 | ostream &logout){
|
---|
[2464] | 141 |
|
---|
[2369] | 142 | }
|
---|
| 143 |
|
---|
| 144 | void browseaction::define_external_macros (displayclass &disp,
|
---|
| 145 | cgiargsclass &args,
|
---|
| 146 | recptprotolistclass *protos,
|
---|
| 147 | ostream &logout){
|
---|
[2461] | 148 |
|
---|
[2369] | 149 | }
|
---|
| 150 |
|
---|
| 151 | bool browseaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
|
---|
[2464] | 152 | browsermapclass *browsers, displayclass &disp,
|
---|
| 153 | outconvertclass &outconvert, ostream &textout,
|
---|
| 154 | ostream &logout){
|
---|
| 155 |
|
---|
[2449] | 156 | if(args["c"].empty()) return false;
|
---|
| 157 | else if(get_document_list(args, protos, browsers, disp, outconvert, textout,
|
---|
| 158 | logout)) return true;
|
---|
| 159 | else return false;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | bool browseaction::get_document_list(cgiargsclass &args,
|
---|
| 163 | recptprotolistclass *protos, browsermapclass *browsers,
|
---|
| 164 | displayclass &disp, outconvertclass &outconvert,
|
---|
| 165 | ostream &textout, ostream &logout){
|
---|
[2404] | 166 |
|
---|
[2449] | 167 | text_t collection = args["c"];
|
---|
| 168 | comerror_t err;
|
---|
[2456] | 169 | text_t list_type = "VList"; //result display type
|
---|
[2449] | 170 |
|
---|
| 171 | //check that the protocol is alive
|
---|
| 172 | recptproto* colproto = protos->getrecptproto (collection, logout);
|
---|
| 173 | if(colproto == NULL) {
|
---|
| 174 | logout << outconvert << "ERROR: Null collection protocol trying to browse "
|
---|
| 175 | << collection << "\n";
|
---|
| 176 | return false;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | //check the collection is responding/in place
|
---|
| 180 | ColInfoResponse_t *colinfo = recpt->get_collectinfo_ptr(colproto, collection,
|
---|
| 181 | logout);
|
---|
| 182 | if(colinfo == NULL){
|
---|
| 183 | logout << outconvert << "ERROR: Null returned for get_collectinfo_ptr on "
|
---|
| 184 | << collection << "in browseaction\n";
|
---|
| 185 | return false;
|
---|
| 186 | }
|
---|
[2456] | 187 |
|
---|
| 188 | browserclass* br_ptr = browsers->getbrowser(list_type);
|
---|
| 189 |
|
---|
| 190 | FilterRequest_t request;
|
---|
| 191 | FilterResponse_t response;
|
---|
| 192 |
|
---|
| 193 | //set up browser structure
|
---|
| 194 | br_ptr->set_filter_options(request, args);
|
---|
[7426] | 195 | request.filterLang = args["l"];
|
---|
[2456] | 196 | br_ptr->load_metadata_defaults(request.fields);
|
---|
| 197 |
|
---|
| 198 | //set up format information
|
---|
| 199 | format_t* formatptr = new format_t();
|
---|
| 200 | parse_formatstring(br_ptr->get_default_formatstring(), formatptr,
|
---|
| 201 | request.fields, request.getParents);
|
---|
| 202 |
|
---|
| 203 | request.filterResultOptions = FROID | FRmetadata;
|
---|
[2449] | 204 |
|
---|
[7426] | 205 | text_t bf_string = g_EmptyText;
|
---|
[2490] | 206 | format_browsestring(args["bft"],bf_string,args.getintarg("bt"));
|
---|
| 207 |
|
---|
| 208 | set_browsefilter_options(request, bf_string, args);
|
---|
| 209 |
|
---|
[2459] | 210 | //set up browse filter string;
|
---|
| 211 | if(!args["bft"].empty()){
|
---|
| 212 |
|
---|
[2464] | 213 | colproto->filter (collection, request, response, err, logout);
|
---|
| 214 | if (err != noError) {
|
---|
| 215 | outconvertclass text_t2ascii;
|
---|
| 216 | logout << text_t2ascii
|
---|
| 217 | << "browseaction::get_document_list QueryFilter failed "
|
---|
| 218 | << "for " << collection << " collection ("
|
---|
| 219 | << get_comerror_string (err) << ")\n";
|
---|
| 220 | return false;
|
---|
| 221 | }// if (err != noError)
|
---|
| 222 |
|
---|
[2612] | 223 | }// end if(!args["bft"].empty())
|
---|
[2504] | 224 | else {
|
---|
| 225 | text_tset metadata_items;
|
---|
| 226 | text_t temp = "Title";
|
---|
| 227 | metadata_items.insert(temp);
|
---|
| 228 | temp = "browselist";
|
---|
[7426] | 229 | if (!get_children(temp, args["c"], args["l"], metadata_items, false, colproto,
|
---|
[2504] | 230 | response,logout)) return false;
|
---|
| 231 | }
|
---|
[2612] | 232 |
|
---|
| 233 | //get rid of documents that do not have the metadata element classified on
|
---|
| 234 | if(!remove_no_meta_results("Title",response, outconvert)) {
|
---|
| 235 | return false;
|
---|
| 236 | logout<<"ERROR: browseactiontools::remove_no_meta_results failed"<<endl;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
[2464] | 239 | textout << outconvert << disp << "_browse:header_\n" <<"_browse:content_";
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | bool use_table = is_table_content (formatptr);
|
---|
| 243 | br_ptr->output_section_group (response, args, collection, 0, formatptr,
|
---|
| 244 | use_table, request.fields, request.getParents,
|
---|
| 245 | colproto, disp, outconvert, textout, logout);
|
---|
| 246 |
|
---|
| 247 | textout << outconvert << disp << "_browse:footer_";
|
---|
[2456] | 248 |
|
---|
| 249 |
|
---|
| 250 |
|
---|
[2369] | 251 | return true;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
[7371] | 254 | #endif //GSDL_USE_BROWSE_ACTION
|
---|