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

Last change on this file since 155 was 155, checked in by rjmcnab, 25 years ago

Got the receptionist producing something using the statusaction.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.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 155 1999-02-08 01:28:04Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.4 1999/02/08 01:27:59 rjmcnab
15
16 Got the receptionist producing something using the statusaction.
17
18 Revision 1.3 1999/02/05 10:42:41 rjmcnab
19
20 Continued working on receptionist
21
22 Revision 1.2 1999/02/04 10:00:53 rjmcnab
23
24 Developed the idea of an "action" and having them define the cgi arguments
25 which they need and how those cgi arguments function.
26
27 Revision 1.1 1999/01/08 08:40:52 rjmcnab
28
29 Moved from lib directory.
30
31 Revision 1.1 1999/01/08 03:57:44 rjmcnab
32
33 Initial revision
34
35 */
36
37
38#include "action.h"
39#include <assert.h>
40
41
42// define all the macros which are related to pages generated
43// by this action
44void action::define_internal_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
45 ostream &/*logout*/) {
46}
47
48action::action () {
49}
50
51action::~action () {
52}
53
54// returns the "a" argument value that will specify this action
55// this name should be short but does not have to be one character
56// long
57text_t action::get_action_name () {
58 return "nzdl";
59}
60
61// check_cgiargs should be called before get_cgihead_info,
62// define_external_macros, and do_action. If an error is found
63// a message will be written to logout, if the error is severe
64// then the function will return false and no page content
65// should be produced based on the arguments.
66bool action::check_cgiargs (cgiargsclass &args, ostream &logout) {
67 return true;
68}
69
70// get_cgihead_info determines the cgi header information for
71// a set of cgi arguments. If response contains location then
72// response_data contains the redirect address. If reponse
73// contains content then reponse_data contains the content-type.
74// Note that images can now be produced by the receptionist.
75void action::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
76 text_t &response_data, ostream &/*logout*/) {
77 response = location;
78 response_data = "http://www.nzdl.org";
79}
80
81// define all the macros which might be used by other actions
82// to produce pages. These macros should be well documented.
83void action::define_external_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
84 ostream &/*logout*/) {
85}
86
87// returns false if there was an error which prevented the action
88// from outputing anything.
89bool action::do_action (cgiargsclass &/*args*/, outconvertclass &/*outconvert*/,
90 ostream &/*textout*/, ostream &/*logout*/) {
91 return true;
92}
93
94// configure should be called once for each configuration line
95// the default version configures the default for any arguments
96// which this action uses
97void action::configure (const text_t &key, const text_tarray &cfgline) {
98 cgiarginfo *info = NULL;
99 if ((key == "argdefault") && (cfgline.size() == 2) &&
100 ((info = argsinfo.getarginfo(cfgline[0])) != NULL)) {
101 if (info->defaultstatus <= cgiarginfo::config) {
102 info->defaultstatus = cgiarginfo::config;
103 info->argdefault = cfgline[1];
104 }
105 }
106}
107
108
109
110actionmapclass::actionmapclass () {
111}
112
113// theaction becomes the property of this class after addaction
114// therefore theaction should always be created using new but
115// not deleted after the call to addaction.
116void actionmapclass::addaction (action *theaction) {
117 // can't add a null action
118 assert (theaction != NULL);
119 if (theaction == NULL) return;
120
121 // can't add an action with no name
122 assert (!(theaction->get_action_name()).empty());
123 if ((theaction->get_action_name()).empty()) return;
124
125 actionptr aptr;
126 aptr.a = theaction;
127 actionptrs[theaction->get_action_name()] = aptr;
128 aptr.a = NULL; // control has passed on
129}
130
131// getaction will return NULL if the action could not be found
132action *actionmapclass::getaction (const text_t &key) {
133 iterator here = actionptrs.find (key);
134 if (here == actionptrs.end()) return NULL;
135
136 return (*here).second.a;
137}
138
Note: See TracBrowser for help on using the repository browser.