KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > tags > UserTag


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 javax.servlet.jsp.JspException JavaDoc;
19
20 import net.sf.hibernate.HibernateException;
21 import net.sf.hibernate.Session;
22 import dlog4j.SiteManager;
23 import dlog4j.UserManager;
24 import dlog4j.formbean.UserForm;
25
26 /**
27  * @author Liudong 用于查询用户资料的标签库
28  */

29 public class UserTag extends DlogBaseTag {
30
31     int userid = -1;
32
33     String JavaDoc detail = "false";
34
35     String JavaDoc loginName = null;
36
37     /*
38      * (non-Javadoc)
39      *
40      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
41      */

42     public int doStartTag() throws JspException JavaDoc {
43         if (loginName != null) {
44             Session ssn = null;
45             try {
46                 ssn = getSession();
47                 UserForm user = UserManager.getUser(ssn, SiteManager
48                         .getCurrentSite(pageContext.getRequest()), loginName);
49
50                 if (user != null)
51                     pageContext.setAttribute(id, user);
52             } catch (HibernateException e) {
53                 throw new JspException JavaDoc(e);
54             } catch (Exception JavaDoc e) {
55                 throw new JspException JavaDoc(e);
56             } finally {
57                 try {
58                     closeSession(ssn);
59                 } catch (Exception JavaDoc e) {
60                 }
61             }
62         } else {
63             int uid = userid;
64             if (uid == -1)
65                 try {
66                     uid = Integer.parseInt(pageContext.getRequest()
67                             .getParameter("userid"));
68                 } catch (Exception JavaDoc e) {
69                 }
70             if (uid > -1) {
71                 Session ssn = null;
72                 try {
73                     ssn = getSession();
74                     boolean bDetail = "true".equalsIgnoreCase(detail);
75                     UserForm user = UserManager.getUser(ssn, uid, bDetail);
76                     if (user != null)
77                         pageContext.setAttribute(id, user);
78                 } catch (HibernateException e) {
79                     throw new JspException JavaDoc(e);
80                 } catch (Exception JavaDoc e) {
81                     throw new JspException JavaDoc(e);
82                 } finally {
83                     try {
84                         closeSession(ssn);
85                     } catch (Exception JavaDoc e) {
86                     }
87                 }
88             }
89         }
90         return SKIP_BODY;
91     }
92
93     public int doEndTag() throws JspException JavaDoc {
94         release();
95         return EVAL_PAGE;
96     }
97
98     public void release() {
99         userid = -1;
100         detail = "false";
101     }
102
103     /**
104      * @return
105      */

106     public String JavaDoc getDetail() {
107         return detail;
108     }
109
110     /**
111      * @param string
112      */

113     public void setDetail(String JavaDoc string) {
114         detail = string;
115     }
116
117     /**
118      * @return
119      */

120     public int getUserid() {
121         return userid;
122     }
123
124     /**
125      * @param i
126      */

127     public void setUserid(int i) {
128         userid = i;
129     }
130
131     /**
132      * @param i
133      */

134     public void setUserid(Integer JavaDoc i) {
135         userid = i.intValue();
136     }
137
138     /**
139      * @param i
140      */

141     public void setUserid(String JavaDoc i) {
142         userid = Integer.parseInt(i);
143     }
144
145     public String JavaDoc getLoginName() {
146         return loginName;
147     }
148
149     public void setLoginName(String JavaDoc loginName) {
150         this.loginName = loginName;
151     }
152 }
Popular Tags