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

Last change on this file since 9608 was 9608, checked in by kjdon, 19 years ago

added in x++ -> ++x changes submitted by Emanuel Dejanu

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