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

Last change on this file since 1860 was 1860, checked in by cs025, 23 years ago

Included CORBA branch for first time

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