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