[22739] | 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 |
|
---|
[8182] | 27 | #include "metaformatsaction.h"
|
---|
| 28 | #include "metaformat.h"
|
---|
[15428] | 29 | #include "recptprototools.h"
|
---|
[8182] | 30 | #include "oaitools.h"
|
---|
| 31 |
|
---|
| 32 | bool metaformatsaction::validateAction(recptproto *protocol, oaiargs ¶ms)
|
---|
| 33 | {
|
---|
[16716] | 34 | // ----------------------------------------------------------------------------
|
---|
| 35 | // 1. Check for invalid arguments
|
---|
| 36 | // ----------------------------------------------------------------------------
|
---|
| 37 | bool invalid_argument_supplied = false;
|
---|
[15198] | 38 | text_tmap::const_iterator param_iterator = params.begin();
|
---|
| 39 | while (param_iterator != params.end())
|
---|
| 40 | {
|
---|
[16716] | 41 | // Check for arguments that aren't valid for this action
|
---|
[15198] | 42 | if (param_iterator->first != "verb" &&
|
---|
| 43 | param_iterator->first != "identifier")
|
---|
| 44 | {
|
---|
[16716] | 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
|
---|
[15198] | 49 | params.erase(param_iterator->first);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | param_iterator++;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[16716] | 55 | // If we found an invalid argument it's an error, so don't go any further
|
---|
| 56 | if (invalid_argument_supplied)
|
---|
| 57 | {
|
---|
[8182] | 58 | this->errorType = "badArgument";
|
---|
| 59 | return false;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[16716] | 62 | // ----------------------------------------------------------------------------
|
---|
| 63 | // 2. Handle any exclusive arguments
|
---|
| 64 | // ----------------------------------------------------------------------------
|
---|
[8182] | 65 |
|
---|
[16716] | 66 | // None!
|
---|
[8182] | 67 |
|
---|
[16716] | 68 | // ----------------------------------------------------------------------------
|
---|
| 69 | // 3. Handle any required arguments
|
---|
| 70 | // ----------------------------------------------------------------------------
|
---|
[8182] | 71 |
|
---|
[16716] | 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 | {
|
---|
[8182] | 91 | this->errorType = "idDoesNotExist";
|
---|
[16716] | 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 | {
|
---|
[8182] | 99 | return false;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
[16716] | 103 |
|
---|
| 104 | // If we've reached here everything must be fine
|
---|
| 105 | this->errorType = "";
|
---|
[8182] | 106 | return true;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | bool metaformatsaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms)
|
---|
| 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 | }
|
---|
[9608] | 146 | ++here;
|
---|
[8182] | 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | return true;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | void 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);
|
---|
[9608] | 161 | ++here;
|
---|
[8182] | 162 | }
|
---|
| 163 | }
|
---|
| 164 |
|
---|