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 146 1999-02-04 10:00:57Z rjmcnab $
|
---|
9 | *
|
---|
10 | *********************************************************************/
|
---|
11 |
|
---|
12 | /*
|
---|
13 | $Log$
|
---|
14 | Revision 1.2 1999/02/04 10:00:53 rjmcnab
|
---|
15 |
|
---|
16 | Developed the idea of an "action" and having them define the cgi arguments
|
---|
17 | which they need and how those cgi arguments function.
|
---|
18 |
|
---|
19 | Revision 1.1 1999/01/08 08:40:52 rjmcnab
|
---|
20 |
|
---|
21 | Moved from lib directory.
|
---|
22 |
|
---|
23 | Revision 1.1 1999/01/08 03:57:44 rjmcnab
|
---|
24 |
|
---|
25 | Initial revision
|
---|
26 |
|
---|
27 | */
|
---|
28 |
|
---|
29 |
|
---|
30 | #include "action.h"
|
---|
31 | #include <assert.h>
|
---|
32 |
|
---|
33 |
|
---|
34 | action::action () {
|
---|
35 | }
|
---|
36 |
|
---|
37 | action::~action () {
|
---|
38 | }
|
---|
39 |
|
---|
40 | // returns the "a" argument value that will specify this action
|
---|
41 | // this name should be short but does not have to be one character
|
---|
42 | // long
|
---|
43 | text_t action::get_action_name () {
|
---|
44 | return "nzdl";
|
---|
45 | }
|
---|
46 |
|
---|
47 | // get_cgihead_info determines the cgi header information for
|
---|
48 | // a set of cgi arguments. If response contains location then
|
---|
49 | // response_data contains the redirect address. If reponse
|
---|
50 | // contains content then reponse_data contains the content-type.
|
---|
51 | // Note that images can now be produced by the receptionist.
|
---|
52 | void action::get_cgihead_info (cgiargsclass &args, response_t &response,
|
---|
53 | text_t &response_data, ostream &logout) {
|
---|
54 | response = location;
|
---|
55 | response_data = "http://www.nzdl.org";
|
---|
56 | }
|
---|
57 |
|
---|
58 | // returns false if there was an error which prevented the action
|
---|
59 | // from outputing anything.
|
---|
60 | bool action::do_action (cgiargsclass &args, outconvertclass &outconvert,
|
---|
61 | ostream &textout, ostream &logout) {
|
---|
62 | return true;
|
---|
63 | }
|
---|
64 |
|
---|
65 | // configure should be called once for each configuration line
|
---|
66 | void action::configure (const text_tarray &cfgline) {
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | // theaction becomes the property of this class after addaction
|
---|
72 | // therefore theaction should always be created using new but
|
---|
73 | // not deleted after the call to addaction.
|
---|
74 | void actionmapclass::addaction (action *theaction) {
|
---|
75 | // can't add a null action
|
---|
76 | assert (theaction != NULL);
|
---|
77 | if (theaction == NULL) return;
|
---|
78 |
|
---|
79 | // can't add an action with no name
|
---|
80 | assert (!(theaction->get_action_name()).empty());
|
---|
81 | if ((theaction->get_action_name()).empty()) return;
|
---|
82 |
|
---|
83 | actionptr aptr;
|
---|
84 | aptr.a = theaction;
|
---|
85 | actionptrs[theaction->get_action_name()] = aptr;
|
---|
86 | }
|
---|
87 |
|
---|
88 | // getaction will return NULL if the action could not be found
|
---|
89 | action *actionmapclass::getaction (const text_t &key) {
|
---|
90 | iterator here = actionptrs.find (key);
|
---|
91 | if (here == actionptrs.end()) return NULL;
|
---|
92 |
|
---|
93 | return (*here).second.a;
|
---|
94 | }
|
---|