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 for protected words dictionary management.
25   * This class handles pagination functionality for browsing protected words.
26   */
27  public class ProtwordsPager implements Serializable {
28  
29      /**
30       * Default constructor.
31       */
32      public ProtwordsPager() {
33          // Default constructor
34      }
35  
36      private static final long serialVersionUID = 1L;
37  
38      /** The total number of records. */
39      private int allRecordCount;
40  
41      /**
42       * The total number of pages.
43       */
44      private int allPageCount;
45  
46      /** Whether a previous page exists. */
47      private boolean existPrePage;
48  
49      /** Whether a next page exists. */
50      private boolean existNextPage;
51  
52      /** The list of page numbers for pagination display. */
53      private List<Integer> pageNumberList;
54  
55      /** The number of items to display per page. */
56      private int pageSize;
57  
58      /** The current page number. */
59      private int currentPageNumber;
60  
61      /** The dictionary ID */
62      public String id;
63  
64      /**
65       * Clears all pagination data and resets to default values.
66       */
67      public void clear() {
68          allRecordCount = 0;
69          allPageCount = 0;
70          existPrePage = false;
71          existNextPage = false;
72          pageSize = getDefaultPageSize();
73          currentPageNumber = getDefaultCurrentPageNumber();
74  
75          id = null;
76      }
77  
78      /**
79       * Gets the default page size from configuration.
80       * @return the default page size
81       */
82      protected int getDefaultPageSize() {
83          return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
84      }
85  
86      /**
87       * Gets the default current page number.
88       * @return the default current page number (1)
89       */
90      protected int getDefaultCurrentPageNumber() {
91          return 1;
92      }
93  
94      /**
95       * Gets the total number of records.
96       * @return the total record count
97       */
98      public int getAllRecordCount() {
99          return allRecordCount;
100     }
101 
102     /**
103      * Sets the total number of records.
104      * @param allRecordCount the total record count
105      */
106     public void setAllRecordCount(final int allRecordCount) {
107         this.allRecordCount = allRecordCount;
108     }
109 
110     /**
111      * Gets the total number of pages.
112      * @return the total page count
113      */
114     public int getAllPageCount() {
115         return allPageCount;
116     }
117 
118     /**
119      * Sets the total number of pages.
120      * @param allPageCount the total page count
121      */
122     public void setAllPageCount(final int allPageCount) {
123         this.allPageCount = allPageCount;
124     }
125 
126     /**
127      * Checks if there is a previous page.
128      * @return true if previous page exists, false otherwise
129      */
130     public boolean isExistPrePage() {
131         return existPrePage;
132     }
133 
134     /**
135      * Sets whether a previous page exists.
136      * @param existPrePage true if previous page exists
137      */
138     public void setExistPrePage(final boolean existPrePage) {
139         this.existPrePage = existPrePage;
140     }
141 
142     /**
143      * Checks if there is a next page.
144      * @return true if next page exists, false otherwise
145      */
146     public boolean isExistNextPage() {
147         return existNextPage;
148     }
149 
150     /**
151      * Sets whether a next page exists.
152      * @param existNextPage true if next page exists
153      */
154     public void setExistNextPage(final boolean existNextPage) {
155         this.existNextPage = existNextPage;
156     }
157 
158     /**
159      * Gets the page size.
160      * @return the page size
161      */
162     public int getPageSize() {
163         if (pageSize <= 0) {
164             pageSize = getDefaultPageSize();
165         }
166         return pageSize;
167     }
168 
169     /**
170      * Sets the page size.
171      * @param pageSize the page size
172      */
173     public void setPageSize(final int pageSize) {
174         this.pageSize = pageSize;
175     }
176 
177     /**
178      * Gets the current page number.
179      * @return the current page number
180      */
181     public int getCurrentPageNumber() {
182         if (currentPageNumber <= 0) {
183             currentPageNumber = getDefaultCurrentPageNumber();
184         }
185         return currentPageNumber;
186     }
187 
188     /**
189      * Sets the current page number.
190      * @param currentPageNumber the current page number
191      */
192     public void setCurrentPageNumber(final int currentPageNumber) {
193         this.currentPageNumber = currentPageNumber;
194     }
195 
196     /**
197      * Gets the list of page numbers for pagination display.
198      * @return the list of page numbers
199      */
200     public List<Integer> getPageNumberList() {
201         return pageNumberList;
202     }
203 
204     /**
205      * Sets the list of page numbers for pagination display.
206      * @param pageNumberList the list of page numbers
207      */
208     public void setPageNumberList(final List<Integer> pageNumberList) {
209         this.pageNumberList = pageNumberList;
210     }
211 }