KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > tags > TopCommentTag


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.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.jsp.JspException JavaDoc;
24
25 import net.sf.hibernate.HibernateException;
26 import net.sf.hibernate.Session;
27 import dlog4j.ReplyManager;
28 import dlog4j.SiteManager;
29 import dlog4j.formbean.SiteForm;
30 import dlog4j.formbean.UserForm;
31
32 /**
33  * @author Liudong
34  * TOP N Comment
35  */

36 public class TopCommentTag extends DlogBaseTag {
37
38     int count = 10;
39     
40     public int doEndTag() throws JspException JavaDoc {
41         release();
42         return EVAL_PAGE;
43     }
44     public void release() {
45         count = 10;
46     }
47     /* (non-Javadoc)
48      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
49      */

50     public int doStartTag() throws JspException JavaDoc {
51         if (pageContext.getAttribute(id) == null) {
52             Session session = null;
53             List JavaDoc replies = null;
54             try {
55                 session = getSession();
56                 SiteForm site = SiteManager.getCurrentSite(pageContext.getRequest());
57                 UserForm loginUser = UserForm.getLoginUser((HttpServletRequest JavaDoc)pageContext.getRequest());
58                 replies = ReplyManager.listReplies(session, site, loginUser, count);
59             } catch (SQLException JavaDoc e) {
60                 throw new JspException JavaDoc(e);
61             } catch (HibernateException e) {
62                 throw new JspException JavaDoc(e);
63             } finally {
64                 try {
65                     closeSession(session);
66                 } catch (Exception JavaDoc e) {}
67             }
68             if (replies == null)
69                 replies = new ArrayList JavaDoc();
70             pageContext.setAttribute(id, replies);
71         }
72         return SKIP_BODY;
73     }
74
75     /**
76      * @return
77      */

78     public int getCount() {
79         return count;
80     }
81
82     /**
83      * @param i
84      */

85     public void setCount(int i) {
86         count = i;
87     }
88
89     /**
90      * @param i
91      */

92     public void setCount(Integer JavaDoc i) {
93         count = i.intValue();
94     }
95
96     /**
97      * @param i
98      */

99     public void setCount(String JavaDoc i) {
100         count = Integer.parseInt(i);
101     }
102
103 }
104
Popular Tags