source: gsdl/trunk/src/oaiservr/listidsaction.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: 2.2 KB
Line 
1#include "listidsaction.h"
2#include "OIDtools.h"
3#include "oaitools.h"
4
5//--------------------------------------------------------------------------------------------------
6
7bool listidsaction::validateAction(recptproto *protocol, oaiargs &params)
8{
9 int params_size = params.getSize();
10 int numArgs = 1; // For "verb" arg
11
12 if (!abstractlistaction::validateAction(protocol, params, numArgs)) {
13 return false;
14 }
15
16 // In OAI v1.1 metadataPrefix is not allowed.
17 if (this->configuration->getOAIVersion() <= 110){
18 if(numArgs != params_size){
19 this->errorType = "badArgument";
20 return false;
21 }
22 }
23 else { // In OAI v2.0, it is compulsory
24 text_t metaFormat = params["metadataPrefix"];
25 if (metaFormat == ""){
26 this->errorType = "badArgument";
27 return false;
28 }
29 else { // If it isn't empty, increase the valid args count and compare this to the total num of args
30 if (++numArgs != params_size){
31 this->errorType = "badArgument";
32 return false;
33 }
34 }
35 // Check that the metadataPrefix is a format we support
36 if (this->formatNotSupported(metaFormat)){
37 this->errorType = "cannotDisseminateFormat";
38 return false;
39 }
40 }
41 this->errorType = "";
42 return true;
43}
44
45//--------------------------------------------------------------------------------------------------
46
47bool listidsaction::output_document(ostream& output, recptproto *protocol, const text_t &collection,
48 const text_t &OID, const text_t &metadataPrefix /* ignored */)
49{
50 FilterResponse_t response;
51 ResultDocInfo_t doc_info;
52 text_tset metadata;
53 ofstream logout("oai.log", ios::app);
54 text_t lastModified;
55 int oaiVersion = this->configuration->getOAIVersion();
56
57 get_info(OID, collection, "", metadata, false, protocol, response, logout);
58 doc_info = response.docInfo[0];
59 this->getLastModifiedDate(doc_info, lastModified);
60
61 // output the record for this document
62 text_t oaiLabel = OID;
63 oaiclassifier::toOAI(collection, oaiLabel);
64
65 if(oaiVersion <= 110)
66 output << " <identifier>" << oaiLabel << "</identifier>\n";
67 else
68 this->output_record_header(output, oaiLabel, lastModified,
69 doc_info.metadata["memberof"].values, oaiVersion);
70
71 return true;
72}
Note: See TracBrowser for help on using the repository browser.