source: trunk/greenorg/src/recpt/action.cpp@ 9483

Last change on this file since 9483 was 5503, checked in by sjboddie, 21 years ago

* empty log message *

  • Property svn:mime-type set to application/octet-stream
File size: 5.1 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 *********************************************************************/
25
26#include "action.h"
27#include <assert.h>
28
29
30// define all the macros which are related to pages generated
31// by this action
32void action::define_internal_macros (displayclass &disp, cgiargsclass &args,
33 ostream &logout) {
34}
35
36action::action () {
37}
38
39action::~action () {
40}
41
42// configure should be called once for each configuration line
43void action::configure (const text_t &key, const text_tarray &cfgline) {
44 if (key == "gsdlhome") {
45 gsdlhome = cfgline[0];
46 if (gdbmhome.empty()) gdbmhome = cfgline[0];
47 }
48 if (key == "gdbmhome") {gdbmhome = cfgline[0];}
49}
50
51// init should be called after all the configuration is done but
52// before any other methods are called
53bool action::init (ostream &logout) {
54 return true;
55}
56
57// returns the "a" argument value that will specify this action
58// this name should be short but does not have to be one character
59// long
60text_t action::get_action_name () {
61 return "nzdl";
62}
63
64// check_cgiargs should be called before get_cgihead_info,
65// define_external_macros, and do_action. If an error is found
66// a message will be written to logout, if the error is severe
67// then the function will return false and no page content
68// should be produced based on the arguments.
69bool action::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
70 ostream &logout) {
71 return true;
72}
73
74// check_external_cgiargs should be called after check_cgiargs
75// for all actions. It should only be used to override some other
76// normal behaviour, for example, producing a login page when
77// the requested page needs authentication.
78bool action::check_external_cgiargs (cgiargsinfoclass &argsinfo,
79 cgiargsclass &args,
80 outconvertclass &outconvert,
81 const text_t &saveconf,
82 ostream &logout) {
83 return true;
84}
85
86// get_cgihead_info determines the cgi header information for
87// a set of cgi arguments. If response contains location then
88// response_data contains the redirect address. If reponse
89// contains content then reponse_data contains the content-type.
90// Note that images can now be produced by the receptionist.
91void action::get_cgihead_info (cgiargsclass &args, response_t &response,
92 text_t &response_data, ostream &logout) {
93 response = location;
94 response_data = "http://www.nzdl.org";
95}
96
97// uses_display should return true if the receptionist should return
98// true if the display class is needed to output the page content
99// The default is to return true.
100bool action::uses_display (cgiargsclass &args) {
101 return true;
102}
103
104
105// define all the macros which might be used by other actions
106// to produce pages. These macros should be well documented.
107void action::define_external_macros (displayclass &disp, cgiargsclass &args,
108 ostream &logout) {
109}
110
111// returns false if there was an error which prevented the action
112// from outputing anything.
113bool action::do_action (cgiargsclass &args, displayclass &disp,
114 outconvertclass &outconvert, ostream &textout,
115 ostream &logout) {
116 return true;
117}
118
119
120bool operator==(const actionptr &x, const actionptr &y) {
121 return (x.a == y.a);
122}
123
124bool operator<(const actionptr &x, const actionptr &y) {
125 return (x.a < y.a);
126}
127
128
129// theaction remains the property of the calling code but
130// should not be deleted until it is removed from this list.
131void actionmapclass::addaction (action *theaction) {
132 // can't add a null action
133 assert (theaction != NULL);
134 if (theaction == NULL) return;
135
136 // can't add an action with no name
137 assert (!(theaction->get_action_name()).empty());
138 if ((theaction->get_action_name()).empty()) return;
139
140 actionptr aptr;
141 aptr.a = theaction;
142 actionptrs[theaction->get_action_name()] = aptr;
143}
144
145// getaction will return NULL if the action could not be found
146action *actionmapclass::getaction (const text_t &key) {
147 // can't find an action with no name
148 assert (!key.empty());
149 if (key.empty()) return NULL;
150
151 iterator here = actionptrs.find (key);
152 if (here == actionptrs.end()) return NULL;
153
154 return (*here).second.a;
155}
Note: See TracBrowser for help on using the repository browser.