root/main/trunk/greenstone2/runtime-src/src/oaiservr/resumptiontoken.cpp @ 22739

Revision 22739, 3.2 KB (checked in by mdewsnip, 9 years ago)

Added copyright header to runtime-src/src/oaiserver/*.cpp and runtime-src/src/oaiserver/*.h.

  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 * resumptiontoken.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 "resumptiontoken.h"
28
29
30ResumptionToken::ResumptionToken(const text_t &build_date, const text_t &set, const text_t &metadata_prefix,
31                 const text_t &from, const text_t &until, const text_t &position)
32{
33  this->build_date = build_date;
34  this->set = set;
35  this->metadata_prefix = metadata_prefix;
36  this->from = from;
37  this->until = until;
38  this->position = position;
39  this->valid = true;
40}
41
42
43ResumptionToken::ResumptionToken(const text_t &resumption_token_string)
44{
45  this->build_date = "";
46  this->set = "";
47  this->metadata_prefix = "";
48  this->from = "";
49  this->until = "";
50  this->position = "";
51
52  // This uses custom code instead of the text_t splitchar() function because that is buggy
53  text_tarray resumption_token_string_parts;
54  text_t resumption_token_string_part;
55  text_t::const_iterator resumption_token_string_iterator = resumption_token_string.begin();
56  while (resumption_token_string_iterator != resumption_token_string.end())
57  {
58    if (*resumption_token_string_iterator == ',')
59    {
60      resumption_token_string_parts.push_back(resumption_token_string_part);
61      resumption_token_string_part.clear();
62    }
63    else
64    {
65      resumption_token_string_part.push_back(*resumption_token_string_iterator);
66    }
67
68    resumption_token_string_iterator++;
69  }
70  resumption_token_string_parts.push_back(resumption_token_string_part);
71
72  if (resumption_token_string_parts.size() != 6)
73  {
74    // The resumption token is invalid -- there should be exactly 6 parts
75    this->valid = false;
76    return;
77  }
78
79  this->build_date = resumption_token_string_parts[0];
80  this->set = resumption_token_string_parts[1];
81  this->metadata_prefix = resumption_token_string_parts[2];
82  this->from = resumption_token_string_parts[3];
83  this->until = resumption_token_string_parts[4];
84  this->position = resumption_token_string_parts[5];
85  this->valid = true;
86}
87
88
89text_t ResumptionToken::getResumptionTokenString()
90{
91  return this->build_date + "," + this->set + "," + this->metadata_prefix + "," + this->from + "," + this->until + "," + this->position;
92}
93
94
95bool ResumptionToken::isValid()
96{
97  return this->valid;
98}
Note: See TracBrowser for help on using the browser.