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 for duplicate host management with standard paging functionality.
25 * This class provides pagination support for duplicate host listings in the admin interface,
26 * including navigation controls and search/filter parameters.
27 *
28 * <p>Duplicate hosts allow administrators to define hostname patterns that should
29 * be treated as equivalent during crawling, helping to avoid duplicate content
30 * from the same logical site accessed via different hostnames.</p>
31 */
32 public class DuplicateHostPager implements Serializable {
33
34 private static final long serialVersionUID = 1L;
35
36 /** Default page size for pagination. */
37 public static final int DEFAULT_PAGE_SIZE = 20;
38
39 /** Default current page number (first page). */
40 public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
41
42 /** Total number of records across all pages. */
43 private int allRecordCount;
44
45 /** Total number of pages. */
46 private int allPageCount;
47
48 /** Flag indicating if there is a previous page. */
49 private boolean existPrePage;
50
51 /** Flag indicating if there is a next page. */
52 private boolean existNextPage;
53
54 /** List of page numbers for pagination navigation. */
55 private List<Integer> pageNumberList;
56
57 /** Number of records to display per page. */
58 private int pageSize;
59
60 /** Current page number being displayed. */
61 private int currentPageNumber;
62
63 /** Search/filter parameter for duplicate host configuration ID. */
64 public String id;
65
66 /** Search/filter parameter for regular hostname pattern. */
67 public String regularName;
68
69 /** Search/filter parameter for duplicate hostname pattern. */
70 public String duplicateHostName;
71
72 /** Search/filter parameter for duplicate host sort order. */
73 public String sortOrder;
74
75 /** Search/filter parameter for duplicate host creator. */
76 public String createdBy;
77
78 /** Search/filter parameter for duplicate host creation time. */
79 public String createdTime;
80
81 /** Search/filter parameter for duplicate host version number. */
82 public String versionNo;
83
84 /**
85 * Creates a new DuplicateHostPager with default values.
86 * Initializes pagination settings and clears all search parameters.
87 */
88 public DuplicateHostPager() {
89 // Default constructor with explicit documentation
90 }
91
92 /**
93 * Clears all paging state and search/filter parameters.
94 * Resets the pager to its initial state with default values.
95 */
96 public void clear() {
97 allRecordCount = 0;
98 allPageCount = 0;
99 existPrePage = false;
100 existNextPage = false;
101 pageSize = getDefaultPageSize();
102 currentPageNumber = getDefaultCurrentPageNumber();
103
104 id = null;
105 regularName = null;
106 duplicateHostName = null;
107 sortOrder = null;
108 createdBy = null;
109 createdTime = null;
110 versionNo = null;
111
112 }
113
114 /**
115 * Returns the default current page number.
116 *
117 * @return the default current page number (1)
118 */
119 protected int getDefaultCurrentPageNumber() {
120 return DEFAULT_CURRENT_PAGE_NUMBER;
121 }
122
123 /**
124 * Gets the total number of records across all pages.
125 *
126 * @return the total record count
127 */
128 public int getAllRecordCount() {
129 return allRecordCount;
130 }
131
132 /**
133 * Sets the total number of records across all pages.
134 *
135 * @param allRecordCount the total record count
136 */
137 public void setAllRecordCount(final int allRecordCount) {
138 this.allRecordCount = allRecordCount;
139 }
140
141 /**
142 * Gets the total number of pages.
143 *
144 * @return the total page count
145 */
146 public int getAllPageCount() {
147 return allPageCount;
148 }
149
150 /**
151 * Sets the total number of pages.
152 *
153 * @param allPageCount the total page count
154 */
155 public void setAllPageCount(final int allPageCount) {
156 this.allPageCount = allPageCount;
157 }
158
159 /**
160 * Checks if there is a previous page available.
161 *
162 * @return true if there is a previous page, false otherwise
163 */
164 public boolean isExistPrePage() {
165 return existPrePage;
166 }
167
168 /**
169 * Sets whether there is a previous page available.
170 *
171 * @param existPrePage true if there is a previous page, false otherwise
172 */
173 public void setExistPrePage(final boolean existPrePage) {
174 this.existPrePage = existPrePage;
175 }
176
177 /**
178 * Checks if there is a next page available.
179 *
180 * @return true if there is a next page, false otherwise
181 */
182 public boolean isExistNextPage() {
183 return existNextPage;
184 }
185
186 /**
187 * Sets whether there is a next page available.
188 *
189 * @param existNextPage true if there is a next page, false otherwise
190 */
191 public void setExistNextPage(final boolean existNextPage) {
192 this.existNextPage = existNextPage;
193 }
194
195 /**
196 * Gets the number of records to display per page.
197 * If the page size is not set or is invalid, returns the default page size.
198 *
199 * @return the page size
200 */
201 public int getPageSize() {
202 if (pageSize <= 0) {
203 pageSize = getDefaultPageSize();
204 }
205 return pageSize;
206 }
207
208 /**
209 * Sets the number of records to display per page.
210 *
211 * @param pageSize the page size
212 */
213 public void setPageSize(final int pageSize) {
214 this.pageSize = pageSize;
215 }
216
217 /**
218 * Gets the current page number being displayed.
219 * If the current page number is not set or is invalid, returns the default page number.
220 *
221 * @return the current page number
222 */
223 public int getCurrentPageNumber() {
224 if (currentPageNumber <= 0) {
225 currentPageNumber = getDefaultCurrentPageNumber();
226 }
227 return currentPageNumber;
228 }
229
230 /**
231 * Sets the current page number being displayed.
232 *
233 * @param currentPageNumber the current page number
234 */
235 public void setCurrentPageNumber(final int currentPageNumber) {
236 this.currentPageNumber = currentPageNumber;
237 }
238
239 /**
240 * Gets the list of page numbers for pagination navigation.
241 *
242 * @return the list of page numbers
243 */
244 public List<Integer> getPageNumberList() {
245 return pageNumberList;
246 }
247
248 /**
249 * Sets the list of page numbers for pagination navigation.
250 *
251 * @param pageNumberList the list of page numbers
252 */
253 public void setPageNumberList(final List<Integer> pageNumberList) {
254 this.pageNumberList = pageNumberList;
255 }
256
257 /**
258 * Returns the default page size from the system configuration.
259 *
260 * @return the default page size configured in the system
261 */
262 protected int getDefaultPageSize() {
263 return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
264 }
265
266 }