source: main/trunk/greenstone2/runtime-src/src/oaiservr/identifyaction.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: 6.4 KB
RevLine 
[22739]1/**********************************************************************
2 *
3 * identifyaction.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
[15844]27#include "identifyaction.h"
[8182]28
[15844]29bool identifyaction::validateAction(recptproto *protocol, oaiargs &params)
[8182]30{
[16711]31 // ----------------------------------------------------------------------------
32 // 1. Check for invalid arguments
33 // ----------------------------------------------------------------------------
34 bool invalid_argument_supplied = false;
[15198]35 text_tmap::const_iterator param_iterator = params.begin();
36 while (param_iterator != params.end())
37 {
[16711]38 // Check for arguments that aren't valid for this action
[15198]39 if (param_iterator->first != "verb")
40 {
[16711]41 // We've found an invalid argument
42 invalid_argument_supplied = true;
43
44 // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
[15198]45 params.erase(param_iterator->first);
46 }
47
48 param_iterator++;
49 }
[16711]50
51 // If we found an invalid argument it's an error, so don't go any further
52 if (invalid_argument_supplied)
53 {
[8182]54 this->errorType = "badArgument";
55 return false;
56 }
[16711]57
58 // ----------------------------------------------------------------------------
59 // 2. Handle any exclusive arguments
60 // ----------------------------------------------------------------------------
61
62 // None!
63
64 // ----------------------------------------------------------------------------
65 // 3. Handle any required arguments
66 // ----------------------------------------------------------------------------
67
68 // None!
69
70 // ----------------------------------------------------------------------------
71 // 4. Check any remaining arguments
72 // ----------------------------------------------------------------------------
73
74 // None!
75
76 // If we've reached here everything must be fine
77 this->errorType = "";
[8182]78 return true;
79}
80
[15844]81bool identifyaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
[8182]82{
[20707]83 utf8outconvertclass utf8convert;
84
[8182]85 // Get the repository name (some human-readable name for the site, or superset of collections)
[22213]86 text_t repositoryName = this->configuration->getRepositoryName();
[22287]87 text_t repositoryId = this->configuration->getRepositoryId();
[8182]88 // Get admin's email address (i.e. the site maintainer)
[22213]89 text_t maintainer = this->configuration->getMaintainer();
[8182]90 text_t version = (this->configuration->getOAIVersion() <= 110) ? (text_t)"1.1":(text_t)"2.0";
[22287]91 text_t id_version = this->configuration->getRepositoryIdVersion();
92
[22213]93 text_t baseURL = this->configuration->getBaseURL();
[8182]94
[20707]95 output << utf8convert << " <repositoryName>" << repositoryName << "</repositoryName>\n";
96 output << utf8convert << " <baseURL>" << baseURL << "</baseURL>\n";
97 output << utf8convert << " <protocolVersion>" << version << "</protocolVersion>\n";
98 output << utf8convert << " <adminEmail>" << maintainer << "</adminEmail>\n";
[8182]99
100 if(version == "2.0"){
101 // earliestDatestamp *should* be the YYYY-MM-DD format of the oldest lastmodified record in the
102 // repository, but we're just setting it to be the default oldest possible date - ugly, but judged
103 // not to be worth the effort of trolling through all the lastmodified dates (by others with more
104 // say than me)
[20707]105 output << utf8convert << " <earliestDatestamp>1970-01-01</earliestDatestamp>\n";
106 output << utf8convert << " <deletedRecord>no</deletedRecord>\n";
107 output << utf8convert << " <granularity>YYYY-MM-DD</granularity>\n";
[8182]108 }
[22287]109 // list the oai identifier
110 output << " <description>\n";
111 if (id_version == "1.1") {
112
113 output << " <oai-identifier xmlns=\"http://www.openarchives.org/OAI/1.1/oai-identifier\"\n";
114 output << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
[22557]115 output << " xsi:schemaLocation=\"http://www.openarchives.org/OAI/1.1/oai-identifier\n";
116 output << " http://www.openarchives.org/OAI/1.1/oai-identifier.xsd\">\n";
[22287]117 } else {
118
119 output << " <oai-identifier xmlns=\"http://www.openarchives.org/OAI/2.0/oai-identifier\"\n";
120 output << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
121 output << " xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai-identifier\n";
[22557]122 output << " http://www.openarchives.org/OAI/2.0/oai-identifier.xsd\">\n";
[22287]123
124
125 }
126
[22557]127 output << " <scheme>oai</scheme>\n";
128 output << " <repositoryIdentifier>"<< repositoryId <<"</repositoryIdentifier>\n";
129 output << " <delimiter>:</delimiter>\n";
130 output << " <sampleIdentifier>oai:"<<repositoryId<<":demo:HASH983080b052e9230b7ccf94</sampleIdentifier>\n";
131 output << " </oai-identifier>\n";
[22287]132
[8182]133 // list all configuration information
134 text_tmap::iterator here = this->configuration->getInformation()->begin();
135 text_tmap::iterator end = this->configuration->getInformation()->end();
[22557]136 if (here != end) {
137 output << " <gsdl xmlns=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\"\n";
138 output << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
139 output << " xsi:schemaLocation=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\n";
140 output << " http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo.xsd\">\n";
141
142
143 while (here != end) {
144 output << utf8convert << " <Metadata name=\"" << here->first << "\">" << here->second << "</Metadata>\n";
145 ++here;
146 }
147 output << " </gsdl>\n";
[8182]148 }
149
[22557]150 output << utf8convert << " </description>\n";
151
[8182]152 return true;
153}
154
Note: See TracBrowser for help on using the repository browser.