source: gsdl/trunk/runtime-src/src/oaiservr/oaitools.cpp@ 20589

Last change on this file since 20589 was 20589, checked in by mdewsnip, 11 years ago

Removed some unnecessary #includes.

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