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

Last change on this file since 21758 was 15418, checked in by mdewsnip, 16 years ago

(Untangling colservr/recpt) Split recpt/OIDtools into two: lib/OIDtools.cpp/h contains the purely string-based functions (may be used by the colservr), and recpt/recptprototools.cpp/h contains the functions requiring a call to the colservr (get_info() etc.).

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 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.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;
51 arg_ainfo.defaultstatus = cgiarginfo::weak;
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;
61 arg_ainfo.defaultstatus = cgiarginfo::weak;
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;
73 arg_ainfo.argdefault = g_EmptyText;
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;
83 arg_ainfo.argdefault = g_EmptyText;
84 arg_ainfo.savedarginfo = cgiarginfo::must;
85 argsinfo.addarginfo (NULL, arg_ainfo);
86
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);
97
98
99}
100
101browseaction::~browseaction(){}
102
103bool browseaction::init (ostream &logout){
104 return true;
105}
106
107void browseaction::configure (const text_t &key, const text_tarray &cfgline){
108 action::configure(key, cfgline);
109}
110
111
112
113bool browseaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
114 recptprotolistclass * /*protos*/, ostream &/*logout*/) {
115 // don't want to check anything yet.
116
117 return true;
118}
119
120
121void browseaction::get_cgihead_info (cgiargsclass &args,
122 recptprotolistclass *protos,
123 response_t &response,
124 text_t &response_data,
125 ostream &logout){
126 response = content;
127 response_data = "text/html";
128
129
130}
131
132void browseaction::define_internal_macros (displayclass &disp,
133 cgiargsclass &args,
134 recptprotolistclass *protos,
135 ostream &logout){
136
137}
138
139void browseaction::define_external_macros (displayclass &disp,
140 cgiargsclass &args,
141 recptprotolistclass *protos,
142 ostream &logout){
143
144}
145
146bool browseaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
147 browsermapclass *browsers, displayclass &disp,
148 outconvertclass &outconvert, ostream &textout,
149 ostream &logout){
150
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
157bool browseaction::get_document_list(cgiargsclass &args,
158 recptprotolistclass *protos, browsermapclass *browsers,
159 displayclass &disp, outconvertclass &outconvert,
160 ostream &textout, ostream &logout){
161
162 text_t collection = args["c"];
163 comerror_t err;
164 text_t list_type = "VList"; //result display type
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 }
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);
190 request.filterLang = args["l"];
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;
199
200 text_t bf_string = g_EmptyText;
201 format_browsestring(args["bft"],bf_string,args.getintarg("bt"));
202
203 set_browsefilter_options(request, bf_string, args);
204
205 //set up browse filter string;
206 if(!args["bft"].empty()){
207
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
218 }// end if(!args["bft"].empty())
219 else {
220 text_tset metadata_items;
221 text_t temp = "Title";
222 metadata_items.insert(temp);
223 temp = "browselist";
224 if (!get_children(temp, args["c"], args["l"], metadata_items, false, colproto,
225 response,logout)) return false;
226 }
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
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_";
243
244
245
246 return true;
247}
248
249#endif //GSDL_USE_BROWSE_ACTION
Note: See TracBrowser for help on using the repository browser.