#include "oaitools.h" #include #include "OIDtools.h" void oaiclassifier::swapColonsAndPeriods(text_t &classifier) { for (int i = 1; i <= classifier.size(); ++i) { if (classifier[i] == '.') { classifier[i] = ':'; } else if (classifier[i] == ':') { classifier[i] = '.'; } } } text_t oaiclassifier::getGSDL_OID(const text_t &collection, const text_t& oai_id, recptproto *protocol, ostream &logout) { FilterResponse_t response; text_tset metadata; // metadata.insert("gsdl_id"); bool status_ok = get_children(oai_id, collection, "", metadata, false, protocol, response, logout); text_t gsdl_id = ""; if (status_ok) { if(response.docInfo.size() > 0){ gsdl_id = response.docInfo[0].OID; } else { // Response.docInfo is empty, meaning the doc in question didn't have an oai_id number. return gsdl_id; // Return the empty string to indicate this. } } return gsdl_id; } /** * Called to convert GS classifier/document identifiers that use * a '.' to separate levels in the hierarchy into OAI identifiers * that use ':' instead. */ void oaiclassifier::toOAI(const text_t &collection, text_t &classifier) { oaiclassifier::swapColonsAndPeriods(classifier); // prepend the collection identifier to the beginning of the // OAI identifier. text_t tmp = collection; tmp.append(":"); tmp.append(classifier); classifier = tmp; } /** * Called to convert OAI classifier/document identifiers that use * a ':' to separate levels in the hierarchy into GS identifiers * that use '.' instead. */ void oaiclassifier::toGSDL(text_t &collection, text_t &classifier) { oaiclassifier::swapColonsAndPeriods(classifier); // separate out the collection identifier that should be // found at the beginning of the OAI identifier from the // item identifier within the collection text_t::iterator colon = find(classifier.begin(), classifier.end(), '.'); if (colon != classifier.end()) { collection = substr(classifier.begin(), colon); classifier = substr(colon + 1, classifier.end()); } else{ collection = classifier; classifier = ""; } }