KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jsptags > navigation > pager > IndexTag


1 /*
2  * Pager Tag Library
3  *
4  * Copyright (C) 2002 James Klicman <james@jsptags.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20
21 package com.jsptags.navigation.pager;
22
23 import javax.servlet.jsp.*;
24 import javax.servlet.jsp.tagext.*;
25 import com.jsptags.navigation.pager.parser.*;
26
27 public final class IndexTag extends PagerTagSupport {
28
29     private String JavaDoc export = null;
30
31     private IndexTagExport indexTagExport = null;
32     private Object JavaDoc oldItemCount = null;
33     private Object JavaDoc oldPageCount = null;
34
35
36     public final void setExport(String JavaDoc value) throws JspException {
37         if (export != value) {
38             try {
39                 indexTagExport = TagExportParser.parseIndexTagExport(value);
40             } catch (ParseException ex) {
41                 throw new JspTagException(ex.getMessage());
42             }
43         }
44         export = value;
45     }
46
47     public final String JavaDoc getExport() {
48         return export;
49     }
50
51
52     public int doStartTag() throws JspException {
53         super.doStartTag();
54
55         if (indexTagExport != null) {
56             String JavaDoc name;
57             if ((name = indexTagExport.getItemCount()) != null) {
58                 oldItemCount = pageContext.getAttribute(name);
59                 pageContext.setAttribute(name,
60                     new Integer JavaDoc(pagerTag.getItemCount()));
61             }
62
63             if ((name = indexTagExport.getPageCount()) != null) {
64                 oldPageCount = pageContext.getAttribute(name);
65                 pageContext.setAttribute(name,
66                     new Integer JavaDoc(pagerTag.getPageCount()));
67             }
68         }
69
70         return (pagerTag.isIndexNeeded() ? EVAL_BODY_INCLUDE : SKIP_BODY);
71     }
72
73     public int doEndTag() throws JspException {
74
75         if (indexTagExport != null) {
76             String JavaDoc name;
77             if ((name = indexTagExport.getItemCount()) != null) {
78                 restoreAttribute(name, oldItemCount);
79                 oldItemCount = null;
80             }
81
82             if ((name = indexTagExport.getPageCount()) != null) {
83                 restoreAttribute(name, oldPageCount);
84                 oldPageCount = null;
85             }
86         }
87
88         super.doEndTag();
89
90         return EVAL_PAGE;
91     }
92
93     public void release() {
94         export = null;
95         indexTagExport = null;
96         oldItemCount = null;
97         oldPageCount = null;
98
99         super.release();
100     }
101 }
102
103 /* vim:set ts=4 sw=4: */
104
Popular Tags