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