1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.services.wcm.search.base;
18
19 import java.util.Comparator;
20 import java.util.List;
21
22 import org.exoplatform.commons.exception.ExoMessageException;
23 import org.exoplatform.commons.utils.PageList;
24 import org.exoplatform.services.log.ExoLogger;
25 import org.exoplatform.services.log.Log;
26
27
28
29
30
31
32
33 @SuppressWarnings("deprecation")
34 public abstract class AbstractPageList<E> extends PageList<E> {
35
36 public static final int DEFAULT_PAGE_SIZE = 10;
37
38 public static final int DEAFAULT_BUFFER_SIZE = 100;
39
40 public static final int RESULT_SIZE_SEPARATOR = 100;
41
42 private static final Log LOG = ExoLogger.getLogger(AbstractPageList.class.getName());
43
44
45 protected String spellSuggestion;
46
47 protected long queryTime;
48
49 protected NodeSearchFilter filter;
50
51 protected SearchDataCreator<E> searchDataCreator;
52
53 protected Comparator<E> comparator;
54
55 protected String sortByField;
56
57 protected String order;
58
59 protected int offset_;
60
61 protected boolean loadedAllData_ = true;
62
63 public Comparator<E> getComparator() {
64 return comparator;
65 }
66
67 public void setComparator(Comparator<E> comparator) {
68 this.comparator = comparator;
69 }
70
71 public String getSortByField() {
72 return sortByField;
73 }
74
75 public void setSortByField(String sortByField) {
76 this.sortByField = sortByField;
77 }
78
79 public String getOrder() {
80 return order;
81 }
82
83 public void setOrder(String order) {
84 this.order = order;
85 }
86
87
88 public AbstractPageList(int pageSize) {
89 super(pageSize);
90 }
91
92
93 public AbstractPageList(int pageSize, NodeSearchFilter filter, SearchDataCreator<E> creator) {
94 this(pageSize);
95 this.filter = filter;
96 this.searchDataCreator = creator;
97 }
98
99 public String getSpellSuggestion() {
100 return spellSuggestion;
101 }
102
103 public void setSpellSuggestion(String spellSuggestion) {
104 this.spellSuggestion = spellSuggestion;
105 }
106
107 public long getQueryTime() {
108 return queryTime;
109 }
110
111 public void setQueryTime(long queryTime) {
112 this.queryTime = queryTime;
113 }
114
115 public NodeSearchFilter getFilter() {
116 return filter;
117 }
118
119 public void setFilter(NodeSearchFilter filter) {
120 this.filter = filter;
121 }
122
123 public SearchDataCreator<E> getSearchDataCreator() {
124 return searchDataCreator;
125 }
126
127 public void setSearchDataCreator(SearchDataCreator<E> searchDataCreator) {
128 this.searchDataCreator = searchDataCreator;
129 }
130
131 @SuppressWarnings("unchecked")
132 public List currentPage() throws Exception
133 {
134 populateCurrentPage(currentPage_);
135 return currentListPage_;
136 }
137
138 @Override
139 protected void checkAndSetPage(int page) throws Exception
140 {
141 currentPage_ = page;
142 if (page < 1 || page > availablePage_ + offset_/getPageSize())
143 {
144 Object[] args = {Integer.toString(page), Integer.toString(availablePage_)};
145 throw new ExoMessageException("PageList.page-out-of-range", args);
146 }
147 }
148
149
150 public abstract void sortData();
151
152 public abstract List<E> getPageWithOffsetCare(int page) throws Exception;
153
154 protected void removeRedundantPages(int availablePage) {
155 for (int i = 1; i < Math.min(availablePage, this.getAvailablePage()); i++) {
156 try {
157 int currentPageSize = this.getPage(i).size();
158 if (currentPageSize == 0) {
159 this.setAvailablePage((i-1)*this.getPageSize());
160 break;
161 }
162 if (currentPageSize < this.getPageSize()) {
163 this.setAvailablePage(i*this.getPageSize());
164 break;
165 }
166 } catch (Exception e) {
167 if (LOG.isWarnEnabled()) {
168 LOG.warn("Error in getPage.", e);
169 }
170 }
171 }
172 try {
173 getPageWithOffsetCare(1);
174 } catch (Exception e) {
175 if (LOG.isWarnEnabled()) {
176 LOG.warn("Error in getPageWithOffsetCare.", e);
177 }
178 }
179 }
180
181 public boolean loadedAllData() {
182 return loadedAllData_;
183 }
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210 }