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 class for bad word management with pagination support.
25   * Provides pagination functionality for bad word lists.
26   */
27  public class BadWordPager implements Serializable {
28  
29      private static final long serialVersionUID = 1L;
30  
31      /** Default page size for bad word pagination. */
32      public static final int DEFAULT_PAGE_SIZE = 20;
33  
34      /** Default current page number. */
35      public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
36  
37      /**
38       * The total number of records available.
39       */
40      private int allRecordCount;
41  
42      /**
43       * The total number of pages available.
44       */
45      private int allPageCount;
46  
47      /**
48       * Whether a previous page exists.
49       */
50      private boolean existPrePage;
51  
52      /**
53       * Whether a next page exists.
54       */
55      private boolean existNextPage;
56  
57      /**
58       * The list of page numbers for navigation.
59       */
60      private List<Integer> pageNumberList;
61  
62      /**
63       * The number of records per page.
64       */
65      private int pageSize;
66  
67      /**
68       * The current page number.
69       */
70      private int currentPageNumber;
71  
72      /** Bad word ID for search filtering. */
73      public String id;
74  
75      /** Suggest word for search filtering. */
76      public String suggestWord;
77  
78      /** Creator username for search filtering. */
79      public String createdBy;
80  
81      /** Creation time for search filtering. */
82      public String createdTime;
83  
84      /** Version number for search filtering. */
85      public String versionNo;
86  
87      /**
88       * Default constructor for BadWordPager.
89       */
90      public BadWordPager() {
91          // Default constructor
92      }
93  
94      /**
95       * Clears all search criteria and resets pagination settings.
96       */
97      public void clear() {
98          allRecordCount = 0;
99          allPageCount = 0;
100         existPrePage = false;
101         existNextPage = false;
102         pageSize = getDefaultPageSize();
103         currentPageNumber = getDefaultCurrentPageNumber();
104 
105         id = null;
106         suggestWord = null;
107         createdBy = null;
108         createdTime = null;
109         versionNo = null;
110 
111     }
112 
113     /**
114      * Gets the default current page number.
115      * @return The default current page number.
116      */
117     protected int getDefaultCurrentPageNumber() {
118         return DEFAULT_CURRENT_PAGE_NUMBER;
119     }
120 
121     /**
122      * Gets the total number of records.
123      * @return The total record count.
124      */
125     public int getAllRecordCount() {
126         return allRecordCount;
127     }
128 
129     /**
130      * Sets the total number of records.
131      * @param allRecordCount The total record count.
132      */
133     public void setAllRecordCount(final int allRecordCount) {
134         this.allRecordCount = allRecordCount;
135     }
136 
137     /**
138      * Gets the total number of pages.
139      * @return The total page count.
140      */
141     public int getAllPageCount() {
142         return allPageCount;
143     }
144 
145     /**
146      * Sets the total number of pages.
147      * @param allPageCount The total page count.
148      */
149     public void setAllPageCount(final int allPageCount) {
150         this.allPageCount = allPageCount;
151     }
152 
153     /**
154      * Checks if there is a previous page.
155      * @return True if a previous page exists, false otherwise.
156      */
157     public boolean isExistPrePage() {
158         return existPrePage;
159     }
160 
161     /**
162      * Sets the existence of a previous page.
163      * @param existPrePage True if a previous page exists.
164      */
165     public void setExistPrePage(final boolean existPrePage) {
166         this.existPrePage = existPrePage;
167     }
168 
169     /**
170      * Checks if there is a next page.
171      * @return True if a next page exists, false otherwise.
172      */
173     public boolean isExistNextPage() {
174         return existNextPage;
175     }
176 
177     /**
178      * Sets the existence of a next page.
179      * @param existNextPage True if a next page exists.
180      */
181     public void setExistNextPage(final boolean existNextPage) {
182         this.existNextPage = existNextPage;
183     }
184 
185     /**
186      * Gets the page size for pagination.
187      * @return The page size.
188      */
189     public int getPageSize() {
190         if (pageSize <= 0) {
191             pageSize = getDefaultPageSize();
192         }
193         return pageSize;
194     }
195 
196     /**
197      * Sets the page size for pagination.
198      * @param pageSize The page size.
199      */
200     public void setPageSize(final int pageSize) {
201         this.pageSize = pageSize;
202     }
203 
204     /**
205      * Gets the current page number.
206      * @return The current page number.
207      */
208     public int getCurrentPageNumber() {
209         if (currentPageNumber <= 0) {
210             currentPageNumber = getDefaultCurrentPageNumber();
211         }
212         return currentPageNumber;
213     }
214 
215     /**
216      * Sets the current page number.
217      * @param currentPageNumber The current page number.
218      */
219     public void setCurrentPageNumber(final int currentPageNumber) {
220         this.currentPageNumber = currentPageNumber;
221     }
222 
223     /**
224      * Gets the list of page numbers for pagination navigation.
225      * @return The list of page numbers.
226      */
227     public List<Integer> getPageNumberList() {
228         return pageNumberList;
229     }
230 
231     /**
232      * Sets the list of page numbers for pagination navigation.
233      * @param pageNumberList The list of page numbers.
234      */
235     public void setPageNumberList(final List<Integer> pageNumberList) {
236         this.pageNumberList = pageNumberList;
237     }
238 
239     /**
240      * Gets the default page size from configuration.
241      * @return The default page size.
242      */
243     protected int getDefaultPageSize() {
244         return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
245     }
246 
247 }