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

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

added ability to set receptionist from collect.cfg

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/**********************************************************************
2 *
3 * pageaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: pageaction.cpp 430 1999-08-03 03:29:47Z sjboddie $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.9 1999/08/03 03:29:47 sjboddie
15 added ability to set receptionist from collect.cfg
16
17 Revision 1.8 1999/07/30 02:24:44 sjboddie
18 added collectinfo argument to some functions
19
20 Revision 1.7 1999/06/24 05:12:24 sjboddie
21 lots of small changes
22
23 Revision 1.6 1999/06/10 00:39:16 sjboddie
24 navigation bar is no longer written out for every page (it should
25 be included in the _content_ macro of pages wanting to display it).
26
27 Revision 1.5 1999/06/08 04:29:35 sjboddie
28 added argsinfo to the call to check_cgiargs to make it easy to set
29 args to their default if they're found to be screwed up
30
31 Revision 1.4 1999/02/28 20:00:14 rjmcnab
32
33
34 Fixed a few things.
35
36 Revision 1.3 1999/02/25 21:58:58 rjmcnab
37
38 Merged sources.
39
40 Revision 1.2 1999/02/21 22:33:54 rjmcnab
41
42 Lots of stuff :-)
43
44 Revision 1.1 1999/02/12 02:40:17 sjboddie
45
46 Added page action
47
48 */
49
50
51#include "pageaction.h"
52#include "receptionist.h"
53#include <time.h>
54
55pageaction::pageaction () {
56
57 recpt = NULL;
58
59 // this action uses cgi variables "a" and "p"
60 cgiarginfo arg_ainfo;
61 arg_ainfo.shortname = "a";
62 arg_ainfo.longname = "action";
63 arg_ainfo.multiplechar = true;
64 arg_ainfo.defaultstatus = cgiarginfo::weak;
65 arg_ainfo.argdefault = "p";
66 arg_ainfo.savedarginfo = cgiarginfo::must;
67 argsinfo.addarginfo (NULL, arg_ainfo);
68
69 arg_ainfo.shortname = "p";
70 arg_ainfo.longname = "page";
71 arg_ainfo.multiplechar = true;
72 arg_ainfo.defaultstatus = cgiarginfo::weak;
73 arg_ainfo.argdefault = "about";
74 arg_ainfo.savedarginfo = cgiarginfo::can;
75 argsinfo.addarginfo (NULL, arg_ainfo);
76}
77
78pageaction::~pageaction () {
79}
80
81bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
82 ostream &/*logout*/) {
83 // don't want to check anything yet.
84 return true;
85}
86
87void pageaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
88 text_t &response_data, ostream &/*logout*/) {
89 response = content;
90 response_data = "text/html";
91}
92
93
94// define all the macros which might be used by other actions
95// to produce pages.
96void pageaction::define_external_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &/*disp*/,
97 cgiargsclass &/*args*/, recptproto */*collectproto*/,
98 ostream &/*logout*/) {
99}
100
101
102void pageaction::define_internal_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &disp,
103 cgiargsclass &args, recptproto */*collectproto*/,
104 ostream &logout) {
105
106 // define_internal_macros sets the following macros:
107
108 // _homeextra_ this is the list of available collections and collection info
109 // to be displayed on the home page
110
111 if (args["p"] == "home") {
112 // make sure we know about a receptionist
113 if (recpt == NULL) {
114 logout << "The page action does not contain information\n"
115 << "about any receptionists. The method set_receptionist\n"
116 << "was probably not called from the module which instantiated\n"
117 << "this page action.\n";
118 return;
119 }
120
121 unsigned long current_time = time(NULL);
122 text_t homeextra;
123
124 recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr ();
125 if (rprotolist == NULL) return;
126
127 recptprotolistclass::iterator rprotolist_here = rprotolist->begin();
128 recptprotolistclass::iterator rprotolist_end = rprotolist->end();
129 while (rprotolist_here != rprotolist_end) {
130 if ((*rprotolist_here).p != NULL) {
131 text_tarray collist;
132 comerror_t err;
133 (*rprotolist_here).p->get_collection_list (collist, err, logout);
134 if (err == noError) {
135 text_tarray::iterator collist_here = collist.begin();
136 text_tarray::iterator collist_end = collist.end();
137
138 homeextra += "<dl>\n";
139
140 while (collist_here != collist_end) {
141 ColInfoResponse_t cinfo;
142 (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout);
143 if (err == noError) {
144 text_t link = "<a href=\"_gwcgi_?a=q&c=" + *collist_here + "\">";
145 if (!cinfo.receptionist.empty())
146 link = "<a href=\"" + cinfo.receptionist + "?a=q&c=" + *collist_here + "\">";
147
148 homeextra += "<dt>" + link + *collist_here + "</a></dt>\n";
149 homeextra += "<dd>";
150 if (cinfo.numDocs != 0) homeextra += text_t(cinfo.numDocs) + "_documents_";
151 if (cinfo.numWords != 0) homeextra += text_t(cinfo.numWords) + "_words_";
152 unsigned long last_update = (current_time - cinfo.buildDate) / 86400;
153 homeextra += "_lastupdate_ " + text_t(last_update) + " _ago_</dd>\n";
154 }
155 collist_here ++;
156 }
157 homeextra += "</dl>\n";
158 disp.setmacro ("homeextra", "home", homeextra);
159 }
160 }
161 rprotolist_here ++;
162 }
163 }
164}
165
166bool pageaction::do_action (cgiargsclass &args, const ColInfoResponse_t &/*collectinfo*/,
167 recptproto */*collectproto*/, displayclass &disp,
168 outconvertclass &outconvert, ostream &textout,
169 ostream &/*logout*/) {
170
171 text_t &arg_p = args["p"];
172
173 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
174 << ("_" + arg_p + ":content_\n")
175 << ("_" + arg_p + ":footer_\n");
176
177 return true;
178}
Note: See TracBrowser for help on using the repository browser.