source: trunk/gsdl/src/oaiservr/listsetsaction.cpp@ 9608

Last change on this file since 9608 was 9608, checked in by kjdon, 19 years ago

added in x++ -> ++x changes submitted by Emanuel Dejanu

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1#include "listsetsaction.h"
2
3#if defined(GSDL_USE_STL_H)
4#include <fstream.h>
5#else
6#include <fstream>
7#endif
8
9#include "OIDtools.h"
10#include "oaitools.h"
11
12bool listsetsaction::validateAction(recptproto *protocol, oaiargs &params)
13{ if(params.getSize() != 1){
14 this->errorType = "badArgument";
15 return false;
16 }
17
18 return true;
19}
20
21bool listsetsaction::output_content(ostream &output, recptproto *protocol, text_tset &collections, oaiargs &params)
22{
23 text_tset::iterator here = collections.begin();
24 text_tset::iterator end = collections.end();
25 while (here != end) {
26 text_t collect = *here;
27 this->output_content(output, protocol, params);
28 ++here;
29 }
30 return true;
31}
32
33bool listsetsaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
34{
35 // output the total list of classifier points
36
37 // variables required
38 text_t browseOID = "browse";
39 FilterResponse_t response;
40 comerror_t err;
41 text_tarray & collections = this->configuration->getCollectionsList();
42 text_tset metadata;
43 ofstream logout("oai.log", ios::app);
44 text_tarray *result = new text_tarray;
45
46 // get a list of the collections available
47 // protocol->get_collection_list(collections, err, output);
48 if (collections.size() == 0) {
49 logout << "Found *no* OAI collections - check main.cfg for oaicollection items and read the OAI documentation.\n";
50 }
51
52 for(int current_col = 0; current_col < collections.size(); ++current_col) {
53 // output the collection as a set, first, then its children
54 text_t gsdlCollect = collections[current_col];
55
56 output << " <set>" << endl;
57 output << " <setSpec>" << gsdlCollect << "</setSpec>" << endl;;
58 output << " <setName>" << gsdlCollect << "</setName>" << endl;
59 output << " </set>" << endl;
60
61 // get all the children of the (relevant) classifier data structures
62 get_children(browseOID, gsdlCollect, "", metadata, false, protocol, response, logout);
63
64 // and send them to the "recurse_content" list
65 for (int c = 0; c < response.numDocs; ++c) {
66 this->recurse_content(output, protocol, gsdlCollect, response.docInfo[c].OID, gsdlCollect);
67 }
68 }
69
70 return true;
71}
72
73void listsetsaction::recurse_content(ostream &output, recptproto *protocol, text_t &collection,
74 const text_t &classifier, text_t setHierarchy)
75{
76 // metadata for this call
77 FilterResponse_t response;
78 text_tset metadata;
79 ofstream logout("oai.log", ios::app);
80
81 metadata.insert("contains");
82 metadata.insert("Title");
83 metadata.insert("supportsmemberof");
84
85 // get the document information
86 if (!get_info(classifier, collection, "", metadata, false, protocol, response, logout)) {
87 // cerr << "Bad identifier or protocol " << classifier << endl;
88 return;
89 }
90
91 // check for top-level classifiers, check if the set name includes a '.'; if
92 // not, it is a top-level classifier: check for memberof support. Those without
93 // memberof support will not be supported on OAI
94 if (findchar(classifier.begin(), classifier.end(), '.') == classifier.end()) {
95 if (response.docInfo[0].metadata["supportsmemberof"].values.size() > 0) {
96 text_t memberOf = response.docInfo[0].metadata["supportsmemberof"].values[0];
97 if (memberOf != "true") {
98 return;
99 }
100 }
101 else {
102 return;
103 }
104 }
105
106 MetadataInfo_tmap::iterator here = response.docInfo[0].metadata.begin();
107 MetadataInfo_tmap::iterator end = response.docInfo[0].metadata.end();
108 text_t title;
109
110 while (here != end)
111 {
112 // Each set should only have one title - hence we only output one title here
113 // (it is a set title, not a collection)
114 if (here->first == "Title" && here->second.values.size() > 0) {
115 title = here->second.values[0];
116 }
117
118 ++here;
119 }
120
121 // output the xml for this set; use the classifier id for the name
122 // if the title is blank
123 output << " <set>" << endl;
124 text_t oai_classifier = classifier;
125 oaiclassifier::toOAI(collection, oai_classifier);
126 output << " <setSpec>" << oai_classifier << "</setSpec>" << endl;
127 output << " <setName>";
128 // curSet holds the colon-separated sequence of parent sets of the current set
129 text_t curSet;
130 if (!title.empty()) {
131 curSet = setHierarchy + ":" + title;
132 }
133 else {
134 curSet = classifier; // Pretty much never gets here (shouldn't, at least)
135 }
136 output << curSet;
137 output << "</setName>" << endl;
138 output << " </set>" << endl;
139
140 // get the children of this classifier and iterate them
141 get_children(classifier, collection, "", metadata, false, protocol, response, logout);
142 for (int c = 0; c < response.numDocs; ++c) {
143 text_t child = response.docInfo[c].OID;
144
145 if (child == classifier)
146 continue;
147
148 // check for HASH items and exclude them
149 text_t childHead;
150 text_t::const_iterator start = child.begin();
151 text_t::const_iterator here = child.begin();
152 here += 4;
153 childHead = substr(start, here);
154
155 if (childHead == "HASH")
156 continue;
157
158 // Recurse for "proper" classifier children. Pass curSet, the colon-separated list of
159 // parent sets. curSet is pass-by-value, so that as we step out of recursion we remember
160 // old set hierarchies.
161 this->recurse_content(output, protocol, collection, child, curSet);
162 }
163
164 return;
165}
Note: See TracBrowser for help on using the repository browser.