KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > tags > MemberTag


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

16 package dlog4j.tags;
17
18 import java.sql.SQLException JavaDoc;
19 import java.util.List JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22
23 import net.sf.hibernate.HibernateException;
24 import net.sf.hibernate.Session;
25 import dlog4j.ParamManager;
26 import dlog4j.SiteManager;
27 import dlog4j.UserManager;
28 import dlog4j.formbean.SiteForm;
29
30 /**
31  * @author Liudong
32  * 最新注册成员列表
33  */

34 public class MemberTag extends DlogBaseTag {
35
36     public final static String JavaDoc USERS_PER_PAGE = "USERS_PER_PAGE";
37     
38     int count = -1;
39     int page = -1; //当前页
40
int role = -2;
41     String JavaDoc usersPageId = MemberTei.PER_COUNT;
42     String JavaDoc pageCountId = MemberTei.PAGE_COUNT;
43     String JavaDoc userCountId = MemberTei.USER_COUNT;
44     String JavaDoc curPageId = MemberTei.CUR_PAGE_COUNT;
45     boolean query = true;
46
47     public int doEndTag() throws JspException JavaDoc {
48         release();
49         return EVAL_PAGE;
50     }
51     public void release() {
52         count = -1;
53         page = -1; //当前页
54
role = -2;
55     }
56     /* (non-Javadoc)
57      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
58      */

59     public int doStartTag() throws JspException JavaDoc {
60         Session session = null;
61         List JavaDoc users = null;
62         String JavaDoc query_key = null;
63         if(query)
64             query_key = getParameter("query");
65         try {
66             session = getSession();
67             SiteForm site = SiteManager.getCurrentSite(pageContext.getRequest());
68             //用户总数
69
int userCount = UserManager.getUserCount(session,site,role,query_key);
70             pageContext.setAttribute(userCountId,new Integer JavaDoc(userCount));
71             //每页用户数
72
int usersPage = ParamManager.getIntParam(session,site,USERS_PER_PAGE,10);
73             pageContext.setAttribute(usersPageId,new Integer JavaDoc(usersPage));
74             //页数
75
int pageCount = (userCount / usersPage) + (((userCount % usersPage)>0)?1:0);
76             pageContext.setAttribute(pageCountId,new Integer JavaDoc(pageCount));
77             //当前页
78
pageContext.setAttribute(curPageId, new Integer JavaDoc(page));
79             //读取用户列表
80
int from = page-1;
81             if(from<0)
82                 from = 0;
83             if(from>pageCount)
84                 from = pageCount;
85             from *= usersPage;
86             int uc = (count==-1)?usersPage:count;
87             users = UserManager.listUsers(session,site,from,uc,query_key);
88             pageContext.setAttribute(id, users);
89         } catch (SQLException JavaDoc e) {
90             throw new JspException JavaDoc(e);
91         } catch (HibernateException e) {
92             throw new JspException JavaDoc(e);
93         } finally {
94             try {
95                 closeSession(session);
96             } catch (Exception JavaDoc e) {
97             }
98         }
99         return SKIP_BODY;
100     }
101
102     public int getCount() {
103         return count;
104     }
105
106     public void setCount(int i) {
107         count = i;
108     }
109
110     public int getPage() {
111         return page;
112     }
113     public void setPage(int page) {
114         this.page = page;
115     }
116     public void setPage(String JavaDoc page) {
117         this.page = Integer.parseInt(page);
118     }
119     public void setPage(Integer JavaDoc page) {
120         this.page = page.intValue();
121     }
122     public String JavaDoc getPageCountId() {
123         return pageCountId;
124     }
125     public void setPageCountId(String JavaDoc pageCountId) {
126         this.pageCountId = pageCountId;
127     }
128     public String JavaDoc getUserCountId() {
129         return userCountId;
130     }
131     public void setUserCountId(String JavaDoc userCountId) {
132         this.userCountId = userCountId;
133     }
134     public String JavaDoc getUsersPageId() {
135         return usersPageId;
136     }
137     public void setUsersPageId(String JavaDoc usersPageId) {
138         this.usersPageId = usersPageId;
139     }
140     public int getRole() {
141         return role;
142     }
143     public void setRole(int role) {
144         this.role = role;
145     }
146     public String JavaDoc getCurPageId() {
147         return curPageId;
148     }
149     public void setCurPageId(String JavaDoc curPageId) {
150         this.curPageId = curPageId;
151     }
152     public boolean isQuery() {
153         return query;
154     }
155     public void setQuery(boolean query) {
156         this.query = query;
157     }
158 }
159
Popular Tags