View Javadoc
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 implementation for crawling information pagination.
25   * Provides functionality for paginating crawling information results in the admin interface.
26   */
27  public class CrawlingInfoPager implements Serializable {
28  
29      /**
30       * Creates a new pager instance with default settings.
31       */
32      public CrawlingInfoPager() {
33          // Default constructor
34      }
35  
36      private static final long serialVersionUID = 1L;
37  
38      /**
39       * Default page size for pagination.
40       */
41      public static final int DEFAULT_PAGE_SIZE = 20;
42  
43      /**
44       * Default current page number (1-based).
45       */
46      public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
47  
48      /**
49       * The total number of records across all pages.
50       */
51      private int allRecordCount;
52  
53      /**
54       * The total number of pages available.
55       */
56      private int allPageCount;
57  
58      /**
59       * Indicates whether a previous page exists before the current page.
60       */
61      private boolean existPrePage;
62  
63      /**
64       * Indicates whether a next page exists after the current page.
65       */
66      private boolean existNextPage;
67  
68      /**
69       * The list of page numbers to display in the pagination component.
70       */
71      private List<Integer> pageNumberList;
72  
73      /**
74       * The number of records to display per page.
75       */
76      private int pageSize;
77  
78      /**
79       * The current page number (1-based) for pagination.
80       */
81      private int currentPageNumber;
82  
83      /**
84       * Crawling information ID.
85       */
86      public String id;
87  
88      /**
89       * Session ID for the crawling session.
90       */
91      public String sessionId;
92  
93      /**
94       * Creation time of the crawling information.
95       */
96      public String createdTime;
97  
98      /**
99       * Clears all pagination state and crawling information fields.
100      * Resets all counts, page flags, and crawling-specific fields to their default values.
101      */
102     public void clear() {
103         allRecordCount = 0;
104         allPageCount = 0;
105         existPrePage = false;
106         existNextPage = false;
107         pageSize = getDefaultPageSize();
108         currentPageNumber = getDefaultCurrentPageNumber();
109 
110         id = null;
111         sessionId = null;
112         createdTime = null;
113 
114     }
115 
116     /**
117      * Gets the default current page number.
118      *
119      * @return the default current page number (1)
120      */
121     protected int getDefaultCurrentPageNumber() {
122         return DEFAULT_CURRENT_PAGE_NUMBER;
123     }
124 
125     /**
126      * Gets the total number of records across all pages.
127      *
128      * @return the total record count
129      */
130     public int getAllRecordCount() {
131         return allRecordCount;
132     }
133 
134     /**
135      * Sets the total number of records across all pages.
136      *
137      * @param allRecordCount the total record count to set
138      */
139     public void setAllRecordCount(final int allRecordCount) {
140         this.allRecordCount = allRecordCount;
141     }
142 
143     /**
144      * Gets the total number of pages available.
145      *
146      * @return the total page count
147      */
148     public int getAllPageCount() {
149         return allPageCount;
150     }
151 
152     /**
153      * Sets the total number of pages available.
154      *
155      * @param allPageCount the total page count to set
156      */
157     public void setAllPageCount(final int allPageCount) {
158         this.allPageCount = allPageCount;
159     }
160 
161     /**
162      * Checks if a previous page exists before the current page.
163      *
164      * @return true if a previous page exists, false otherwise
165      */
166     public boolean isExistPrePage() {
167         return existPrePage;
168     }
169 
170     /**
171      * Sets whether a previous page exists before the current page.
172      *
173      * @param existPrePage true if a previous page exists, false otherwise
174      */
175     public void setExistPrePage(final boolean existPrePage) {
176         this.existPrePage = existPrePage;
177     }
178 
179     /**
180      * Checks if a next page exists after the current page.
181      *
182      * @return true if a next page exists, false otherwise
183      */
184     public boolean isExistNextPage() {
185         return existNextPage;
186     }
187 
188     /**
189      * Sets whether a next page exists after the current page.
190      *
191      * @param existNextPage true if a next page exists, false otherwise
192      */
193     public void setExistNextPage(final boolean existNextPage) {
194         this.existNextPage = existNextPage;
195     }
196 
197     /**
198      * Gets the number of records to display per page.
199      * If the page size is not set or is invalid (≤0), returns the default page size.
200      *
201      * @return the page size
202      */
203     public int getPageSize() {
204         if (pageSize <= 0) {
205             pageSize = getDefaultPageSize();
206         }
207         return pageSize;
208     }
209 
210     /**
211      * Sets the number of records to display per page.
212      *
213      * @param pageSize the page size to set
214      */
215     public void setPageSize(final int pageSize) {
216         this.pageSize = pageSize;
217     }
218 
219     /**
220      * Gets the current page number (1-based).
221      * If the current page number is not set or is invalid (≤0), returns the default page number.
222      *
223      * @return the current page number
224      */
225     public int getCurrentPageNumber() {
226         if (currentPageNumber <= 0) {
227             currentPageNumber = getDefaultCurrentPageNumber();
228         }
229         return currentPageNumber;
230     }
231 
232     /**
233      * Sets the current page number (1-based).
234      *
235      * @param currentPageNumber the current page number to set
236      */
237     public void setCurrentPageNumber(final int currentPageNumber) {
238         this.currentPageNumber = currentPageNumber;
239     }
240 
241     /**
242      * Gets the list of page numbers to display in the pagination component.
243      *
244      * @return the list of page numbers, or null if not set
245      */
246     public List<Integer> getPageNumberList() {
247         return pageNumberList;
248     }
249 
250     /**
251      * Sets the list of page numbers to display in the pagination component.
252      *
253      * @param pageNumberList the list of page numbers to set
254      */
255     public void setPageNumberList(final List<Integer> pageNumberList) {
256         this.pageNumberList = pageNumberList;
257     }
258 
259     /**
260      * Gets the default page size from the Fess configuration.
261      *
262      * @return the default page size configured in the system
263      */
264     protected int getDefaultPageSize() {
265         return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
266     }
267 
268 }