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

Last change on this file since 1266 was 962, checked in by sjboddie, 24 years ago

actions are now configured with gsdlhome

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