source: main/tags/2.80/gsdl/src/oaiservr/resumptiontoken.cpp@ 24527

Last change on this file since 24527 was 11760, checked in by davidb, 18 years ago

Minor tweak from 'TRUE' to 'true' (to fix compliation under linux issue).

  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1#include "resumptiontoken.h"
2#include "oaitools.h"
3
4/**
5 * Generate an initial resumption token from some basic details.
6 *
7 * TODO: add optional argument to set the server name.
8 */
9ResumptionToken::ResumptionToken(const text_t &collection, const text_t &node,
10 const text_t &buildDate)
11{ this->collection = collection;
12 this->browseNode = node;
13 this->buildDate = buildDate;
14 this->startItem = 0;
15}
16
17/**
18 * Generate a resumption token from a URN-style format.
19 *
20 * See getToken() for details of the format.
21 *
22 * TODO: support inclusion of an optional server name.
23 */
24ResumptionToken::ResumptionToken(const text_t &URN)
25{ text_t::const_iterator first = URN.begin();
26 text_t::const_iterator last = URN.end();
27 text_t::const_iterator second;
28
29 this->collection = "";
30 this->browseNode = "";
31 this->startItem = -1;
32
33 text_t::const_iterator here = findchar(first, last, ':');
34 if (here == first) {
35 return;
36 }
37
38 text_t oainamespace = substr(first, here);
39 if (oainamespace != "gsdloai") {
40 return;
41 }
42
43 // increment past the first colon to get the location
44 first = ++here;
45
46 // get the collection, browseNode
47 here = findchar(first, last, ',');
48 if (here == last) {
49 return;
50 }
51
52 second = findchar(first, here,'.');
53 this->collection = substr(first, second);
54
55 // cerr << "Collection " << this->collection << endl;
56
57 if (second != here) {
58 this->browseNode = substr(second, here);
59 }
60 else {
61 first = here;
62 }
63 // get past the ','
64 first = ++here;
65
66 // find the second ',' to delimit the position stack
67 second = findchar(first, last, ',');
68
69 // if not found, then get build and start item
70 if (second != first) {
71 // extract list and step past it
72 text_t offsetList = substr(first, second);
73 first = ++second;
74
75 do {
76 second = findchar(offsetList.begin(), offsetList.end(), '.');
77 if (second == offsetList.end())
78 break;
79
80 // extract and push the next position
81 text_t thisPos = substr(offsetList.begin(), second);
82 this->browsePosition.push_back(thisPos.getint());
83
84 // pop the position from the list
85 offsetList = substr(++second, offsetList.end());
86 } while (true);
87 this->browsePosition.push_back(offsetList.getint());
88 }
89 else {
90 first ++;
91 }
92
93 // now find the build date marker
94 here = findchar(first, last, '-');
95 if (here == first) {
96 this->startItem = substr(first, last).getint();
97 }
98 else {
99 this->startItem = substr(first, here).getint();
100 this->buildDate = substr(++here, last);
101 }
102}
103
104/**
105 * Get a resumption token in text_t format.
106 *
107 * Resumption tokens are in the format:
108 *
109 * gsdloai:<serverName>:collectionname.browseNode,startItem-BuildDate
110 *
111 * The resumption token format does not currently implement the use of
112 * the optional <serverName> item; it is taken to default to the name of
113 * the receiving server.
114 *
115 * TODO: add server identity as an optional argument; also change
116 * ResumptionToken(text_t &) accordingly.
117 */
118text_t ResumptionToken::getToken()
119{ text_t reply = "gsdloai:";
120 reply = reply + this->collection;
121 if (this->browseNode != "") {
122 reply = reply + "." + this->browseNode;
123 }
124 reply = reply + ",";
125 for (int i = 0; i < this->browsePosition.size(); i++) {
126 if (i != 0) {
127 reply.append(".");
128 }
129 reply.appendint(i);
130 }
131 reply = reply + ",";
132 reply.append(this->startItem);
133 reply = reply + "-" + buildDate;
134
135 return reply;
136}
137
138/**
139 * Update the position of an existing resumption token
140 */
141void ResumptionToken::setPosition(const text_t &node, int startItem)
142{ this->browseNode = node;
143 this->startItem = startItem;
144}
145
146/**
147 * Check if the resumption token is valid - only a very primitive
148 * check is done here; one ought to check for an existing collection
149 * and valid browse Node, build date and startItem
150 *
151 * TODO: implement improved validation checking.
152 */
153bool ResumptionToken::isValid()
154{ return this->collection != "";
155}
Note: See TracBrowser for help on using the repository browser.