source: gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.cpp@ 16708

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

Changed all the "OIDtools.h" to "recptprototools.h".

  • 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 "recptprototools.h"
4#include "oaitools.h"
5
6bool metaformatsaction::validateAction(recptproto *protocol, oaiargs &params)
7{
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
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"] != "") {
28 ++numArgs;
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
33 if((params_size != numArgs)){
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
65bool metaformatsaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
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 }
102 ++here;
103 }
104 }
105
106 return true;
107}
108
109void 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);
117 ++here;
118 }
119}
120
Note: See TracBrowser for help on using the repository browser.