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

Last change on this file since 22739 was 22739, checked in by mdewsnip, 14 years ago

Added copyright header to runtime-src/src/oaiserver/*.cpp and runtime-src/src/oaiserver/*.h.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/**********************************************************************
2 *
3 * metaformatsaction.cpp --
4 *
5 * Copyright (C) 2004-2010 The New Zealand Digital Library Project
6 *
7 * A component of the Greenstone digital library software
8 * from the New Zealand Digital Library Project at the
9 * University of Waikato, New Zealand.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 *********************************************************************/
26
27#include "metaformatsaction.h"
28#include "metaformat.h"
29#include "recptprototools.h"
30#include "oaitools.h"
31
32bool metaformatsaction::validateAction(recptproto *protocol, oaiargs &params)
33{
34 // ----------------------------------------------------------------------------
35 // 1. Check for invalid arguments
36 // ----------------------------------------------------------------------------
37 bool invalid_argument_supplied = false;
38 text_tmap::const_iterator param_iterator = params.begin();
39 while (param_iterator != params.end())
40 {
41 // Check for arguments that aren't valid for this action
42 if (param_iterator->first != "verb" &&
43 param_iterator->first != "identifier")
44 {
45 // We've found an invalid argument
46 invalid_argument_supplied = true;
47
48 // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
49 params.erase(param_iterator->first);
50 }
51
52 param_iterator++;
53 }
54
55 // If we found an invalid argument it's an error, so don't go any further
56 if (invalid_argument_supplied)
57 {
58 this->errorType = "badArgument";
59 return false;
60 }
61
62 // ----------------------------------------------------------------------------
63 // 2. Handle any exclusive arguments
64 // ----------------------------------------------------------------------------
65
66 // None!
67
68 // ----------------------------------------------------------------------------
69 // 3. Handle any required arguments
70 // ----------------------------------------------------------------------------
71
72 // None!
73
74 // ----------------------------------------------------------------------------
75 // 4. Check any remaining arguments
76 // ----------------------------------------------------------------------------
77
78 // Check "identifier" argument
79 if (params["identifier"] != "")
80 {
81 text_t identifier = params["identifier"];
82
83 // Extract the collection name from the identifier specification
84 text_t collection = "";
85 oaiclassifier::toGSDL(collection, identifier);
86
87 // Check a document with the specified identifier exists
88 text_tset metadata;
89 if (!get_info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout))
90 {
91 this->errorType = "idDoesNotExist";
92
93 // Only throw an error if we're using v2.0.
94 // v1.1 should simply return a response without a metadataFormat container. 1.1
95 // should still set the errorType so we know that the error was encountered
96 // the information retrieved here is retained for the output_content function below
97 if (this->configuration->getOAIVersion() >= 200)
98 {
99 return false;
100 }
101 }
102 }
103
104 // If we've reached here everything must be fine
105 this->errorType = "";
106 return true;
107}
108
109bool metaformatsaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
110{
111 // if an identifier parameter is being used, then respond to it - currently we reject anything other
112 // than dublin core (unqualified)
113 //
114 // TODO: only return the selected identifier (if given) and don't validate the entry; just
115 // return nothing if an invalid or unknown metadata format is given
116
117 // give the required xml response
118
119 text_t gsdlId = params["identifier"];
120 text_t gsdlCollect;
121
122 // convert record identifier into GSDL format from OAI
123 if (gsdlId != "") {
124 oaiclassifier::toGSDL(gsdlCollect, gsdlId);
125 }
126
127 metaformat_map::iterator here = this->formats->begin();
128 metaformat_map::iterator end = this->formats->end();
129
130 // v1.1 should check that the id - if supplied - didn't cause an error. If it did,
131 // don't output the metadataFormat tags. OAI v2.0 should already have bailed.
132 if(this->errorType != "idDoesNotExist"){
133 while (here != end) { // Loop through the repository's supported metadata formats
134 bool doOutput = true;
135
136 // if we were given an identifier, then check if it supports the metadata format in question
137 if (gsdlId != "") {
138 doOutput = here->second.get_class()->is_available(gsdlCollect, this->gsdlResponse.docInfo[0]);
139 }
140
141 if (doOutput) {
142 output << " <metadataFormat>" << endl;
143 here->second.get_class()->output_formatdata(output);
144 output << " </metadataFormat>\n";
145 }
146 ++here;
147 }
148 }
149
150 return true;
151}
152
153void metaformatsaction::setConfiguration(oaiconfig *configuration)
154{
155 this->configuration = configuration;
156
157 metaformat_map::iterator here = this->formats->begin();
158 metaformat_map::iterator end = this->formats->end();
159 while (here != end) {
160 here->second.set_configuration((oaiconfig *) configuration);
161 ++here;
162 }
163}
164
Note: See TracBrowser for help on using the repository browser.