source: main/tags/2.80/gsdl/src/oaiservr/listsetsaction.cpp@ 24527

Last change on this file since 24527 was 11311, checked in by kjdon, 18 years ago

anywhere where we determine document/classifier by checking for starting with HASH, I changed to check if starts with CL

  • 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 // and send them to the "recurse_content" list
64 for (int c = 0; c < response.numDocs; ++c) {
65 this->recurse_content(output, protocol, gsdlCollect, response.docInfo[c].OID, gsdlCollect);
66 }
67 }
68
69 return true;
70}
71
72void listsetsaction::recurse_content(ostream &output, recptproto *protocol, text_t &collection,
73 const text_t &classifier, text_t setHierarchy)
74{
75 // metadata for this call
76 FilterResponse_t response;
77 text_tset metadata;
78 ofstream logout("oai.log", ios::app);
79
80 metadata.insert("contains");
81 metadata.insert("Title");
82 metadata.insert("supportsmemberof");
83
84 // get the document information
85 if (!get_info(classifier, collection, "", metadata, false, protocol, response, logout)) {
86 //cerr << "recurse content: Bad identifier or protocol " << classifier << endl;
87 return;
88 }
89
90 // check for top-level classifiers, check if the set name includes a '.'; if
91 // not, it is a top-level classifier: check for memberof support. Those without
92 // memberof support will not be supported on OAI
93 if (findchar(classifier.begin(), classifier.end(), '.') == classifier.end()) {
94 if (response.docInfo[0].metadata["supportsmemberof"].values.size() > 0) {
95 text_t memberOf = response.docInfo[0].metadata["supportsmemberof"].values[0];
96 if (memberOf != "true") {
97 return;
98 }
99 }
100 else {
101 return;
102 }
103 }
104
105 MetadataInfo_tmap::iterator here = response.docInfo[0].metadata.begin();
106 MetadataInfo_tmap::iterator end = response.docInfo[0].metadata.end();
107 text_t title;
108
109 while (here != end)
110 {
111 // Each set should only have one title - hence we only output one title here
112 // (it is a set title, not a collection)
113 if (here->first == "Title" && here->second.values.size() > 0) {
114 title = here->second.values[0];
115 }
116
117 ++here;
118 }
119
120 // output the xml for this set; use the classifier id for the name
121 // if the title is blank
122 output << " <set>" << endl;
123 text_t oai_classifier = classifier;
124 oaiclassifier::toOAI(collection, oai_classifier);
125 output << " <setSpec>" << oai_classifier << "</setSpec>" << endl;
126 output << " <setName>";
127 // curSet holds the colon-separated sequence of parent sets of the current set
128 text_t curSet;
129 if (!title.empty()) {
130 curSet = setHierarchy + ":" + title;
131 }
132 else {
133 curSet = classifier; // Pretty much never gets here (shouldn't, at least)
134 }
135 output << curSet;
136 output << "</setName>" << endl;
137 output << " </set>" << endl;
138
139 // get the children of this classifier and iterate them
140 get_children(classifier, collection, "", metadata, false, protocol, response, logout);
141 for (int c = 0; c < response.numDocs; ++c) {
142 text_t child = response.docInfo[c].OID;
143
144 if (child == classifier)
145 continue;
146
147 // check for non classifier items and exclude them
148 text_t childHead;
149 text_t::const_iterator start = child.begin();
150 text_t::const_iterator here = child.begin();
151 here += 2;
152 childHead = substr(start, here);
153
154 if (childHead != "CL")
155 continue;
156
157 // Recurse for "proper" classifier children. Pass curSet, the colon-separated list of
158 // parent sets. curSet is pass-by-value, so that as we step out of recursion we remember
159 // old set hierarchies.
160 this->recurse_content(output, protocol, collection, child, curSet);
161 }
162
163 return;
164}
Note: See TracBrowser for help on using the repository browser.