[8182] | 1 | #include "oaitools.h"
|
---|
| 2 |
|
---|
[15428] | 3 | #include "recptprototools.h"
|
---|
[8182] | 4 |
|
---|
[20589] | 5 |
|
---|
[8337] | 6 | void oaiclassifier::swapColonsAndPeriods(text_t &classifier)
|
---|
| 7 | {
|
---|
[9608] | 8 | for (int i = 1; i <= classifier.size(); ++i) {
|
---|
[8337] | 9 | if (classifier[i] == '.') {
|
---|
| 10 | classifier[i] = ':';
|
---|
| 11 | }
|
---|
| 12 | else if (classifier[i] == ':') {
|
---|
| 13 | classifier[i] = '.';
|
---|
| 14 | }
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | }
|
---|
| 18 |
|
---|
[8182] | 19 | text_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 | }
|
---|
[8219] | 33 | else {
|
---|
| 34 | // Response.docInfo is empty, meaning the doc in question didn't have an oai_id number.
|
---|
[8182] | 35 | return gsdl_id; // Return the empty string to indicate this.
|
---|
[8219] | 36 | }
|
---|
[8182] | 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 | */
|
---|
[22285] | 47 | void oaiclassifier::toOAI(const text_t repos_id, const text_t &collection, text_t &classifier)
|
---|
| 48 | {
|
---|
| 49 |
|
---|
| 50 | text_t tmp = "oai:";
|
---|
| 51 | tmp.append(repos_id);
|
---|
| 52 | tmp.append(":");
|
---|
| 53 | tmp.append(collection);
|
---|
| 54 | toOAI(tmp, classifier);
|
---|
| 55 |
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | /**
|
---|
| 59 | * Called to convert GS classifier/document identifiers that use
|
---|
| 60 | * a '.' to separate levels in the hierarchy into OAI identifiers
|
---|
| 61 | * that use ':' instead.
|
---|
| 62 | */
|
---|
[8182] | 63 | void oaiclassifier::toOAI(const text_t &collection, text_t &classifier)
|
---|
| 64 | {
|
---|
[8337] | 65 | oaiclassifier::swapColonsAndPeriods(classifier);
|
---|
[8182] | 66 |
|
---|
| 67 | // prepend the collection identifier to the beginning of the
|
---|
| 68 | // OAI identifier.
|
---|
| 69 | text_t tmp = collection;
|
---|
| 70 | tmp.append(":");
|
---|
| 71 | tmp.append(classifier);
|
---|
| 72 |
|
---|
| 73 | classifier = tmp;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[22285] | 76 | void oaiclassifier::getCollectionFromOAIID(const text_t oai_id, text_t &collection_id) {
|
---|
| 77 |
|
---|
| 78 | // id is like oai:repos-id:collection:OID, we just want the collection bit
|
---|
| 79 |
|
---|
| 80 | text_t::const_iterator begin = oai_id.begin();
|
---|
| 81 | text_t::const_iterator end = oai_id.end();
|
---|
| 82 | text_t::const_iterator colon = findchar(begin, end, ':'); // 1
|
---|
| 83 | if (colon != end) {
|
---|
| 84 | colon = findchar(colon+1, end, ':'); // 2
|
---|
| 85 | }
|
---|
| 86 | text_t::const_iterator third_colon;
|
---|
| 87 | if (colon !=end) {
|
---|
| 88 | third_colon = findchar(colon+1, end, ':');
|
---|
| 89 | }
|
---|
| 90 | if (third_colon != end) {
|
---|
| 91 | collection_id = substr(colon+1, third_colon);
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[8182] | 95 | /**
|
---|
| 96 | * Called to convert OAI classifier/document identifiers that use
|
---|
| 97 | * a ':' to separate levels in the hierarchy into GS identifiers
|
---|
| 98 | * that use '.' instead.
|
---|
| 99 | */
|
---|
| 100 | void oaiclassifier::toGSDL(text_t &collection, text_t &classifier)
|
---|
| 101 | {
|
---|
[8337] | 102 | oaiclassifier::swapColonsAndPeriods(classifier);
|
---|
[8182] | 103 |
|
---|
| 104 | // separate out the collection identifier that should be
|
---|
| 105 | // found at the beginning of the OAI identifier from the
|
---|
| 106 | // item identifier within the collection
|
---|
| 107 | text_t::iterator colon = find(classifier.begin(), classifier.end(), '.');
|
---|
| 108 | if (colon != classifier.end()) {
|
---|
| 109 | collection = substr(classifier.begin(), colon);
|
---|
| 110 | classifier = substr(colon + 1, classifier.end());
|
---|
| 111 | }
|
---|
| 112 | else{
|
---|
| 113 | collection = classifier;
|
---|
| 114 | classifier = "";
|
---|
| 115 | }
|
---|
| 116 | }
|
---|