Revision 61781
Added by Michele Artini over 2 years ago
ResumptionTokenImpl.java | ||
---|---|---|
3 | 3 |
import java.util.Arrays; |
4 | 4 |
import java.util.List; |
5 | 5 |
|
6 |
import eu.dnetlib.oai.BadResumptionTokenException; |
|
7 | 6 |
import org.apache.commons.lang3.StringEscapeUtils; |
8 | 7 |
import org.apache.commons.lang3.StringUtils; |
9 | 8 |
|
9 |
import eu.dnetlib.miscutils.functional.hash.Hashing; |
|
10 |
import eu.dnetlib.oai.BadResumptionTokenException; |
|
11 |
|
|
10 | 12 |
public class ResumptionTokenImpl implements ResumptionToken { |
11 | 13 |
|
12 | 14 |
/** |
... | ... | |
44 | 46 |
*/ |
45 | 47 |
@Override |
46 | 48 |
public String serialize() { |
47 |
String escapedQuery = StringEscapeUtils.escapeXml11(query); |
|
48 |
List<String> info = Arrays.asList("" + nMaxElements, metadataPrefix, escapedQuery, "" + nRead, lastObjIdentifier, "" + hasDateRange, requestedSet);
|
|
49 |
return StringUtils.join(info, "|");
|
|
49 |
final String escapedQuery = StringEscapeUtils.escapeXml11(query);
|
|
50 |
final List<String> info =
|
|
51 |
Arrays.asList("" + nMaxElements, metadataPrefix, escapedQuery, "" + nRead, lastObjIdentifier, "" + hasDateRange, requestedSet);
|
|
50 | 52 |
|
53 |
String s = StringUtils.join(info, "|"); |
|
54 |
|
|
55 |
while ((s.length() % 3) != 0) { |
|
56 |
s += " "; // If the length is multiple of 3 the base64 does not contain the padding chars (=) |
|
57 |
} |
|
58 |
|
|
59 |
return Hashing.encodeBase64(s); |
|
51 | 60 |
} |
52 | 61 |
|
53 | 62 |
/** |
... | ... | |
57 | 66 |
*/ |
58 | 67 |
@Override |
59 | 68 |
public void deserialize(final String token) throws BadResumptionTokenException { |
60 |
String[] info = token.split("\\|");
|
|
61 |
if (info.length < 6) throw new BadResumptionTokenException(token);
|
|
62 |
this.nMaxElements = Integer.parseInt(info[0]);
|
|
63 |
this.metadataPrefix = info[1];
|
|
64 |
String unescapedQuery = StringEscapeUtils.unescapeXml(info[2]); |
|
65 |
this.query = unescapedQuery;
|
|
66 |
this.nRead = Integer.parseInt(info[3]);
|
|
67 |
this.lastObjIdentifier = info[4];
|
|
68 |
this.hasDateRange = Boolean.valueOf(info[5]);
|
|
69 |
final String[] info = Hashing.decodeBase64(token).trim().split("\\|");
|
|
70 |
if (info.length < 6) { throw new BadResumptionTokenException(token); }
|
|
71 |
nMaxElements = Integer.parseInt(info[0]); |
|
72 |
metadataPrefix = info[1]; |
|
73 |
final String unescapedQuery = StringEscapeUtils.unescapeXml(info[2]);
|
|
74 |
query = unescapedQuery; |
|
75 |
nRead = Integer.parseInt(info[3]); |
|
76 |
lastObjIdentifier = info[4]; |
|
77 |
hasDateRange = Boolean.valueOf(info[5]); |
|
69 | 78 |
if (info.length == 7) { |
70 |
this.requestedSet = info[6];
|
|
79 |
requestedSet = info[6]; |
|
71 | 80 |
} |
72 | 81 |
} |
73 | 82 |
|
... | ... | |
172 | 181 |
*/ |
173 | 182 |
@Override |
174 | 183 |
public boolean hasDateRange() { |
175 |
return this.hasDateRange;
|
|
184 |
return hasDateRange; |
|
176 | 185 |
} |
177 | 186 |
|
178 | 187 |
/** |
Also available in: Unified diff
resunptionToken in bas64