source: gsdl/trunk/src/oaiservr/metaformatsaction.cpp@ 15198

Last change on this file since 15198 was 15198, checked in by mdewsnip, 16 years ago

Now each action checks for invalid arguments in the params structure and deletes any that aren't valid, so they don't get into the "<request>" tag in the resulting XML and cause OAI validation errors. By DL Consulting Ltd.

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