KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > servlet > http > jsp > tagext > iteration > CurrentPageTag


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.servlet.http.jsp.tagext.iteration;
8
9 import javax.servlet.jsp.JspException JavaDoc;
10 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
11
12 import org.apache.struts.util.RequestUtils;
13 import org.apache.struts.util.ResponseUtils;
14
15 /**
16  * Description of the Class
17  *
18  * @author Laurent Etiemble
19  * @version $Revision: 1.4 $
20  * @todo Javadoc to complete
21  * @jsp:tag name="currentPage"
22  * body-content="empty"
23  */

24 public class CurrentPageTag extends TagSupport JavaDoc
25 {
26    /** Description of the Field */
27    protected String JavaDoc current = null;
28    /** Description of the Field */
29    protected String JavaDoc length = null;
30    /** Description of the Field */
31    protected String JavaDoc scope = null;
32    /** Description of the Field */
33    protected String JavaDoc size = null;
34
35
36    /**
37     * Description of the Method
38     *
39     * @return Description of the Returned Value
40     * @exception JspException Description of Exception
41     */

42    public int doStartTag()
43       throws JspException JavaDoc
44    {
45       int currentPage = ((Integer JavaDoc) RequestUtils.lookup(pageContext, current, scope)).intValue();
46       int contentSize = ((Integer JavaDoc) RequestUtils.lookup(pageContext, size, scope)).intValue();
47       int pageLength = Integer.parseInt(length);
48
49       // Compute the last page
50
int lastPage = (contentSize / pageLength);
51       if ((contentSize % pageLength) > 0)
52       {
53          lastPage++;
54       }
55       if (lastPage == 0)
56       {
57          lastPage = 1;
58       }
59
60       StringBuffer JavaDoc output = new StringBuffer JavaDoc();
61       output.append(currentPage);
62       output.append("/");
63       output.append(lastPage);
64
65       ResponseUtils.write(pageContext, output.toString());
66
67       // Continue processing this page
68
return (SKIP_BODY);
69    }
70
71
72    /**
73     * Returns the start.
74     *
75     * @return String
76     * @jsp:attribute name="current"
77     * required="true"
78     * rtexprvalue="true"
79     */

80    public String JavaDoc getCurrent()
81    {
82       return current;
83    }
84
85
86    /**
87     * Returns the page.
88     *
89     * @return String
90     * @jsp:attribute name="length"
91     * required="true"
92     * rtexprvalue="true"
93     */

94    public String JavaDoc getLength()
95    {
96       return length;
97    }
98
99
100    /**
101     * Getter for the scope attribute
102     *
103     * @return The value of scope attribute
104     * @jsp:attribute name="scope"
105     * required="false"
106     * rtexprvalue="true"
107     */

108    public String JavaDoc getScope()
109    {
110       return (this.scope);
111    }
112
113
114    /**
115     * Returns the length.
116     *
117     * @return String
118     * @jsp:attribute name="size"
119     * required="true"
120     * rtexprvalue="true"
121     */

122    public String JavaDoc getSize()
123    {
124       return size;
125    }
126
127
128    /** Release all allocated resources. */
129    public void release()
130    {
131       super.release();
132       size = null;
133       current = null;
134    }
135
136
137    /**
138     * Sets the current.
139     *
140     * @param current The current to set
141     */

142    public void setCurrent(String JavaDoc current)
143    {
144       this.current = current;
145    }
146
147
148    /**
149     * Sets the length.
150     *
151     * @param length The length to set
152     */

153    public void setLength(String JavaDoc length)
154    {
155       this.length = length;
156    }
157
158
159    /**
160     * Sets the scope.
161     *
162     * @param scope The scope to set
163     */

164    public void setScope(String JavaDoc scope)
165    {
166       this.scope = scope;
167    }
168
169
170    /**
171     * Sets the size.
172     *
173     * @param size The size to set
174     */

175    public void setSize(String JavaDoc size)
176    {
177       this.size = size;
178    }
179
180 }
181
182
Popular Tags