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 |
|
---|
27 | #include "identifyaction.h"
|
---|
28 |
|
---|
29 | bool identifyaction::validateAction(recptproto *protocol, oaiargs ¶ms)
|
---|
30 | {
|
---|
31 | // ----------------------------------------------------------------------------
|
---|
32 | // 1. Check for invalid arguments
|
---|
33 | // ----------------------------------------------------------------------------
|
---|
34 | bool invalid_argument_supplied = false;
|
---|
35 | text_tmap::const_iterator param_iterator = params.begin();
|
---|
36 | while (param_iterator != params.end())
|
---|
37 | {
|
---|
38 | // Check for arguments that aren't valid for this action
|
---|
39 | if (param_iterator->first != "verb")
|
---|
40 | {
|
---|
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
|
---|
45 | params.erase(param_iterator->first);
|
---|
46 | }
|
---|
47 |
|
---|
48 | param_iterator++;
|
---|
49 | }
|
---|
50 |
|
---|
51 | // If we found an invalid argument it's an error, so don't go any further
|
---|
52 | if (invalid_argument_supplied)
|
---|
53 | {
|
---|
54 | this->errorType = "badArgument";
|
---|
55 | return false;
|
---|
56 | }
|
---|
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 = "";
|
---|
78 | return true;
|
---|
79 | }
|
---|
80 |
|
---|
81 | bool identifyaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms)
|
---|
82 | {
|
---|
83 | utf8outconvertclass utf8convert;
|
---|
84 |
|
---|
85 | // Get the repository name (some human-readable name for the site, or superset of collections)
|
---|
86 | text_t repositoryName = this->configuration->getRepositoryName();
|
---|
87 | text_t repositoryId = this->configuration->getRepositoryId();
|
---|
88 | // Get admin's email address (i.e. the site maintainer)
|
---|
89 | text_t maintainer = this->configuration->getMaintainer();
|
---|
90 | text_t version = (this->configuration->getOAIVersion() <= 110) ? (text_t)"1.1":(text_t)"2.0";
|
---|
91 | text_t id_version = this->configuration->getRepositoryIdVersion();
|
---|
92 |
|
---|
93 | text_t baseURL = this->configuration->getBaseURL();
|
---|
94 |
|
---|
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";
|
---|
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)
|
---|
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";
|
---|
108 | }
|
---|
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";
|
---|
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";
|
---|
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";
|
---|
122 | output << " http://www.openarchives.org/OAI/2.0/oai-identifier.xsd\">\n";
|
---|
123 |
|
---|
124 |
|
---|
125 | }
|
---|
126 |
|
---|
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";
|
---|
132 |
|
---|
133 | // list all configuration information
|
---|
134 | text_tmap::iterator here = this->configuration->getInformation()->begin();
|
---|
135 | text_tmap::iterator end = this->configuration->getInformation()->end();
|
---|
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";
|
---|
148 | }
|
---|
149 |
|
---|
150 | output << utf8convert << " </description>\n";
|
---|
151 |
|
---|
152 | return true;
|
---|
153 | }
|
---|
154 |
|
---|