source: main/trunk/greenstone2/runtime-src/src/recpt/browseaction.cpp@ 22984

Last change on this file since 22984 was 22984, checked in by ak19, 14 years ago
  1. Undoing commit of 22934 where decode_commas was called on stem and fold comma separated list: previously separated due to url-encoding of commas. Now that the problem has been fixed at the source, the decode_commas hack is no longer necessary. 2. Commas in stem and fold are no longer url-encoded because the multiple_value field of the continuously-reused struct arg_ainfo is always set back to the default false after ever being set to true. So it no longer subtly stays at true to affect Greenstone functioning in unforeseen ways (such as suddenly and unnecessarily URL-encoding commas where this is not wanted).
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
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
26#include "gsdl_modules_cfg.h"
27#ifdef GSDL_USE_BROWSE_ACTION
28
29#include "browseaction.h"
30#include "querytools.h"
31#include "browseactiontools.h"
32#include "recptprototools.h"
33
34browseaction::browseaction(){
35
36
37
38 cgiarginfo arg_ainfo;
39 arg_ainfo.shortname = "a";
40 arg_ainfo.longname = "action";
41 arg_ainfo.multiplechar = true;
42 arg_ainfo.multiplevalue = false;
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;
52 arg_ainfo.multiplevalue = false;
53 arg_ainfo.defaultstatus = cgiarginfo::weak;
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;
63 arg_ainfo.multiplevalue = false;
64 arg_ainfo.defaultstatus = cgiarginfo::weak;
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;
75 arg_ainfo.multiplevalue = false;
76 arg_ainfo.defaultstatus = cgiarginfo::good;
77 arg_ainfo.argdefault = g_EmptyText;
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;
86 arg_ainfo.multiplevalue = false;
87 arg_ainfo.defaultstatus = cgiarginfo::none;
88 arg_ainfo.argdefault = g_EmptyText;
89 arg_ainfo.savedarginfo = cgiarginfo::must;
90 argsinfo.addarginfo (NULL, arg_ainfo);
91
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;
98 arg_ainfo.multiplevalue = false;
99 arg_ainfo.defaultstatus = cgiarginfo::weak;
100 arg_ainfo.argdefault = "0";
101 arg_ainfo.savedarginfo = cgiarginfo::must;
102 argsinfo.addarginfo (NULL, arg_ainfo);
103
104}
105
106browseaction::~browseaction(){}
107
108bool browseaction::init (ostream &logout){
109 return true;
110}
111
112void browseaction::configure (const text_t &key, const text_tarray &cfgline){
113 action::configure(key, cfgline);
114}
115
116
117
118bool browseaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
119 recptprotolistclass * /*protos*/, ostream &/*logout*/) {
120 // don't want to check anything yet.
121
122 return true;
123}
124
125
126void browseaction::get_cgihead_info (cgiargsclass &args,
127 recptprotolistclass *protos,
128 response_t &response,
129 text_t &response_data,
130 ostream &logout){
131 response = content;
132 response_data = "text/html";
133
134
135}
136
137void browseaction::define_internal_macros (displayclass &disp,
138 cgiargsclass &args,
139 recptprotolistclass *protos,
140 ostream &logout){
141
142}
143
144void browseaction::define_external_macros (displayclass &disp,
145 cgiargsclass &args,
146 recptprotolistclass *protos,
147 ostream &logout){
148
149}
150
151bool browseaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
152 browsermapclass *browsers, displayclass &disp,
153 outconvertclass &outconvert, ostream &textout,
154 ostream &logout){
155
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
162bool browseaction::get_document_list(cgiargsclass &args,
163 recptprotolistclass *protos, browsermapclass *browsers,
164 displayclass &disp, outconvertclass &outconvert,
165 ostream &textout, ostream &logout){
166
167 text_t collection = args["c"];
168 comerror_t err;
169 text_t list_type = "VList"; //result display type
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 }
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);
195 request.filterLang = args["l"];
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;
204
205 text_t bf_string = g_EmptyText;
206 format_browsestring(args["bft"],bf_string,args.getintarg("bt"));
207
208 set_browsefilter_options(request, bf_string, args);
209
210 //set up browse filter string;
211 if(!args["bft"].empty()){
212
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
223 }// end if(!args["bft"].empty())
224 else {
225 text_tset metadata_items;
226 text_t temp = "Title";
227 metadata_items.insert(temp);
228 temp = "browselist";
229 if (!get_children(temp, args["c"], args["l"], metadata_items, false, colproto,
230 response,logout)) return false;
231 }
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
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_";
248
249
250
251 return true;
252}
253
254#endif //GSDL_USE_BROWSE_ACTION
Note: See TracBrowser for help on using the repository browser.