1 ////////////////////////////////////////////////////////////////////////////////
2 //CabaWeb
3 //Copyright (C) 2004 Thomas Vogt <Thomas.Vogt@TVC-Software.com>
4 //
5 //This library is free software; you can redistribute it and/or
6 //modify it under the terms of the GNU Lesser General Public
7 //License as published by the Free Software Foundation; either
8 //version 2.1 of the License, or (at your option) any later version.
9 //
10 //This library is distributed in the hope that it will be useful,
11 //but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 //Lesser General Public License for more details.
14 //
15 //You should have received a copy of the GNU Lesser General Public
16 //License along with this library; if not, write to the Free Software
17 //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ////////////////////////////////////////////////////////////////////////////////
19 package org.fhw.cabaweb.webfrontend.tools;
20
21 import javax.servlet.http.HttpServletRequest;
22
23 /***
24 * Diese Klasse enthält einige allgemeine Methoden für das Webfrontend.
25 *
26 * @author <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
27 * @version Version 1.0 29.07.2004
28 */
29 public final class Common
30 {
31
32 /***
33 * Schreibt OffsetWErte in den Request um eine Pager zu erzeugen.
34 *
35 * @param request Der Request
36 * @param size Die Listengrösse
37 */
38 public final static void Pager(HttpServletRequest request, int size)
39 {
40 int offset;
41 int length = 25;
42 String pageOffset = request.getParameter("offset");
43
44 if (pageOffset == null || pageOffset.equals(""))
45 {
46 offset = 0;
47 }
48 else
49 {
50 offset = Integer.parseInt(pageOffset);
51 }
52
53 request.setAttribute("offset", new Integer(offset));
54 if ((offset - length) >= 0)
55 {
56 request.setAttribute("offsetL", new Integer(offset - length));
57 }
58 else
59 request.setAttribute("offsetL", null);
60
61 if ((offset + length) <= size)
62 {
63 request.setAttribute("offsetM", new Integer(offset + length));
64 }
65 else
66 request.setAttribute("offsetM", null);
67
68 request.setAttribute("length", new Integer(length));
69 }
70 }