1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * oaitools.cpp --
|
---|
4 | *
|
---|
5 | * Copyright (C) 2004-2010 The New Zealand Digital Library Project
|
---|
6 | *
|
---|
7 | * A component of the Greenstone digital library software
|
---|
8 | * from the New Zealand Digital Library Project at the
|
---|
9 | * University of Waikato, New Zealand.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | *
|
---|
25 | *********************************************************************/
|
---|
26 |
|
---|
27 | #include "oaitools.h"
|
---|
28 |
|
---|
29 | #include "recptprototools.h"
|
---|
30 |
|
---|
31 |
|
---|
32 | void oaiclassifier::swapColonsAndPeriods(text_t &classifier)
|
---|
33 | {
|
---|
34 | for (int i = 0; i < classifier.size(); ++i) {
|
---|
35 | if (classifier[i] == '.') {
|
---|
36 | classifier[i] = ':';
|
---|
37 | }
|
---|
38 | else if (classifier[i] == ':') {
|
---|
39 | classifier[i] = '.';
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | text_t oaiclassifier::getGSDL_OID(const text_t &collection, const text_t& oai_id,
|
---|
46 | recptproto *protocol, ostream &logout)
|
---|
47 | {
|
---|
48 | FilterResponse_t response;
|
---|
49 | text_tset metadata;
|
---|
50 |
|
---|
51 | // metadata.insert("gsdl_id");
|
---|
52 |
|
---|
53 | bool status_ok = get_children(oai_id, collection, "", metadata, false, protocol, response, logout);
|
---|
54 | // OLD: gets the ID in the 'contains' field of the index_db for OID key of type [oai.x] where x is numeric
|
---|
55 | // Now we check the etc/oai-inf.<db> instead.
|
---|
56 | text_t gsdl_id = "";
|
---|
57 | if (status_ok) {
|
---|
58 | if(response.docInfo.size() > 0){
|
---|
59 | gsdl_id = response.docInfo[0].OID;
|
---|
60 | }
|
---|
61 | else {
|
---|
62 | // Response.docInfo is empty, meaning the doc in question didn't have an oai_id number.
|
---|
63 | return gsdl_id; // Return the empty string to indicate this.
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | return gsdl_id;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Called to convert GS classifier/document identifiers that use
|
---|
72 | * a '.' to separate levels in the hierarchy into OAI identifiers
|
---|
73 | * that use ':' instead.
|
---|
74 | */
|
---|
75 | void oaiclassifier::toOAI(const text_t repos_id, const text_t &collection, text_t &classifier)
|
---|
76 | {
|
---|
77 |
|
---|
78 | text_t tmp = "oai:";
|
---|
79 | tmp.append(repos_id);
|
---|
80 | tmp.append(":");
|
---|
81 | tmp.append(collection);
|
---|
82 | toOAI(tmp, classifier);
|
---|
83 |
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Called to convert GS classifier/document identifiers that use
|
---|
88 | * a '.' to separate levels in the hierarchy into OAI identifiers
|
---|
89 | * that use ':' instead.
|
---|
90 | */
|
---|
91 | void oaiclassifier::toOAI(const text_t &collection, text_t &classifier)
|
---|
92 | {
|
---|
93 | oaiclassifier::swapColonsAndPeriods(classifier);
|
---|
94 |
|
---|
95 | // prepend the collection identifier to the beginning of the
|
---|
96 | // OAI identifier.
|
---|
97 | text_t tmp = collection;
|
---|
98 | tmp.append(":");
|
---|
99 | tmp.append(classifier);
|
---|
100 |
|
---|
101 | classifier = tmp;
|
---|
102 | }
|
---|
103 |
|
---|
104 | void oaiclassifier::getCollectionFromOAIID(const text_t oai_id, text_t &collection_id) {
|
---|
105 |
|
---|
106 | // id is like oai:repos-id:collection:OID, we just want the collection bit
|
---|
107 |
|
---|
108 | text_t::const_iterator begin = oai_id.begin();
|
---|
109 | text_t::const_iterator end = oai_id.end();
|
---|
110 | text_t::const_iterator colon = findchar(begin, end, ':'); // 1
|
---|
111 | if (colon != end) {
|
---|
112 | colon = findchar(colon+1, end, ':'); // 2
|
---|
113 | }
|
---|
114 | text_t::const_iterator third_colon;
|
---|
115 | if (colon !=end) {
|
---|
116 | third_colon = findchar(colon+1, end, ':');
|
---|
117 | }
|
---|
118 | if (third_colon != end) {
|
---|
119 | collection_id = substr(colon+1, third_colon);
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Called to convert OAI classifier/document identifiers that use
|
---|
125 | * a ':' to separate levels in the hierarchy into GS identifiers
|
---|
126 | * that use '.' instead.
|
---|
127 | */
|
---|
128 | void oaiclassifier::toGSDL(text_t &collection, text_t &classifier)
|
---|
129 | {
|
---|
130 | oaiclassifier::swapColonsAndPeriods(classifier);
|
---|
131 |
|
---|
132 | // separate out the collection identifier that should be
|
---|
133 | // found at the beginning of the OAI identifier from the
|
---|
134 | // item identifier within the collection
|
---|
135 | text_t::iterator colon = find(classifier.begin(), classifier.end(), '.');
|
---|
136 | if (colon != classifier.end()) {
|
---|
137 | collection = substr(classifier.begin(), colon);
|
---|
138 | classifier = substr(colon + 1, classifier.end());
|
---|
139 | }
|
---|
140 | else{
|
---|
141 | collection = classifier;
|
---|
142 | classifier = "";
|
---|
143 | }
|
---|
144 | }
|
---|