[22739] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * oaidispatcher.cpp --
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2004-2010 The New Zealand Digital Library Project
|
---|
| 6 | *
|
---|
| 7 | * A component of the Greenstone digital library software
|
---|
| 8 | * from the New Zealand Digital Library Project at the
|
---|
| 9 | * University of Waikato, New Zealand.
|
---|
| 10 | *
|
---|
| 11 | * This program is free software; you can redistribute it and/or modify
|
---|
| 12 | * it under the terms of the GNU General Public License as published by
|
---|
| 13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | * (at your option) any later version.
|
---|
| 15 | *
|
---|
| 16 | * This program is distributed in the hope that it will be useful,
|
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | * GNU General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
| 22 | * along with this program; if not, write to the Free Software
|
---|
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | *
|
---|
| 25 | *********************************************************************/
|
---|
| 26 |
|
---|
[8182] | 27 | #include "oaidispatcher.h"
|
---|
| 28 |
|
---|
| 29 | oaidispatcher::oaidispatcher()
|
---|
| 30 | { this->configuration = NULL;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | oaidispatcher::~oaidispatcher()
|
---|
| 34 | {
|
---|
| 35 | oaiactionmap::iterator here = this->actions.begin();
|
---|
| 36 | oaiactionmap::iterator end = this->actions.end();
|
---|
| 37 |
|
---|
| 38 | while (here != end) {
|
---|
| 39 | delete here->second;
|
---|
[9608] | 40 | ++here;
|
---|
[8182] | 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | void oaidispatcher::addAction(oaiaction *thisAction) {
|
---|
| 45 | thisAction->setConfiguration(this->configuration);
|
---|
| 46 | this->actions[thisAction->getName()] = thisAction;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | void oaidispatcher::doAction(ostream &output, recptproto *protocol, oaiargs &args) {
|
---|
| 50 |
|
---|
| 51 | text_t verb = args["Verb"];
|
---|
| 52 | if(verb == "") verb = args["verb"];
|
---|
| 53 |
|
---|
| 54 | oaiaction *action = actions[verb];
|
---|
| 55 |
|
---|
| 56 | if (action != NULL) {
|
---|
| 57 | action->getResponse(output, protocol, args);
|
---|
| 58 | }
|
---|
| 59 | else {
|
---|
| 60 | // If the verb isn't correct, send an error.
|
---|
| 61 | action = actions["Identify"];
|
---|
| 62 | text_t responseDate, requestURL;
|
---|
| 63 | int version = this->configuration->getOAIVersion();
|
---|
| 64 | action->getResponseDate(responseDate);
|
---|
| 65 | oaiargs emptySet;
|
---|
| 66 | action->getRequestURL(emptySet, requestURL);
|
---|
| 67 |
|
---|
| 68 | // Bad verb is signified by a status 400 response for OAI 1.1
|
---|
| 69 | if (version <= 110) {
|
---|
| 70 | output << "Status: 400\n";
|
---|
| 71 | }
|
---|
| 72 | else {
|
---|
| 73 | output << "Status: 200\n";
|
---|
| 74 | }
|
---|
| 75 | output << "Content-type: text/xml" << endl << endl;
|
---|
| 76 | output << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
|
---|
| 77 |
|
---|
| 78 | if(version <= 110){
|
---|
| 79 | // output OAI v1.1 action header tag - nil, as there is no valid heeader for the action
|
---|
| 80 | /*
|
---|
| 81 | output << "<" << action->name;
|
---|
[15192] | 82 | output << "\n xmlns=\"http://www.openarchives.org/OAI/1.1/OAI_" << action->name << "\" ";
|
---|
[8182] | 83 | output << "\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
|
---|
| 84 | output << "\n xsi:schemaLocation=\"http://www.openarchives.org/OAI/1.1/OAI_" << action->name;
|
---|
| 85 | output << "\n http://www.openarchives.org/OAI/1.1/OAI_" << action->name << ".xsd\">\n";
|
---|
| 86 | */
|
---|
| 87 | }
|
---|
| 88 | else {
|
---|
| 89 | // output OAI v2.0 action header tag
|
---|
[23234] | 90 | text_t baseDocRoot = this->configuration->getRelativeBaseDocRoot();
|
---|
[21980] | 91 | output << "<?xml-stylesheet type=\"text/xsl\" href=\""<<baseDocRoot<<"/web/style/oai2.xsl\" ?>\n";
|
---|
[15192] | 92 | output << "<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\"\n"
|
---|
[8182] | 93 | << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
|
---|
| 94 | << " xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/\n"
|
---|
| 95 | << " http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">\n"
|
---|
| 96 | << " <responseDate>" << responseDate << "</responseDate>\n"
|
---|
| 97 | << requestURL
|
---|
| 98 | << " <error code=\"badVerb\">Illegal OAI verb</error>\n"
|
---|
| 99 | << "</OAI-PMH>\n";
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | /*
|
---|
| 103 | cout << "<title>Bad OAI request</title>" << endl;
|
---|
| 104 | cout << "<h1>Bad OAI request</h1>" << endl;
|
---|
| 105 | */
|
---|
| 106 | }
|
---|
| 107 | output.flush();
|
---|
| 108 | }
|
---|