source: trunk/gsdl/src/oaiservr/oaitools.cpp@ 8182

Last change on this file since 8182 was 8182, checked in by cs025, 20 years ago

Added OAI Server code to Greenstone

  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1#include "oaitools.h"
2
3#include <algorithm>
4
5#include "OIDtools.h"
6
7text_t oaiclassifier::getGSDL_OID(const text_t &collection, const text_t& oai_id,
8 recptproto *protocol, ostream &logout)
9{
10 FilterResponse_t response;
11 text_tset metadata;
12
13 // metadata.insert("gsdl_id");
14
15 bool status_ok = get_children(oai_id, collection, "", metadata, false, protocol, response, logout);
16 text_t gsdl_id = "";
17 if (status_ok) {
18 if(response.docInfo.size() > 0){
19 gsdl_id = response.docInfo[0].OID;
20 }
21 else // Response.docInfo is empty, meaning the doc in question didn't have an oai_id number.
22 return gsdl_id; // Return the empty string to indicate this.
23 }
24
25 return gsdl_id;
26}
27
28/**
29 * Called to convert GS classifier/document identifiers that use
30 * a '.' to separate levels in the hierarchy into OAI identifiers
31 * that use ':' instead.
32 */
33void oaiclassifier::toOAI(const text_t &collection, text_t &classifier)
34{
35 for (int i = 1; i <= classifier.size(); i ++) {
36 if (classifier[i] == '.') {
37 classifier[i] = ':';
38 }
39 }
40
41 // prepend the collection identifier to the beginning of the
42 // OAI identifier.
43 text_t tmp = collection;
44 tmp.append(":");
45 tmp.append(classifier);
46
47 classifier = tmp;
48}
49
50/**
51 * Called to convert OAI classifier/document identifiers that use
52 * a ':' to separate levels in the hierarchy into GS identifiers
53 * that use '.' instead.
54 */
55void oaiclassifier::toGSDL(text_t &collection, text_t &classifier)
56{
57 for (int i = 1; i <= classifier.size(); i ++) {
58 if (classifier[i] == ':') {
59 classifier[i] = '.';
60 }
61 }
62
63 // separate out the collection identifier that should be
64 // found at the beginning of the OAI identifier from the
65 // item identifier within the collection
66 text_t::iterator colon = find(classifier.begin(), classifier.end(), '.');
67 if (colon != classifier.end()) {
68 collection = substr(classifier.begin(), colon);
69 classifier = substr(colon + 1, classifier.end());
70 }
71 else{
72 collection = classifier;
73 classifier = "";
74 }
75}
Note: See TracBrowser for help on using the repository browser.