#include "oaidispatcher.h"
oaidispatcher::oaidispatcher()
{ this->configuration = NULL;
}
oaidispatcher::~oaidispatcher()
{
oaiactionmap::iterator here = this->actions.begin();
oaiactionmap::iterator end = this->actions.end();
while (here != end) {
delete here->second;
++here;
}
}
void oaidispatcher::addAction(oaiaction *thisAction) {
thisAction->setConfiguration(this->configuration);
this->actions[thisAction->getName()] = thisAction;
}
void oaidispatcher::doAction(ostream &output, recptproto *protocol, oaiargs &args) {
text_t verb = args["Verb"];
if(verb == "") verb = args["verb"];
oaiaction *action = actions[verb];
if (action != NULL) {
action->getResponse(output, protocol, args);
}
else {
// If the verb isn't correct, send an error.
action = actions["Identify"];
text_t responseDate, requestURL;
int version = this->configuration->getOAIVersion();
action->getResponseDate(responseDate);
oaiargs emptySet;
action->getRequestURL(emptySet, requestURL);
// Bad verb is signified by a status 400 response for OAI 1.1
if (version <= 110) {
output << "Status: 400\n";
}
else {
output << "Status: 200\n";
}
output << "Content-type: text/xml" << endl << endl;
output << "\n";
if(version <= 110){
// output OAI v1.1 action header tag - nil, as there is no valid heeader for the action
/*
output << "<" << action->name;
output << "\n xmlns=\"http://www.openarchives.com/OAI/1.1/OAI_" << action->name << "\" ";
output << "\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
output << "\n xsi:schemaLocation=\"http://www.openarchives.org/OAI/1.1/OAI_" << action->name;
output << "\n http://www.openarchives.org/OAI/1.1/OAI_" << action->name << ".xsd\">\n";
*/
}
else {
// output OAI v2.0 action header tag
output << "