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