[22739] | 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 |
|
---|
[8182] | 27 | #include "resumptiontoken.h"
|
---|
| 28 |
|
---|
[20590] | 29 |
|
---|
| 30 | ResumptionToken::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;
|
---|
[8182] | 40 | }
|
---|
| 41 |
|
---|
| 42 |
|
---|
[20590] | 43 | ResumptionToken::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 = "";
|
---|
[8182] | 51 |
|
---|
[20625] | 52 | // This uses custom code instead of the text_t splitchar() function because that is buggy
|
---|
[20590] | 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 | }
|
---|
[8182] | 67 |
|
---|
[20590] | 68 | resumption_token_string_iterator++;
|
---|
[8182] | 69 | }
|
---|
[20590] | 70 | resumption_token_string_parts.push_back(resumption_token_string_part);
|
---|
[8182] | 71 |
|
---|
[20590] | 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;
|
---|
[11732] | 77 | }
|
---|
[8182] | 78 |
|
---|
[20590] | 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;
|
---|
[8182] | 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
[20590] | 89 | text_t ResumptionToken::getResumptionTokenString()
|
---|
| 90 | {
|
---|
| 91 | return this->build_date + "," + this->set + "," + this->metadata_prefix + "," + this->from + "," + this->until + "," + this->position;
|
---|
[8182] | 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | bool ResumptionToken::isValid()
|
---|
[20590] | 96 | {
|
---|
| 97 | return this->valid;
|
---|
[8182] | 98 | }
|
---|