1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.app.pager;
17
18 import java.io.Serializable;
19 import java.util.List;
20
21 import org.codelibs.fess.util.ComponentUtil;
22
23 /**
24 * Pager class for request header management in the Fess search engine.
25 * This class provides pagination functionality for displaying and managing
26 * request headers in the administration interface.
27 */
28 public class ReqHeaderPager implements Serializable {
29
30 private static final long serialVersionUID = 1L;
31
32 /**
33 * Default number of records to display per page.
34 */
35 public static final int DEFAULT_PAGE_SIZE = 20;
36
37 /**
38 * Default current page number for pagination.
39 */
40 public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
41
42 /**
43 * The total number of records in the result set.
44 */
45 private int allRecordCount;
46
47 /**
48 * The total number of pages available for pagination.
49 */
50 private int allPageCount;
51
52 /**
53 * Indicates whether a previous page exists for pagination.
54 */
55 private boolean existPrePage;
56
57 /**
58 * Indicates whether a next page exists for pagination.
59 */
60 private boolean existNextPage;
61
62 /**
63 * The list of page numbers to display for pagination navigation.
64 */
65 private List<Integer> pageNumberList;
66
67 /**
68 * The number of records to display per page.
69 */
70 private int pageSize;
71
72 /**
73 * The current page number for pagination.
74 */
75 private int currentPageNumber;
76
77 /**
78 * The unique identifier of the request header.
79 */
80 public String id;
81
82 /**
83 * The name of the request header.
84 */
85 public String name;
86
87 /**
88 * The value of the request header.
89 */
90 public String value;
91
92 /**
93 * The web configuration ID associated with this request header.
94 */
95 public String webConfigId;
96
97 /**
98 * The user who created this request header.
99 */
100 public String createdBy;
101
102 /**
103 * The timestamp when this request header was created.
104 */
105 public String createdTime;
106
107 /**
108 * The version number for optimistic locking.
109 */
110 public String versionNo;
111
112 /**
113 * Default constructor for ReqHeaderPager.
114 * Initializes the pager with default values for page size and current page number.
115 */
116 public ReqHeaderPager() {
117 // Default constructor - initialization handled by field defaults and clear() method
118 }
119
120 /**
121 * Clears all pager data and resets to default values.
122 * This method resets pagination state and clears all request header fields.
123 */
124 public void clear() {
125 allRecordCount = 0;
126 allPageCount = 0;
127 existPrePage = false;
128 existNextPage = false;
129 pageSize = getDefaultPageSize();
130 currentPageNumber = getDefaultCurrentPageNumber();
131
132 id = null;
133 name = null;
134 value = null;
135 webConfigId = null;
136 createdBy = null;
137 createdTime = null;
138 versionNo = null;
139
140 }
141
142 /**
143 * Gets the default current page number.
144 *
145 * @return the default current page number
146 */
147 protected int getDefaultCurrentPageNumber() {
148 return DEFAULT_CURRENT_PAGE_NUMBER;
149 }
150
151 /**
152 * Gets the total number of records in the result set.
153 *
154 * @return the total record count
155 */
156 public int getAllRecordCount() {
157 return allRecordCount;
158 }
159
160 /**
161 * Sets the total number of records in the result set.
162 *
163 * @param allRecordCount the total record count to set
164 */
165 public void setAllRecordCount(final int allRecordCount) {
166 this.allRecordCount = allRecordCount;
167 }
168
169 /**
170 * Gets the total number of pages available for pagination.
171 *
172 * @return the total page count
173 */
174 public int getAllPageCount() {
175 return allPageCount;
176 }
177
178 /**
179 * Sets the total number of pages available for pagination.
180 *
181 * @param allPageCount the total page count to set
182 */
183 public void setAllPageCount(final int allPageCount) {
184 this.allPageCount = allPageCount;
185 }
186
187 /**
188 * Checks if a previous page exists for pagination.
189 *
190 * @return true if a previous page exists, false otherwise
191 */
192 public boolean isExistPrePage() {
193 return existPrePage;
194 }
195
196 /**
197 * Sets the flag indicating whether a previous page exists.
198 *
199 * @param existPrePage true if a previous page exists, false otherwise
200 */
201 public void setExistPrePage(final boolean existPrePage) {
202 this.existPrePage = existPrePage;
203 }
204
205 /**
206 * Checks if a next page exists for pagination.
207 *
208 * @return true if a next page exists, false otherwise
209 */
210 public boolean isExistNextPage() {
211 return existNextPage;
212 }
213
214 /**
215 * Sets the flag indicating whether a next page exists.
216 *
217 * @param existNextPage true if a next page exists, false otherwise
218 */
219 public void setExistNextPage(final boolean existNextPage) {
220 this.existNextPage = existNextPage;
221 }
222
223 /**
224 * Gets the number of records to display per page.
225 * If not set or invalid, returns the default page size.
226 *
227 * @return the page size
228 */
229 public int getPageSize() {
230 if (pageSize <= 0) {
231 pageSize = getDefaultPageSize();
232 }
233 return pageSize;
234 }
235
236 /**
237 * Sets the number of records to display per page.
238 *
239 * @param pageSize the page size to set
240 */
241 public void setPageSize(final int pageSize) {
242 this.pageSize = pageSize;
243 }
244
245 /**
246 * Gets the current page number being displayed.
247 * If not set or invalid, returns the default current page number.
248 *
249 * @return the current page number
250 */
251 public int getCurrentPageNumber() {
252 if (currentPageNumber <= 0) {
253 currentPageNumber = getDefaultCurrentPageNumber();
254 }
255 return currentPageNumber;
256 }
257
258 /**
259 * Sets the current page number being displayed.
260 *
261 * @param currentPageNumber the current page number to set
262 */
263 public void setCurrentPageNumber(final int currentPageNumber) {
264 this.currentPageNumber = currentPageNumber;
265 }
266
267 /**
268 * Gets the list of page numbers for pagination navigation.
269 *
270 * @return the list of page numbers
271 */
272 public List<Integer> getPageNumberList() {
273 return pageNumberList;
274 }
275
276 /**
277 * Sets the list of page numbers for pagination navigation.
278 *
279 * @param pageNumberList the list of page numbers to set
280 */
281 public void setPageNumberList(final List<Integer> pageNumberList) {
282 this.pageNumberList = pageNumberList;
283 }
284
285 /**
286 * Gets the default page size from system configuration.
287 *
288 * @return the default page size
289 */
290 protected int getDefaultPageSize() {
291 return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
292 }
293
294 }