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

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

altered receptionist slightly so it now passes *collectproto to
define_internal_macros and define_external_macros - need it
for browseaction

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/**********************************************************************
2 *
3 * action.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: action.cpp 206 1999-03-25 03:06:45Z sjboddie $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.10 1999/03/25 03:06:44 sjboddie
15
16 altered receptionist slightly so it now passes *collectproto to
17 define_internal_macros and define_external_macros - need it
18 for browseaction
19
20 Revision 1.9 1999/02/28 23:16:00 rjmcnab
21
22 Fixed a compiler warning.
23
24 Revision 1.8 1999/02/28 20:00:11 rjmcnab
25
26
27 Fixed a few things.
28
29 Revision 1.7 1999/02/25 21:58:58 rjmcnab
30
31 Merged sources.
32
33 Revision 1.6 1999/02/21 22:33:52 rjmcnab
34
35 Lots of stuff :-)
36
37 Revision 1.5 1999/02/11 01:24:04 rjmcnab
38
39 Fixed a few compiler warnings.
40
41 Revision 1.4 1999/02/08 01:27:59 rjmcnab
42
43 Got the receptionist producing something using the statusaction.
44
45 Revision 1.3 1999/02/05 10:42:41 rjmcnab
46
47 Continued working on receptionist
48
49 Revision 1.2 1999/02/04 10:00:53 rjmcnab
50
51 Developed the idea of an "action" and having them define the cgi arguments
52 which they need and how those cgi arguments function.
53
54 Revision 1.1 1999/01/08 08:40:52 rjmcnab
55
56 Moved from lib directory.
57
58 Revision 1.1 1999/01/08 03:57:44 rjmcnab
59
60 Initial revision
61
62 */
63
64
65#include "action.h"
66#include <assert.h>
67
68
69// define all the macros which are related to pages generated
70// by this action
71void action::define_internal_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
72 recptproto */*collectproto*/, ostream &/*logout*/) {
73}
74
75action::action () {
76}
77
78action::~action () {
79}
80
81// configure should be called once for each configuration line
82// the default version configures the default for any arguments
83// which this action uses
84void action::configure (const text_t &key, const text_tarray &cfgline) {
85 cgiarginfo *info = NULL;
86 if ((key == "argdefault") && (cfgline.size() == 2) &&
87 ((info = argsinfo.getarginfo(cfgline[0])) != NULL)) {
88 if (info->defaultstatus <= cgiarginfo::config) {
89 info->defaultstatus = cgiarginfo::config;
90 info->argdefault = cfgline[1];
91 }
92 }
93}
94
95// init should be called after all the configuration is done but
96// before any other methods are called
97bool action::init (ostream &/*logout*/) {
98 return true;
99}
100
101// returns the "a" argument value that will specify this action
102// this name should be short but does not have to be one character
103// long
104text_t action::get_action_name () {
105 return "nzdl";
106}
107
108// check_cgiargs should be called before get_cgihead_info,
109// define_external_macros, and do_action. If an error is found
110// a message will be written to logout, if the error is severe
111// then the function will return false and no page content
112// should be produced based on the arguments.
113bool action::check_cgiargs (cgiargsclass &/*args*/, ostream &/*logout*/) {
114 return true;
115}
116
117// get_cgihead_info determines the cgi header information for
118// a set of cgi arguments. If response contains location then
119// response_data contains the redirect address. If reponse
120// contains content then reponse_data contains the content-type.
121// Note that images can now be produced by the receptionist.
122void action::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
123 text_t &response_data, ostream &/*logout*/) {
124 response = location;
125 response_data = "http://www.nzdl.org";
126}
127
128// uses_display should return true if the receptionist should return
129// true if the display class is needed to output the page content
130// The default is to return true.
131bool action::uses_display (cgiargsclass &/*args*/) {
132 return true;
133}
134
135
136// define all the macros which might be used by other actions
137// to produce pages. These macros should be well documented.
138void action::define_external_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
139 recptproto */*collectproto*/, ostream &/*logout*/) {
140}
141
142// returns false if there was an error which prevented the action
143// from outputing anything.
144bool action::do_action (cgiargsclass &/*args*/, recptproto */*collectproto*/,
145 displayclass &/*disp*/, outconvertclass &/*outconvert*/,
146 ostream &/*textout*/, ostream &/*logout*/) {
147 return true;
148}
149
150
151
152
153// theaction remains the property of the calling code but
154// should not be deleted until it is removed from this list.
155void actionmapclass::addaction (action *theaction) {
156 // can't add a null action
157 assert (theaction != NULL);
158 if (theaction == NULL) return;
159
160 // can't add an action with no name
161 assert (!(theaction->get_action_name()).empty());
162 if ((theaction->get_action_name()).empty()) return;
163
164 actionptr aptr;
165 aptr.a = theaction;
166 actionptrs[theaction->get_action_name()] = aptr;
167}
168
169// getaction will return NULL if the action could not be found
170action *actionmapclass::getaction (const text_t &key) {
171 // can't find an action with no name
172 assert (!key.empty());
173 if (key.empty()) return NULL;
174
175 iterator here = actionptrs.find (key);
176 if (here == actionptrs.end()) return NULL;
177
178 return (*here).second.a;
179}
180
Note: See TracBrowser for help on using the repository browser.