Pagination.java
3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.searchpromote.xml.result;
import com.day.cq.searchpromote.xml.result.AbstractResultEntity;
import com.day.cq.searchpromote.xml.result.PageList;
import com.day.cq.searchpromote.xml.result.ResultPage;
import com.day.cq.searchpromote.xml.result.ResultParser;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Pagination
extends AbstractResultEntity {
private static final Logger LOG = LoggerFactory.getLogger(Pagination.class);
private static final String TOTAL_PAGES_NODE = "total-pages";
private static final String PAGES_NODE = "pages";
private Long totalPages;
private PageList pageList;
@Override
public void parse(XMLEventReader reader) throws Exception {
XMLEvent event;
LOG.debug("Parsing pagination information");
while (reader.hasNext() && !(event = ResultParser.getNextEvent(reader)).isEndElement()) {
StartElement startElement = event.asStartElement();
String localPart = startElement.getName().getLocalPart();
LOG.debug("Parsing node {}", (Object)localPart);
if (localPart.equals("total-pages")) {
this.totalPages = Long.parseLong(this.readData(reader));
ResultParser.getNextEvent(reader);
continue;
}
if (localPart.equals("pages")) {
this.pageList = new PageList();
this.pageList.parse(reader);
continue;
}
ResultParser.parseUnknownTag(reader);
}
}
public Long getTotalPages() {
return this.totalPages;
}
public List<ResultPage> getResultPages() {
ArrayList<ResultPage> pages = new ArrayList<ResultPage>();
for (ResultPage p : this.pageList.getPages()) {
if (!p.getPosition().matches("\\d+")) continue;
pages.add(p);
}
return pages;
}
public ResultPage getFirst() {
return this.get("first");
}
public ResultPage getLast() {
return this.get("last");
}
public ResultPage getPrevious() {
return this.get("previous");
}
public ResultPage getNext() {
return this.get("next");
}
public ResultPage getViewall() {
return this.get("viewall");
}
public Boolean hasNext() {
return this.checkFor("next");
}
public Boolean hasPrevious() {
return this.checkFor("previous");
}
public Boolean hasFirst() {
return this.checkFor("first");
}
public Boolean hasLast() {
return this.checkFor("last");
}
public Boolean hasViewall() {
return this.checkFor("viewall");
}
public Integer getSize() {
return this.pageList.getPages().size();
}
private ResultPage get(String position) {
for (ResultPage p : this.pageList.getPages()) {
if (!position.equalsIgnoreCase(p.getPosition())) continue;
return p;
}
return null;
}
private Boolean checkFor(String position) {
return this.get(position) != null;
}
}