source: main/trunk/greenstone2/runtime-src/src/oaiservr/metaformatsaction.cpp@ 22289

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

Tidied up the validateAction() function to be consistently structured.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 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 // ----------------------------------------------------------------------------
9 // 1. Check for invalid arguments
10 // ----------------------------------------------------------------------------
11 bool invalid_argument_supplied = false;
12 text_tmap::const_iterator param_iterator = params.begin();
13 while (param_iterator != params.end())
14 {
15 // Check for arguments that aren't valid for this action
16 if (param_iterator->first != "verb" &&
17 param_iterator->first != "identifier")
18 {
19 // We've found an invalid argument
20 invalid_argument_supplied = true;
21
22 // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
23 params.erase(param_iterator->first);
24 }
25
26 param_iterator++;
27 }
28
29 // If we found an invalid argument it's an error, so don't go any further
30 if (invalid_argument_supplied)
31 {
32 this->errorType = "badArgument";
33 return false;
34 }
35
36 // ----------------------------------------------------------------------------
37 // 2. Handle any exclusive arguments
38 // ----------------------------------------------------------------------------
39
40 // None!
41
42 // ----------------------------------------------------------------------------
43 // 3. Handle any required arguments
44 // ----------------------------------------------------------------------------
45
46 // None!
47
48 // ----------------------------------------------------------------------------
49 // 4. Check any remaining arguments
50 // ----------------------------------------------------------------------------
51
52 // Check "identifier" argument
53 if (params["identifier"] != "")
54 {
55 text_t identifier = params["identifier"];
56
57 // Extract the collection name from the identifier specification
58 text_t collection = "";
59 oaiclassifier::toGSDL(collection, identifier);
60
61 // Check a document with the specified identifier exists
62 text_tset metadata;
63 if (!get_info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout))
64 {
65 this->errorType = "idDoesNotExist";
66
67 // Only throw an error if we're using v2.0.
68 // v1.1 should simply return a response without a metadataFormat container. 1.1
69 // should still set the errorType so we know that the error was encountered
70 // the information retrieved here is retained for the output_content function below
71 if (this->configuration->getOAIVersion() >= 200)
72 {
73 return false;
74 }
75 }
76 }
77
78 // If we've reached here everything must be fine
79 this->errorType = "";
80 return true;
81}
82
83bool metaformatsaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
84{
85 // if an identifier parameter is being used, then respond to it - currently we reject anything other
86 // than dublin core (unqualified)
87 //
88 // TODO: only return the selected identifier (if given) and don't validate the entry; just
89 // return nothing if an invalid or unknown metadata format is given
90
91 // give the required xml response
92
93 text_t gsdlId = params["identifier"];
94 text_t gsdlCollect;
95
96 // convert record identifier into GSDL format from OAI
97 if (gsdlId != "") {
98 oaiclassifier::toGSDL(gsdlCollect, gsdlId);
99 }
100
101 metaformat_map::iterator here = this->formats->begin();
102 metaformat_map::iterator end = this->formats->end();
103
104 // v1.1 should check that the id - if supplied - didn't cause an error. If it did,
105 // don't output the metadataFormat tags. OAI v2.0 should already have bailed.
106 if(this->errorType != "idDoesNotExist"){
107 while (here != end) { // Loop through the repository's supported metadata formats
108 bool doOutput = true;
109
110 // if we were given an identifier, then check if it supports the metadata format in question
111 if (gsdlId != "") {
112 doOutput = here->second.get_class()->is_available(gsdlCollect, this->gsdlResponse.docInfo[0]);
113 }
114
115 if (doOutput) {
116 output << " <metadataFormat>" << endl;
117 here->second.get_class()->output_formatdata(output);
118 output << " </metadataFormat>\n";
119 }
120 ++here;
121 }
122 }
123
124 return true;
125}
126
127void metaformatsaction::setConfiguration(oaiconfig *configuration)
128{
129 this->configuration = configuration;
130
131 metaformat_map::iterator here = this->formats->begin();
132 metaformat_map::iterator end = this->formats->end();
133 while (here != end) {
134 here->second.set_configuration((oaiconfig *) configuration);
135 ++here;
136 }
137}
138
Note: See TracBrowser for help on using the repository browser.