source: branches/z3950-branch/gsdl/src/recpt/action.cpp@ 1342

Last change on this file since 1342 was 1342, checked in by johnmcp, 24 years ago

Relatively stable z39.50 implementation now, merged with the mgpp source.
(Still needs a decent interface and query language though...)

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