[8182] | 1 | #include "metaformatsaction.h"
|
---|
| 2 | #include "metaformat.h"
|
---|
[15428] | 3 | #include "recptprototools.h"
|
---|
[8182] | 4 | #include "oaitools.h"
|
---|
| 5 |
|
---|
| 6 | bool metaformatsaction::validateAction(recptproto *protocol, oaiargs ¶ms)
|
---|
| 7 | {
|
---|
[15198] | 8 | int params_size = params.getSize();
|
---|
| 9 |
|
---|
| 10 | // Remove any parameters that aren't valid for this action
|
---|
| 11 | text_tmap::const_iterator param_iterator = params.begin();
|
---|
| 12 | while (param_iterator != params.end())
|
---|
| 13 | {
|
---|
| 14 | if (param_iterator->first != "verb" &&
|
---|
| 15 | param_iterator->first != "identifier")
|
---|
| 16 | {
|
---|
| 17 | params.erase(param_iterator->first);
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | param_iterator++;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
[8182] | 23 | int numArgs = 1; // the number of expected arguments
|
---|
| 24 |
|
---|
| 25 | // increase the number of expected arguments if the optional 'identifier' argument
|
---|
| 26 | // is given
|
---|
| 27 | if (params["identifier"] != "") {
|
---|
[9608] | 28 | ++numArgs;
|
---|
[8182] | 29 | }
|
---|
| 30 |
|
---|
| 31 | // If the total number of params isn't equal to the number of valid
|
---|
| 32 | // args (i.e. we have an arg but it isn't the identifier), throw an error
|
---|
[15198] | 33 | if((params_size != numArgs)){
|
---|
[8182] | 34 | this->errorType = "badArgument";
|
---|
| 35 | return false;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | // Variables to hold identifier in Greenstone format
|
---|
| 39 | text_t docID = params["identifier"];
|
---|
| 40 | text_t collection = "";
|
---|
| 41 |
|
---|
| 42 | // The following two variables are used solely by the get_info() function call to test if
|
---|
| 43 | // the identifier supplied is an actual document. If it isn't, we need to throw an exception.
|
---|
| 44 | const text_tset metadata;
|
---|
| 45 |
|
---|
| 46 | // Check for the existence, etc. of the record if an identifier is given.
|
---|
| 47 | if (docID != "") {
|
---|
| 48 | oaiclassifier::toGSDL(collection, docID);
|
---|
| 49 |
|
---|
| 50 | // Only throw an error if we're using v2.0.
|
---|
| 51 | // v1.1 should simply return a response without a metadataFormat container. 1.1
|
---|
| 52 | // should still set the errorType so we know that the error was encountered
|
---|
| 53 |
|
---|
| 54 | // the information retrieved here is retained for the output_content function below
|
---|
| 55 | if (!get_info(docID, collection, "", metadata, false, protocol, this->gsdlResponse, cerr)){
|
---|
| 56 | this->errorType = "idDoesNotExist";
|
---|
| 57 | if(this->configuration->getOAIVersion() >= 200) {
|
---|
| 58 | return false;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | return true;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | bool metaformatsaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms)
|
---|
| 66 | {
|
---|
| 67 | // if an identifier parameter is being used, then respond to it - currently we reject anything other
|
---|
| 68 | // than dublin core (unqualified)
|
---|
| 69 | //
|
---|
| 70 | // TODO: only return the selected identifier (if given) and don't validate the entry; just
|
---|
| 71 | // return nothing if an invalid or unknown metadata format is given
|
---|
| 72 |
|
---|
| 73 | // give the required xml response
|
---|
| 74 |
|
---|
| 75 | text_t gsdlId = params["identifier"];
|
---|
| 76 | text_t gsdlCollect;
|
---|
| 77 |
|
---|
| 78 | // convert record identifier into GSDL format from OAI
|
---|
| 79 | if (gsdlId != "") {
|
---|
| 80 | oaiclassifier::toGSDL(gsdlCollect, gsdlId);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | metaformat_map::iterator here = this->formats->begin();
|
---|
| 84 | metaformat_map::iterator end = this->formats->end();
|
---|
| 85 |
|
---|
| 86 | // v1.1 should check that the id - if supplied - didn't cause an error. If it did,
|
---|
| 87 | // don't output the metadataFormat tags. OAI v2.0 should already have bailed.
|
---|
| 88 | if(this->errorType != "idDoesNotExist"){
|
---|
| 89 | while (here != end) { // Loop through the repository's supported metadata formats
|
---|
| 90 | bool doOutput = true;
|
---|
| 91 |
|
---|
| 92 | // if we were given an identifier, then check if it supports the metadata format in question
|
---|
| 93 | if (gsdlId != "") {
|
---|
| 94 | doOutput = here->second.get_class()->is_available(gsdlCollect, this->gsdlResponse.docInfo[0]);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | if (doOutput) {
|
---|
| 98 | output << " <metadataFormat>" << endl;
|
---|
| 99 | here->second.get_class()->output_formatdata(output);
|
---|
| 100 | output << " </metadataFormat>\n";
|
---|
| 101 | }
|
---|
[9608] | 102 | ++here;
|
---|
[8182] | 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | return true;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | void metaformatsaction::setConfiguration(oaiconfig *configuration)
|
---|
| 110 | {
|
---|
| 111 | this->configuration = configuration;
|
---|
| 112 |
|
---|
| 113 | metaformat_map::iterator here = this->formats->begin();
|
---|
| 114 | metaformat_map::iterator end = this->formats->end();
|
---|
| 115 | while (here != end) {
|
---|
| 116 | here->second.set_configuration((oaiconfig *) configuration);
|
---|
[9608] | 117 | ++here;
|
---|
[8182] | 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|