source: trunk/gsdl/src/recpt/action.cpp@ 533

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

added GPL notice

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/**********************************************************************
2 *
3 * action.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: action.cpp 533 1999-09-07 04:57:01Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.16 1999/09/07 04:56:51 sjboddie
31 added GPL notice
32
33 Revision 1.15 1999/09/03 09:51:47 rjmcnab
34 removed the argdefault configuration option (it should now be
35 done with cgiarg)
36
37 Revision 1.14 1999/09/02 00:22:42 rjmcnab
38 Changes to get it compiling on AIX
39
40 Revision 1.13 1999/07/30 02:24:43 sjboddie
41 added collectinfo argument to some functions
42
43 Revision 1.12 1999/07/10 22:15:30 rjmcnab
44 Added function check_external_cgiargs so that actions that
45 are not being called can override cgi arguments.
46
47 Revision 1.11 1999/06/08 04:29:41 sjboddie
48 added argsinfo to the call to check_cgiargs to make it easy to set
49 args to their default if they're found to be screwed up
50
51 Revision 1.10 1999/03/25 03:06:44 sjboddie
52
53 altered receptionist slightly so it now passes *collectproto to
54 define_internal_macros and define_external_macros - need it
55 for browseaction
56
57 Revision 1.9 1999/02/28 23:16:00 rjmcnab
58
59 Fixed a compiler warning.
60
61 Revision 1.8 1999/02/28 20:00:11 rjmcnab
62
63
64 Fixed a few things.
65
66 Revision 1.7 1999/02/25 21:58:58 rjmcnab
67
68 Merged sources.
69
70 Revision 1.6 1999/02/21 22:33:52 rjmcnab
71
72 Lots of stuff :-)
73
74 Revision 1.5 1999/02/11 01:24:04 rjmcnab
75
76 Fixed a few compiler warnings.
77
78 Revision 1.4 1999/02/08 01:27:59 rjmcnab
79
80 Got the receptionist producing something using the statusaction.
81
82 Revision 1.3 1999/02/05 10:42:41 rjmcnab
83
84 Continued working on receptionist
85
86 Revision 1.2 1999/02/04 10:00:53 rjmcnab
87
88 Developed the idea of an "action" and having them define the cgi arguments
89 which they need and how those cgi arguments function.
90
91 Revision 1.1 1999/01/08 08:40:52 rjmcnab
92
93 Moved from lib directory.
94
95 Revision 1.1 1999/01/08 03:57:44 rjmcnab
96
97 Initial revision
98
99 */
100
101
102#include "action.h"
103#include <assert.h>
104
105
106// define all the macros which are related to pages generated
107// by this action
108void action::define_internal_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &/*disp*/,
109 cgiargsclass &/*args*/, recptproto */*collectproto*/,
110 ostream &/*logout*/) {
111}
112
113action::action () {
114}
115
116action::~action () {
117}
118
119// configure should be called once for each configuration line
120// the default version does nothing
121void action::configure (const text_t &/*key*/, const text_tarray &/*cfgline*/) {
122}
123
124// init should be called after all the configuration is done but
125// before any other methods are called
126bool action::init (ostream &/*logout*/) {
127 return true;
128}
129
130// returns the "a" argument value that will specify this action
131// this name should be short but does not have to be one character
132// long
133text_t action::get_action_name () {
134 return "nzdl";
135}
136
137// check_cgiargs should be called before get_cgihead_info,
138// define_external_macros, and do_action. If an error is found
139// a message will be written to logout, if the error is severe
140// then the function will return false and no page content
141// should be produced based on the arguments.
142bool action::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
143 ostream &/*logout*/) {
144 return true;
145}
146
147// check_external_cgiargs should be called after check_cgiargs
148// for all actions. It should only be used to override some other
149// normal behaviour, for example, producing a login page when
150// the requested page needs authentication.
151bool action::check_external_cgiargs (cgiargsinfoclass &/*argsinfo*/,
152 cgiargsclass &/*args*/,
153 outconvertclass &/*outconvert*/,
154 const text_t &/*saveconf*/,
155 ostream &/*logout*/) {
156 return true;
157}
158
159// get_cgihead_info determines the cgi header information for
160// a set of cgi arguments. If response contains location then
161// response_data contains the redirect address. If reponse
162// contains content then reponse_data contains the content-type.
163// Note that images can now be produced by the receptionist.
164void action::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
165 text_t &response_data, ostream &/*logout*/) {
166 response = location;
167 response_data = "http://www.nzdl.org";
168}
169
170// uses_display should return true if the receptionist should return
171// true if the display class is needed to output the page content
172// The default is to return true.
173bool action::uses_display (cgiargsclass &/*args*/) {
174 return true;
175}
176
177
178// define all the macros which might be used by other actions
179// to produce pages. These macros should be well documented.
180void action::define_external_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &/*disp*/,
181 cgiargsclass &/*args*/, recptproto */*collectproto*/,
182 ostream &/*logout*/) {
183}
184
185// returns false if there was an error which prevented the action
186// from outputing anything.
187bool action::do_action (cgiargsclass &/*args*/, const ColInfoResponse_t &/*collectinfo*/,
188 recptproto */*collectproto*/, displayclass &/*disp*/,
189 outconvertclass &/*outconvert*/, ostream &/*textout*/,
190 ostream &/*logout*/) {
191 return true;
192}
193
194
195bool operator==(const actionptr &x, const actionptr &y) {
196 return (x.a == y.a);
197}
198
199bool operator<(const actionptr &x, const actionptr &y) {
200 return (x.a < y.a);
201}
202
203
204// theaction remains the property of the calling code but
205// should not be deleted until it is removed from this list.
206void actionmapclass::addaction (action *theaction) {
207 // can't add a null action
208 assert (theaction != NULL);
209 if (theaction == NULL) return;
210
211 // can't add an action with no name
212 assert (!(theaction->get_action_name()).empty());
213 if ((theaction->get_action_name()).empty()) return;
214
215 actionptr aptr;
216 aptr.a = theaction;
217 actionptrs[theaction->get_action_name()] = aptr;
218}
219
220// getaction will return NULL if the action could not be found
221action *actionmapclass::getaction (const text_t &key) {
222 // can't find an action with no name
223 assert (!key.empty());
224 if (key.empty()) return NULL;
225
226 iterator here = actionptrs.find (key);
227 if (here == actionptrs.end()) return NULL;
228
229 return (*here).second.a;
230}
231
Note: See TracBrowser for help on using the repository browser.