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

Last change on this file since 1877 was 1877, checked in by sjboddie, 23 years ago

fixed a couple of minor bugs that were introduced with the corba stuff

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.4 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 *********************************************************************/
25
26#include "OIDtools.h"
27#include "pageaction.h"
28#include "receptionist.h"
29#include <time.h>
30
31pageaction::pageaction () {
32
33 status_disabled = true;
34 collector_disabled = true;
35 recpt = NULL;
36
37 // this action uses cgi variables "a", "p", and "hp"
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 = "p";
44 arg_ainfo.savedarginfo = cgiarginfo::must;
45 argsinfo.addarginfo (NULL, arg_ainfo);
46
47 arg_ainfo.shortname = "p";
48 arg_ainfo.longname = "page";
49 arg_ainfo.multiplechar = true;
50 arg_ainfo.defaultstatus = cgiarginfo::weak;
51 arg_ainfo.argdefault = "home";
52 arg_ainfo.savedarginfo = cgiarginfo::must;
53 argsinfo.addarginfo (NULL, arg_ainfo);
54
55 arg_ainfo.shortname = "hp";
56 arg_ainfo.longname = "html page";
57 arg_ainfo.multiplechar = true;
58 arg_ainfo.defaultstatus = cgiarginfo::weak;
59 arg_ainfo.argdefault = "";
60 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
61 argsinfo.addarginfo (NULL, arg_ainfo);
62}
63
64pageaction::~pageaction () {
65}
66
67bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
68 ostream &/*logout*/) {
69 // don't want to check anything yet.
70 return true;
71}
72
73void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
74 response_t &response,text_t &response_data,
75 ostream &/*logout*/) {
76 response = content;
77 response_data = "text/html";
78}
79
80void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
81 ostream &logout) {
82 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
83 bool found_valid_col = false;
84
85 recptprotolistclass::iterator rprotolist_here = protos->begin();
86 recptprotolistclass::iterator rprotolist_end = protos->end();
87 while (rprotolist_here != rprotolist_end) {
88 if ((*rprotolist_here).p != NULL) {
89
90 text_tarray collist;
91 comerror_t err;
92 (*rprotolist_here).p->get_collection_list (collist, err, logout);
93 if (err == noError) {
94 text_tarray::iterator collist_here = collist.begin();
95 text_tarray::iterator collist_end = collist.end();
96
97 int count = 0;
98 bool first = true;
99 while (collist_here != collist_end) {
100 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
101
102 if (cinfo != NULL) {
103 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
104
105 found_valid_col = true;
106 FilterResponse_t response;
107 text_tset metadata;
108 metadata.insert ("collectionname");
109 metadata.insert ("iconcollection");
110 metadata.insert ("iconcollectionsmall");
111 text_t collectionname = *collist_here;
112 text_t alt = collectionname;
113
114 if (get_info ("collection", *collist_here, metadata, false,
115 (*rprotolist_here).p, response, logout)) {
116 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
117 alt = response.docInfo[0].metadata["collectionname"].values[0];
118
119 text_t iconurl;
120 iconurl.clear();
121
122 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty()) {
123 iconurl = response.docInfo[0].metadata["iconcollectionsmall"].values[0];
124 } else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty()) {
125 iconurl = response.docInfo[0].metadata["iconcollection"].values[0];
126 }
127
128 if (!iconurl.empty())
129 {
130 // check to see URL is local to colserver
131 text_t::iterator iconurl_head = iconurl.begin();
132 text_t iconhead = substr(iconurl_head,iconurl_head+16);
133 if (iconhead=="_httpcollection_")
134 {
135 // local and using _httpcollection_
136 text_t icontail = substr(iconurl_head+16,iconurl.end());
137 iconurl = "http://" + cinfo->httpdomain
138 + cinfo->httpprefix + "/collect/"
139 + *collist_here + "/" + icontail;
140 }
141 else if (iconurl[0]=='/')
142 {
143 // local but with full path
144 iconurl = "http://" + cinfo->httpdomain + iconurl;
145 }
146
147 collectionname
148 = "<img width=150 border=1 src=\"" + iconurl + "\" alt=\"" + alt + "\">";
149 }
150 else
151 {
152 collectionname = alt;
153 }
154
155 }
156 if ((count%3 == 0) && (!first))
157 homeextra += "</tr><tr valign=top>\n";
158
159 text_t optsite = "";
160 text_t site_name = (*rprotolist_here).p->get_site_name ();
161 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
162
163 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + "\">";
164
165 if (!cinfo->receptionist.empty())
166 link = "<a href=\"" + cinfo->receptionist + "\">";
167
168 homeextra += "<td>" + link + collectionname + "</a></td>\n";
169
170 count ++;
171 first = false;
172 }
173 }
174 collist_here ++;
175 }
176
177 for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
178 }
179 }
180 homeextra += "</td></tr>\n<tr>\n";
181 rprotolist_here ++;
182 }
183
184 if (!found_valid_col) {
185 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
186 }
187 homeextra += "</tr></table></center>\n";
188 disp.setmacro ("homeextra", "home", homeextra);
189}
190
191void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
192 recptprotolistclass *protos, ostream &logout) {
193
194 // define_internal_macros sets the following macros:
195
196 // _numdocs_ the number of documents in the collection
197
198 // _builddate_ the date last built
199
200
201 // if page is "home"
202 // _homeextra_ this is the list of available collections and collection info
203 // to be displayed on the home page
204
205
206 // if page is "preferences"
207 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
208
209 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
210
211 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
212
213 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
214
215 // _encodingoption_ encodings to select from
216
217 // if page is "about"
218 // _textsubcollections_ the text on which subcollections make up the collection (if
219 // cross-collection searching is being used
220
221 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
222
223 // _numbrowseoptions_ the number of browsing options
224
225
226 // if page is "help"
227 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
228
229 // _numbrowseoptions_ the number of browsing options
230
231 // _topicreadingdocs_ this section of the help text differs depending on what type of
232 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
233 // _texthelpreadingdocs_
234
235 // _textgocollector_ set to "" if collector is disabled in main.cfg
236 // _textgoadmin_ set to "" if status is disabled in main.cfg
237
238
239 if (recpt == NULL) {
240 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
241 << " information about any receptionists. The method set_receptionist was\n"
242 << " probably not called from the module which instantiated this action.\n";
243 return;
244 }
245
246 text_t &arg_p = args["p"];
247 text_t &arg_c = args["c"];
248 ColInfoResponse_t *cinfo = NULL;
249
250 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
251 if (collectproto != NULL) {
252 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
253
254 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
255 unsigned long current_time = time(NULL);
256 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
257 disp.setmacro ("builddate", "Global", builddate);
258 }
259
260 if (arg_p == "home") {
261 set_homeextra_macro (disp, protos, logout);
262 if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
263 if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
264 }
265
266 else if (arg_p == "preferences") {
267
268 // _collectionoption_
269
270 if (args["ccs"] == "1" && collectproto != NULL && (cinfo->ccsCols.size() > 1)) {
271 text_t collectionoption = "_textcollectionoption_";
272 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
273 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
274 int count = 0;
275 while (col_here != col_end) {
276 text_t colname;
277 if (*col_here == arg_c) {
278 colname = cinfo->collectionmeta["collectionname"];
279 } else {
280 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
281 if (this_cinfo == NULL) {col_here ++; continue;}
282 colname = this_cinfo->collectionmeta["collectionname"];
283 }
284
285 count ++;
286 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
287 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
288 colname + "<br>\n";
289 col_here ++;
290 }
291
292 if (count > 1)
293 disp.setmacro ("collectionoption", "preferences", collectionoption);
294 }
295
296 // _htmloptions_
297
298 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
299 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
300 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
301
302
303 // _PreferenceDocsFromWeb_
304
305 it = cinfo->format.find ("PreferenceDocsFromWeb");
306 if ((it == cinfo->format.end()) || ((*it).second == "true"))
307 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
308 }
309
310 // _languageoption_
311 // Create the "interface language" selection box for the preferences page.
312 // You can use something like "format PreferenceLanguages en|fr|zn" from within
313 // a collect.cfg file to use only a subset of the available languages for
314 // any given collection. This facility is kind of ugly though and should be
315 // replaced by something better when the configuration files are tidied up (as
316 // should all the other "format Preference..." options).
317
318 text_t &arg_l = args["l"];
319 const recptconf &configinfo = recpt->get_configinfo();
320 // put languages in another map to sort them by longname
321 text_tmap languages;
322 languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
323 languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
324 while (thislang != endlang) {
325 languages[(*thislang).second.longname] = (*thislang).first;
326 thislang++;
327 }
328 text_tmap::iterator tlang = languages.begin();
329 text_tmap::iterator elang = languages.end();
330
331 text_t languageoption;
332 it = cinfo->format.find ("PreferenceLanguages");
333 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
334 text_tset pref_langs;
335 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
336 if (pref_langs.size() > 1) {
337 while (tlang != elang) {
338 if (pref_langs.find((*tlang).second) != pref_langs.end()) {
339 languageoption += "<option value=\"" + (*tlang).second + "\"";
340 if ((*tlang).second == arg_l) languageoption += " selected";
341 languageoption += ">" + (*tlang).first + "\n";
342 }
343 tlang ++;
344 }
345 }
346
347 } else {
348 while (tlang != elang) {
349 languageoption += "<option value=\"" + (*tlang).second + "\"";
350 if ((*tlang).second == arg_l) languageoption += " selected";
351 languageoption += ">" + (*tlang).first + "\n";
352 tlang ++;
353 }
354 }
355 if (!languageoption.empty()) {
356 languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
357 languageoption += "</select>\n";
358 disp.setmacro ("languageoption", "preferences", languageoption);
359 }
360
361 // _encodingoption_
362 // create the "encoding" selection box for the preferences page
363 text_t &arg_w = args["w"];
364 text_t encodingoption;
365 text_tmap::const_iterator thisenc = configinfo.encodings.begin();
366 text_tmap::const_iterator endenc = configinfo.encodings.end();
367 while (thisenc != endenc) {
368 encodingoption += "<option value=\"" + (*thisenc).second + "\"";
369 if ((*thisenc).second == arg_w) encodingoption += " selected";
370 encodingoption += ">" + (*thisenc).first + "\n";
371 thisenc ++;
372 }
373
374 if (!encodingoption.empty()) {
375 encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
376 encodingoption += "</select>\n";
377 disp.setmacro ("encodingoption", "preferences", encodingoption);
378 }
379
380 } else if (arg_p == "about" || arg_p == "help") {
381 if (collectproto == NULL) return;
382
383 // _textbrowseoptions_ and _numbrowseoptions_
384
385 FilterResponse_t response;
386 text_tset metadata;
387 metadata.insert ("Title");
388 bool getParents = false;
389 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
390
391 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
392
393 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
394 ResultDocInfo_tarray::iterator end = response.docInfo.end();
395
396 // we're assuming that we've always got a search button
397 text_t shorttext = "<ul><li>_textSearchshort_\n";
398 text_t longtext = "_textSearchlong_";
399
400 while (here != end) {
401 text_t title = (*here).metadata["Title"].values[0];
402
403 text_t stext, ltext;
404 disp.expandstring ("help", "_text" + title + "short_", stext);
405 if (stext == ("_text" + title + "short_")) {
406 shorttext += "<li>_help:textdefaultshorttext_";
407 longtext += "_help:textdefaultlongtext_";
408 } else {
409 shorttext += "<li>_help:text" + title + "short_";
410 longtext += "_help:text" + title + "long_";
411 }
412
413 here ++;
414 }
415 shorttext += "</ul>\n";
416 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
417 else disp.setmacro ("textbrowseoptions", "help", longtext);
418
419 if (arg_p == "help") {
420
421 // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
422
423 // if HTML collection there's no how to read document text
424 text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
425 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
426 disp.setmacro ("topicreadingdocs", "help", "");
427 disp.setmacro ("texthelpreadingdocs", "help", "");
428 }
429 it = cinfo->format.find ("HelpBibDocs");
430 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
431 disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
432 disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
433 }
434 it = cinfo->format.find ("HelpBookDocs");
435 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
436 disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
437 disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
438 }
439
440 }
441 if (arg_p == "about") {
442
443 // _textsubcollections_
444 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
445 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
446 text_tarray::const_iterator here = cinfo->ccsCols.begin();
447 text_tarray::const_iterator end = cinfo->ccsCols.end();
448 bool first = true;
449 int count = 0;
450 while (here != end) {
451 if (*here == arg_c) {
452 if (!first) textsubcollections += "<br>";
453 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
454 } else {
455 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
456 if (this_cinfo == NULL) {here ++; continue;}
457 if (!first) textsubcollections += "<br>";
458 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
459 }
460 count ++;
461 first = false;
462 here ++;
463 }
464 textsubcollections += "_textsubcols2_";
465 if (count > 1)
466 disp.setmacro ("textsubcollections", "about", textsubcollections);
467 }
468 }
469 }
470}
471
472bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
473 browsermapclass * /*browsers*/, displayclass &disp,
474 outconvertclass &outconvert, ostream &textout,
475 ostream &/*logout*/) {
476
477 text_t &arg_p = args["p"];
478
479 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
480 << ("_" + arg_p + ":content_\n")
481 << ("_" + arg_p + ":footer_\n");
482
483 return true;
484}
485
486void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
487 if ((key == "status") && (cfgline.size() == 1) &&
488 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
489 status_disabled = false;
490 } else if ((key == "collector") && (cfgline.size() == 1) &&
491 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
492 collector_disabled = false;
493 } else {
494 // call the parent class to deal with the things which
495 // are not dealt with here
496 action::configure (key, cfgline);
497 }
498}
Note: See TracBrowser for help on using the repository browser.