source: trunk/gsdl/src/recpt/pageaction.cpp@ 604

Last change on this file since 604 was 604, checked in by sjboddie, 25 years ago

fixed a couple of problems with 'unknown' classifier

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1/**********************************************************************
2 *
3 * pageaction.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 * $Id: pageaction.cpp 604 1999-09-17 04:46:06Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.15 1999/09/17 04:46:05 sjboddie
31 fixed a couple of problems with 'unknown' classifier
32
33 Revision 1.14 1999/09/07 23:08:09 rjmcnab
34 Removed some compiler warnings
35
36 Revision 1.13 1999/09/07 04:56:57 sjboddie
37 added GPL notice
38
39 Revision 1.12 1999/09/02 00:26:43 rjmcnab
40 made the p cgi argument always saved in the compressed arguments
41
42 Revision 1.11 1999/08/25 04:48:43 sjboddie
43 changes to the home and about pages
44
45 Revision 1.10 1999/08/11 23:29:43 sjboddie
46 added support for html classifier (i.e. the hp argument)
47
48 Revision 1.9 1999/08/03 03:29:47 sjboddie
49 added ability to set receptionist from collect.cfg
50
51 Revision 1.8 1999/07/30 02:24:44 sjboddie
52 added collectinfo argument to some functions
53
54 Revision 1.7 1999/06/24 05:12:24 sjboddie
55 lots of small changes
56
57 Revision 1.6 1999/06/10 00:39:16 sjboddie
58 navigation bar is no longer written out for every page (it should
59 be included in the _content_ macro of pages wanting to display it).
60
61 Revision 1.5 1999/06/08 04:29:35 sjboddie
62 added argsinfo to the call to check_cgiargs to make it easy to set
63 args to their default if they're found to be screwed up
64
65 Revision 1.4 1999/02/28 20:00:14 rjmcnab
66
67
68 Fixed a few things.
69
70 Revision 1.3 1999/02/25 21:58:58 rjmcnab
71
72 Merged sources.
73
74 Revision 1.2 1999/02/21 22:33:54 rjmcnab
75
76 Lots of stuff :-)
77
78 Revision 1.1 1999/02/12 02:40:17 sjboddie
79
80 Added page action
81
82 */
83
84#include "OIDtools.h"
85#include "pageaction.h"
86#include "receptionist.h"
87#include <time.h>
88
89pageaction::pageaction () {
90
91 recpt = NULL;
92
93 // this action uses cgi variables "a", "p", and "hp"
94 cgiarginfo arg_ainfo;
95 arg_ainfo.shortname = "a";
96 arg_ainfo.longname = "action";
97 arg_ainfo.multiplechar = true;
98 arg_ainfo.defaultstatus = cgiarginfo::weak;
99 arg_ainfo.argdefault = "p";
100 arg_ainfo.savedarginfo = cgiarginfo::must;
101 argsinfo.addarginfo (NULL, arg_ainfo);
102
103 arg_ainfo.shortname = "p";
104 arg_ainfo.longname = "page";
105 arg_ainfo.multiplechar = true;
106 arg_ainfo.defaultstatus = cgiarginfo::weak;
107 arg_ainfo.argdefault = "about";
108 arg_ainfo.savedarginfo = cgiarginfo::must;
109 argsinfo.addarginfo (NULL, arg_ainfo);
110
111 arg_ainfo.shortname = "hp";
112 arg_ainfo.longname = "html page";
113 arg_ainfo.multiplechar = true;
114 arg_ainfo.defaultstatus = cgiarginfo::weak;
115 arg_ainfo.argdefault = "";
116 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
117 argsinfo.addarginfo (NULL, arg_ainfo);
118}
119
120pageaction::~pageaction () {
121}
122
123
124bool pageaction::init (ostream &logout) {
125
126 // classify_meta should contain names of all classifiers supported
127 // by this receptionist. classifications using metadata names not
128 // in this list will be displayed as "unknown"
129 classify_meta.insert ("Title");
130 classify_meta.insert ("List");
131 classify_meta.insert ("Creator");
132 classify_meta.insert ("Series");
133 classify_meta.insert ("Date");
134 classify_meta.insert ("Subject");
135 classify_meta.insert ("Organization");
136 classify_meta.insert ("Howto");
137 classify_meta.insert ("Topic");
138 classify_meta.insert ("Browse");
139 classify_meta.insert ("People");
140
141 return action::init (logout);
142}
143
144
145bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
146 ostream &/*logout*/) {
147 // don't want to check anything yet.
148 return true;
149}
150
151void pageaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
152 text_t &response_data, ostream &/*logout*/) {
153 response = content;
154 response_data = "text/html";
155}
156
157
158// define all the macros which might be used by other actions
159// to produce pages.
160void pageaction::define_external_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &/*disp*/,
161 cgiargsclass &/*args*/, recptproto * /*collectproto*/,
162 ostream &/*logout*/) {
163}
164
165
166void pageaction::define_internal_macros (const ColInfoResponse_t &collectinfo, displayclass &disp,
167 cgiargsclass &args, recptproto *collectproto,
168 ostream &logout) {
169
170 // define_internal_macros sets the following macros:
171
172 // if page is "home"
173 // _homeextra_ this is the list of available collections and collection info
174 // to be displayed on the home page
175
176
177 // if page is "about"
178 // _numdocs_ the number of documents in the collection
179
180 // _builddate_ the date last built
181
182 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
183
184 // _numbrowseoptions_ the number of browsing options
185
186
187 // if page is "help"
188 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
189
190 // _numbrowseoptions_ the number of browsing options
191
192
193 text_t &arg_p = args["p"];
194
195 if (arg_p == "home") {
196 // make sure we know about a receptionist
197 if (recpt == NULL) {
198 logout << "The page action does not contain information\n"
199 << "about any receptionists. The method set_receptionist\n"
200 << "was probably not called from the module which instantiated\n"
201 << "this page action.\n";
202 return;
203 }
204
205 unsigned long current_time = time(NULL);
206 text_t homeextra;
207
208 recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr ();
209 if (rprotolist == NULL) return;
210
211 recptprotolistclass::iterator rprotolist_here = rprotolist->begin();
212 recptprotolistclass::iterator rprotolist_end = rprotolist->end();
213 while (rprotolist_here != rprotolist_end) {
214 if ((*rprotolist_here).p != NULL) {
215 text_tarray collist;
216 comerror_t err;
217 (*rprotolist_here).p->get_collection_list (collist, err, logout);
218 if (err == noError) {
219 text_tarray::iterator collist_here = collist.begin();
220 text_tarray::iterator collist_end = collist.end();
221
222 homeextra += "<dl>\n";
223
224 FilterResponse_t response;
225 text_tarray metadata;
226 metadata.push_back ("collectionname");
227
228 while (collist_here != collist_end) {
229 text_t collectionname = *collist_here;
230 if (get_info ("collection", *collist_here, metadata, false, (*rprotolist_here).p, response, logout))
231 collectionname = response.docInfo[0].metadata[0].values[0];
232
233 ColInfoResponse_t cinfo;
234 (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout);
235 if (err == noError) {
236 text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
237 if (!cinfo.receptionist.empty())
238 link = "<a href=\"" + cinfo.receptionist + "?a=p&p=about&c=" + *collist_here + "\">";
239
240 homeextra += "<dt>" + link + collectionname + "</a></dt>\n";
241 homeextra += "<dd>";
242 if (cinfo.numDocs != 0) homeextra += text_t(cinfo.numDocs) + "_documents_";
243 if (cinfo.numWords != 0) homeextra += text_t(cinfo.numWords) + "_words_";
244 unsigned long last_update = (current_time - cinfo.buildDate) / 86400;
245 homeextra += "_lastupdate_ " + text_t(last_update) + " _ago_</dd>\n";
246 }
247 collist_here ++;
248 }
249 homeextra += "</dl>\n";
250 disp.setmacro ("homeextra", "home", homeextra);
251 }
252 }
253 rprotolist_here ++;
254 }
255 } else if (arg_p == "about") {
256 disp.setmacro ("numdocs", "about", collectinfo.numDocs);
257 unsigned long current_time = time(NULL);
258 unsigned long builddate = (current_time - collectinfo.buildDate) / 86400;
259 disp.setmacro ("builddate", "about", builddate);
260 }
261
262 if (arg_p == "about" || arg_p == "help") {
263
264 // _textbrowseoptions_ and _numbrowseoptions_
265
266 FilterResponse_t response;
267 text_tarray metadata;
268 metadata.push_back ("Title");
269 bool getParents = false;
270 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
271
272 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
273
274 ResultDocInfo_tarray::const_iterator here = response.docInfo.begin();
275 ResultDocInfo_tarray::const_iterator end = response.docInfo.end();
276
277 // we're assuming that we've always got a search button
278 text_t shorttext = "<ul><li>_textSearchshort_\n";
279 text_t longtext = "_textSearchlong_";
280
281 while (here != end) {
282 text_t title = (*here).metadata[0].values[0];
283
284 text_tset::const_iterator it = classify_meta.find (title);
285 if (it == classify_meta.end()) title = "Unknown";
286
287 shorttext += "<li>_text" + title + "short_\n";
288 longtext += "_text" + title + "long_";
289 here ++;
290 }
291 shorttext += "</ul>\n";
292 disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
293 }
294}
295
296bool pageaction::do_action (cgiargsclass &args, const ColInfoResponse_t &/*collectinfo*/,
297 recptproto * /*collectproto*/, displayclass &disp,
298 outconvertclass &outconvert, ostream &textout,
299 ostream &/*logout*/) {
300
301 text_t &arg_p = args["p"];
302
303 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
304 << ("_" + arg_p + ":content_\n")
305 << ("_" + arg_p + ":footer_\n");
306
307 return true;
308}
Note: See TracBrowser for help on using the repository browser.