KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > jsp > CmsContentInfoBean


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/CmsContentInfoBean.java,v $
3  * Date : $Date: 2006/03/27 14:52:19 $
4  * Version: $Revision: 1.15 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.jsp;
33
34 import org.opencms.util.CmsStringUtil;
35
36 /**
37  * A container to store information about a collector's result.<p>
38  *
39  * @author Thomas Weckert
40  *
41  * @version $Revision: 1.15 $
42  *
43  * @since 6.0.0
44  */

45 public class CmsContentInfoBean {
46
47     /** The name under which the collector info is saved in the page context. */
48     public static final String JavaDoc PAGE_CONTEXT_ATTRIBUTE_NAME = "CollectorInfo";
49
50     /** The default locale (as String) that is used. */
51     private String JavaDoc m_locale;
52
53     /** The number of pages of browse through the result list. */
54     private int m_pageCount;
55
56     /** The index of the current page that to be displayed. */
57     private int m_pageIndex;
58
59     /** The page index of the last element in the Google-like page navigation. */
60     private int m_pageNavEndIndex;
61
62     /** The number of page links in the Google-like page navigation. */
63     private int m_pageNavLength;
64
65     /** The page index of the first element in the Google-like page navigation. */
66     private int m_pageNavStartIndex;
67
68     /** The number of entries to be displayed on a page. */
69     private int m_pageSize;
70
71     /** The index of the current resource that gets iterated in the result list. */
72     private int m_resultIndex;
73
74     /** The total size of the collector's result list. */
75     private int m_resultSize;
76
77     /**
78      * Creates a new content info bean.<p>
79      */

80     public CmsContentInfoBean() {
81
82         super();
83
84         m_resultSize = -1;
85         m_resultIndex = -1;
86
87         m_pageCount = 1;
88         m_pageSize = -1;
89         m_pageIndex = 1;
90         m_pageNavStartIndex = 1;
91         m_pageNavEndIndex = 1;
92         m_pageNavLength = 10;
93     }
94
95     /**
96      * Returns the locale used by the content loader.<p>
97      *
98      * @return the locale used by the content loader
99      */

100     public String JavaDoc getLocale() {
101
102         return m_locale;
103     }
104
105     /**
106      * Returns the number of pages of browse through the result list.<p>
107      *
108      * @return the number of pages of browse through the result list
109      */

110     public int getPageCount() {
111
112         return m_pageCount;
113     }
114
115     /**
116      * Returns the index of the current page that gets displayed.<p>
117      *
118      * @return the index of the current page that gets displayed
119      */

120     public int getPageIndex() {
121
122         return m_pageIndex;
123     }
124
125     /**
126      * Returns the page index of the first element in the Google-like page navigation.<p>
127      *
128      * @return the page index of the first element in the Google-like page navigation
129      */

130     public int getPageNavEndIndex() {
131
132         return m_pageNavEndIndex;
133     }
134
135     /**
136      * Returns the page index of the last element in the Google-like page navigation.<p>
137      *
138      * @return page index of the last element in the Google-like page navigation
139      */

140     public int getPageNavLength() {
141
142         return m_pageNavLength;
143     }
144
145     /**
146      * Returns the page index of the first element in the Google-like page navigation.<p>
147      *
148      * @return the page index of the first element in the Google-like page navigation
149      */

150     public int getPageNavStartIndex() {
151
152         return m_pageNavStartIndex;
153     }
154
155     /**
156      * Returns the size of a page.<p>
157      *
158      * @return the size of a page
159      */

160     public int getPageSize() {
161
162         return m_pageSize;
163     }
164
165     /**
166      * Returns the index of the current resource that gets iterated in the result list.<p>
167      *
168      * @return the index of the current resource that gets iterated in the result list
169      */

170     public int getResultIndex() {
171
172         return m_resultIndex;
173     }
174
175     /**
176      * Returns the total size of the collector's result list.<p>
177      *
178      * @return the total size of the collector's result list
179      */

180     public int getResultSize() {
181
182         return m_resultSize;
183     }
184
185     /**
186      * Returns true if there is no resource in the result list.<p>
187      *
188      * @return true if there is no resource in the result list
189      */

190     public boolean isEmptyResult() {
191
192         return m_resultSize <= 0;
193     }
194
195     /**
196      * Returns true if the current resource is the first resource on the current page.<p>
197      *
198      * @return true if the current resource is the first resource on the current page
199      */

200     public boolean isFirstOnPage() {
201
202         return m_resultIndex == (m_pageCount * m_pageSize) + 1;
203     }
204
205     /**
206      * Returns true if the current resource is the first resource in the result list.<p>
207      *
208      * @return true if the current resource is the first resource in the result list
209      */

210     public boolean isFirstResult() {
211
212         return m_resultIndex == 1;
213     }
214
215     /**
216      * Returns true if the current resource is the last resource on the current page.<p>
217      *
218      * @return true if the current resource is the last resource on the current page
219      */

220     public boolean isLastOnPage() {
221
222         return (m_resultIndex == (m_pageCount + 1) * m_pageSize) || isLastResult();
223     }
224
225     /**
226      * Returns true if the current resource is the last resource in the result list.<p>
227      *
228      * @return true if the current resource is the last resource in the result list
229      */

230     public boolean isLastResult() {
231
232         return m_resultIndex == m_resultSize;
233     }
234
235     /**
236      * Sets the current locale used by the content loader.<p>
237      *
238      * @param locale the locale to set
239      */

240     public void setLocale(String JavaDoc locale) {
241
242         m_locale = locale;
243     }
244
245     /**
246      * Increments the index of the current resource that gets iterated in the result list.<p>
247      */

248     void incResultIndex() {
249
250         m_resultIndex++;
251     }
252
253     /**
254      * Initializes the start and end indexes to build a Google-like page navigation.<p>
255      */

256     void initPageNavIndexes() {
257
258         if (m_pageIndex < m_pageNavLength) {
259
260             m_pageNavStartIndex = 1;
261             m_pageNavEndIndex = m_pageCount < m_pageNavLength ? m_pageCount : m_pageNavLength;
262
263         } else {
264
265             int middle = m_pageNavLength / 2;
266             m_pageNavStartIndex = m_pageIndex - middle;
267             m_pageNavEndIndex = m_pageNavStartIndex + m_pageNavLength - 1;
268
269             if (m_pageNavStartIndex < 1) {
270                 m_pageNavStartIndex = 1;
271             } else if (m_pageNavEndIndex < 1) {
272                 m_pageNavEndIndex = m_pageCount;
273             } else if (m_pageNavEndIndex > m_pageCount) {
274
275                 // adjust end index
276
m_pageNavEndIndex = m_pageCount;
277                 m_pageNavStartIndex = m_pageNavEndIndex - m_pageNavLength + 1;
278
279                 if (m_pageNavStartIndex < 1) {
280                     // adjust the start index again
281
m_pageNavStartIndex = 1;
282                 }
283             }
284         }
285     }
286
287     /**
288      * Initializes the index of the current resource that gets iterated in the result list.<p>
289      */

290     void initResultIndex() {
291
292         int startIndex = 0;
293         if (m_pageIndex > 0 && m_pageSize > 0) {
294             startIndex = (m_pageIndex - 1) * m_pageSize;
295         }
296
297         m_resultIndex = startIndex > m_resultSize ? m_resultSize : startIndex;
298     }
299
300     /**
301      * Sets the number of pages of browse through the result list.<p>
302      *
303      * @param pageCount the number of pages of browse through the result list
304      */

305     void setPageCount(int pageCount) {
306
307         m_pageCount = pageCount;
308     }
309
310     /**
311      * Sets the index of the current page that gets displayed as an int.<p>
312      *
313      * @param pageIndex the index of the current page that gets displayed as an int
314      */

315     void setPageIndex(int pageIndex) {
316
317         m_pageIndex = pageIndex;
318     }
319
320     /**
321      * Sets the index of the current page that gets displayed as a string.<p>
322      *
323      * The specified string gets parsed into an int.<p>
324      *
325      * @param pageIndex the index of the current page that gets displayed as a string
326      */

327     void setPageIndexAsString(String JavaDoc pageIndex) {
328
329         if (CmsStringUtil.isEmpty(pageIndex)) {
330             return;
331         }
332
333         try {
334             m_pageIndex = Integer.parseInt(pageIndex);
335         } catch (NumberFormatException JavaDoc e) {
336             // intentionally left blank
337
}
338     }
339
340     /**
341      * Sets the page index of the last element in the Google-like page navigation.<p>
342      *
343      * @param index the page index of the last element in the Google-like page navigation
344      */

345     void setPageNavEndIndex(int index) {
346
347         m_pageNavEndIndex = index;
348     }
349
350     /**
351      * Sets the number of page links in the Google-like page navigation.<p>
352      *
353      * @param length the number of page links in the Google-like page navigation
354      */

355     void setPageNavLength(int length) {
356
357         m_pageNavLength = length;
358     }
359
360     /**
361      * Sets number of page links in the Google-like page navigation as a string.<p>
362      *
363      * @param pageNavLength the number of page links in the Google-like page navigation
364      */

365     void setPageNavLengthAsString(String JavaDoc pageNavLength) {
366
367         if (CmsStringUtil.isEmpty(pageNavLength)) {
368             return;
369         }
370
371         try {
372             m_pageNavLength = Integer.parseInt(pageNavLength);
373         } catch (NumberFormatException JavaDoc e) {
374             // intentionally left blank
375
}
376     }
377
378     /**
379      * Sets the page index of the first element in the Google-like page navigation.<p>
380      *
381      * @param index the page index of the first element in the Google-like page navigation
382      */

383     void setPageNavStartIndex(int index) {
384
385         m_pageNavStartIndex = index;
386     }
387
388     /**
389      * Sets the size of a page as an int.<p>
390      *
391      * @param pageSize the size of a page as an int
392      */

393     void setPageSize(int pageSize) {
394
395         m_pageSize = pageSize;
396     }
397
398     /**
399      * Sets the size of a page as a string.<p>
400      *
401      * The specified string gets parsed into an int.<p>
402      *
403      * @param pageSize the size of a page as a string
404      */

405     void setPageSizeAsString(String JavaDoc pageSize) {
406
407         if (CmsStringUtil.isEmpty(pageSize)) {
408             return;
409         }
410
411         try {
412             m_pageSize = Integer.parseInt(pageSize);
413         } catch (NumberFormatException JavaDoc e) {
414             // intentionally left blank
415
}
416     }
417
418     /**
419      * Sets the total size of the collector's result list.<p>
420      *
421      * @param size the total size of the collector's result list
422      */

423     void setResultSize(int size) {
424
425         m_resultSize = size;
426     }
427 }
Popular Tags