source: trunk/gsdl/src/oaiservr/oaidispatcher.cpp@ 9608

Last change on this file since 9608 was 9608, checked in by kjdon, 19 years ago

added in x++ -> ++x changes submitted by Emanuel Dejanu

  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1#include "oaidispatcher.h"
2
3oaidispatcher::oaidispatcher()
4{ this->configuration = NULL;
5}
6
7oaidispatcher::~oaidispatcher()
8{
9 oaiactionmap::iterator here = this->actions.begin();
10 oaiactionmap::iterator end = this->actions.end();
11
12 while (here != end) {
13 delete here->second;
14 ++here;
15 }
16}
17
18void oaidispatcher::addAction(oaiaction *thisAction) {
19 thisAction->setConfiguration(this->configuration);
20 this->actions[thisAction->getName()] = thisAction;
21}
22
23void oaidispatcher::doAction(ostream &output, recptproto *protocol, oaiargs &args) {
24
25 text_t verb = args["Verb"];
26 if(verb == "") verb = args["verb"];
27
28 oaiaction *action = actions[verb];
29
30 if (action != NULL) {
31 action->getResponse(output, protocol, args);
32 }
33 else {
34 // If the verb isn't correct, send an error.
35 action = actions["Identify"];
36 text_t responseDate, requestURL;
37 int version = this->configuration->getOAIVersion();
38 action->getResponseDate(responseDate);
39 oaiargs emptySet;
40 action->getRequestURL(emptySet, requestURL);
41
42 // Bad verb is signified by a status 400 response for OAI 1.1
43 if (version <= 110) {
44 output << "Status: 400\n";
45 }
46 else {
47 output << "Status: 200\n";
48 }
49 output << "Content-type: text/xml" << endl << endl;
50 output << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
51
52 if(version <= 110){
53 // output OAI v1.1 action header tag - nil, as there is no valid heeader for the action
54 /*
55 output << "<" << action->name;
56 output << "\n xmlns=\"http://www.openarchives.com/OAI/1.1/OAI_" << action->name << "\" ";
57 output << "\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
58 output << "\n xsi:schemaLocation=\"http://www.openarchives.org/OAI/1.1/OAI_" << action->name;
59 output << "\n http://www.openarchives.org/OAI/1.1/OAI_" << action->name << ".xsd\">\n";
60 */
61 }
62 else {
63 // output OAI v2.0 action header tag
64 output << "<OAI-PMH xmlns=\"http://www.openarchives.com/OAI/2.0\"\n"
65 << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
66 << " xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/\n"
67 << " http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">\n"
68 << " <responseDate>" << responseDate << "</responseDate>\n"
69 << requestURL
70 << " <error code=\"badVerb\">Illegal OAI verb</error>\n"
71 << "</OAI-PMH>\n";
72 }
73
74 /*
75 cout << "<title>Bad OAI request</title>" << endl;
76 cout << "<h1>Bad OAI request</h1>" << endl;
77 */
78 }
79 output.flush();
80}
Note: See TracBrowser for help on using the repository browser.