#include "metaformatsaction.h" #include "metaformat.h" #include "recptprototools.h" #include "oaitools.h" bool metaformatsaction::validateAction(recptproto *protocol, oaiargs ¶ms) { int params_size = params.getSize(); // Remove any parameters that aren't valid for this action text_tmap::const_iterator param_iterator = params.begin(); while (param_iterator != params.end()) { if (param_iterator->first != "verb" && param_iterator->first != "identifier") { params.erase(param_iterator->first); } param_iterator++; } int numArgs = 1; // the number of expected arguments // increase the number of expected arguments if the optional 'identifier' argument // is given if (params["identifier"] != "") { ++numArgs; } // If the total number of params isn't equal to the number of valid // args (i.e. we have an arg but it isn't the identifier), throw an error if((params_size != numArgs)){ this->errorType = "badArgument"; return false; } // Variables to hold identifier in Greenstone format text_t docID = params["identifier"]; text_t collection = ""; // The following two variables are used solely by the get_info() function call to test if // the identifier supplied is an actual document. If it isn't, we need to throw an exception. const text_tset metadata; // Check for the existence, etc. of the record if an identifier is given. if (docID != "") { oaiclassifier::toGSDL(collection, docID); // Only throw an error if we're using v2.0. // v1.1 should simply return a response without a metadataFormat container. 1.1 // should still set the errorType so we know that the error was encountered // the information retrieved here is retained for the output_content function below if (!get_info(docID, collection, "", metadata, false, protocol, this->gsdlResponse, cerr)){ this->errorType = "idDoesNotExist"; if(this->configuration->getOAIVersion() >= 200) { return false; } } } return true; } bool metaformatsaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms) { // if an identifier parameter is being used, then respond to it - currently we reject anything other // than dublin core (unqualified) // // TODO: only return the selected identifier (if given) and don't validate the entry; just // return nothing if an invalid or unknown metadata format is given // give the required xml response text_t gsdlId = params["identifier"]; text_t gsdlCollect; // convert record identifier into GSDL format from OAI if (gsdlId != "") { oaiclassifier::toGSDL(gsdlCollect, gsdlId); } metaformat_map::iterator here = this->formats->begin(); metaformat_map::iterator end = this->formats->end(); // v1.1 should check that the id - if supplied - didn't cause an error. If it did, // don't output the metadataFormat tags. OAI v2.0 should already have bailed. if(this->errorType != "idDoesNotExist"){ while (here != end) { // Loop through the repository's supported metadata formats bool doOutput = true; // if we were given an identifier, then check if it supports the metadata format in question if (gsdlId != "") { doOutput = here->second.get_class()->is_available(gsdlCollect, this->gsdlResponse.docInfo[0]); } if (doOutput) { output << " " << endl; here->second.get_class()->output_formatdata(output); output << " \n"; } ++here; } } return true; } void metaformatsaction::setConfiguration(oaiconfig *configuration) { this->configuration = configuration; metaformat_map::iterator here = this->formats->begin(); metaformat_map::iterator end = this->formats->end(); while (here != end) { here->second.set_configuration((oaiconfig *) configuration); ++here; } }