Source Code Cross Referenced for UserForm.java in  » Portal » DLOG4J » dlog4j » formbean » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » DLOG4J » dlog4j.formbean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  This program is free software; you can redistribute it and/or modify
003:         *  it under the terms of the GNU General Public License as published by
004:         *  the Free Software Foundation; either version 2 of the License, or
005:         *  (at your option) any later version.
006:         *
007:         *  This program is distributed in the hope that it will be useful,
008:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *  GNU Library General Public License for more details.
011:         *
012:         *  You should have received a copy of the GNU General Public License
013:         *  along with this program; if not, write to the Free Software
014:         *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015:         */
016:        package dlog4j.formbean;
017:
018:        import java.sql.SQLException;
019:        import java.text.SimpleDateFormat;
020:        import java.util.ArrayList;
021:        import java.util.Date;
022:        import java.util.List;
023:        import java.util.StringTokenizer;
024:
025:        import javax.servlet.http.HttpServletRequest;
026:
027:        import net.sf.hibernate.HibernateException;
028:        import net.sf.hibernate.Session;
029:
030:        import dlog4j.SiteManager;
031:        import dlog4j.UserManager;
032:        import dlog4j.security.DlogRole;
033:        import dlog4j.util.StringUtils;
034:
035:        /** 
036:         * UserForm.java created by EasyStruts - XsltGen.
037:         * http://easystruts.sf.net
038:         * created on 02-02-2004
039:         * 
040:         * XDoclet definition:
041:         * @struts:form name="userForm"
042:         */
043:        public class UserForm extends DlogActionForm implements  Cloneable {
044:
045:            public final static String KEY = "dlog4j.loginUser";
046:            public final static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
047:                    "yyyy-MM-dd");
048:            public final static int MODE_LOGIN = 0;
049:            public final static int MODE_REG = 1;
050:            public final static int MODE_EDIT = 2;
051:            public final static int MODE_CREATE = 4; //创建新站点的管理员
052:            public final static int MODE_DELETE = 8;
053:
054:            // --------------------------------------------------------- Instance Variables
055:
056:            /** age property */
057:            private int id;
058:
059:            /** email property */
060:            private String email;
061:
062:            /** name property */
063:            private String loginName;
064:
065:            private String password;
066:            private String displayName;
067:            private String homePage;
068:            private String resume;
069:            private String portrait;
070:            private int loginCount;
071:            private Date regTime;
072:            private Date lastTime;
073:            private int userRole = DlogRole.ROLE_GUEST;
074:            private int mode = MODE_LOGIN;
075:
076:            private List logs;
077:            private int logCount;
078:            private List replies;
079:            private int replyCount;
080:            private int bookMarkCount; //此字段不对应数据库,而是由getLoginUser标签设置该字段的值
081:
082:            SiteForm site;
083:
084:            DlogRole role;
085:
086:            /**
087:             * 如果用户是密友则该属性为拥有特权(查看与添加)的分类
088:             * 如果用户是好友则该属性是用户可添加日记的分类
089:             * 多个分类使用逗号格开,例如 1,4,5
090:             */
091:            private String cats;
092:
093:            public static UserForm getLoginUser(HttpServletRequest request) {
094:                SiteForm sf = SiteManager.getCurrentSite(request);
095:                if (sf != null)
096:                    return (UserForm) request.getSession().getAttribute(
097:                            sf.getName() + '_' + UserForm.KEY);
098:                return null;
099:            }
100:
101:            public void saveLoginUser(HttpServletRequest request) {
102:                SiteForm sf = SiteManager.getCurrentSite(request);
103:                if (sf != null)
104:                    request.getSession().setAttribute(
105:                            sf.getName() + '_' + UserForm.KEY, this );
106:            }
107:
108:            public static void removeFromSession(HttpServletRequest request) {
109:                SiteForm sf = SiteManager.getCurrentSite(request);
110:                if (sf != null)
111:                    request.getSession().removeAttribute(
112:                            sf.getName() + '_' + UserForm.KEY);
113:            }
114:
115:            public boolean isLogin() {
116:                return regTime != null;
117:            }
118:
119:            public boolean isAdmin() {
120:                return userRole == DlogRole.ROLE_MANAGER;
121:            }
122:
123:            public boolean isFriend() {
124:                return userRole == DlogRole.ROLE_FRIEND;
125:            }
126:
127:            // --------------------------------------------------------- Methods
128:
129:            public String toString() {
130:                StringBuffer user = new StringBuffer(100);
131:                user.append("Name:");
132:                user.append(loginName);
133:                user.append(",displayName:");
134:                user.append(displayName);
135:                user.append(",email:");
136:                user.append(email);
137:                user.append(",password:");
138:                user.append(password);
139:                return user.toString();
140:            }
141:
142:            /**
143:             * 检查登录帐号是否已存在
144:             * @param name
145:             * @return
146:             */
147:            protected UserForm checkLoginName(SiteForm site, String name) {
148:                Session ssn = null;
149:                UserForm user = null;
150:                try {
151:                    ssn = getSession();
152:                    user = UserManager.getUser(ssn, site, name);
153:                } catch (HibernateException e) {
154:                } catch (SQLException e) {
155:                } finally {
156:                    try {
157:                        closeSession(ssn);
158:                    } catch (Exception e) {
159:                    }
160:                }
161:                return user;
162:            }
163:
164:            /**
165:             * @return
166:             */
167:            public String getDisplayName() {
168:                return displayName;
169:            }
170:
171:            /**
172:             * @return
173:             */
174:            public String getEmail() {
175:                return email;
176:            }
177:
178:            /**
179:             * @return
180:             */
181:            public String getHomePage() {
182:                return homePage;
183:            }
184:
185:            /**
186:             * @return
187:             */
188:            public int getId() {
189:                return id;
190:            }
191:
192:            /**
193:             * @return
194:             */
195:            public Date getLastTime() {
196:                return lastTime;
197:            }
198:
199:            /**
200:             * @return
201:             */
202:            public int getLoginCount() {
203:                return loginCount;
204:            }
205:
206:            /**
207:             * @return
208:             */
209:            public String getPassword() {
210:                return password;
211:            }
212:
213:            public String getCryptPassword() {
214:                return StringUtils.encrypt(password);
215:            }
216:
217:            public void setCryptPassword(String pwd) {
218:                password = StringUtils.decrypt(pwd);
219:            }
220:
221:            /**
222:             * @return
223:             */
224:            public Date getRegTime() {
225:                return regTime;
226:            }
227:
228:            /**
229:             * @return
230:             */
231:            public String getResume() {
232:                return resume;
233:            }
234:
235:            /**
236:             * @return
237:             */
238:            public int getUserRole() {
239:                return userRole;
240:            }
241:
242:            public String getRoleDesc() {
243:                String desc = null;
244:                switch (userRole) {
245:                case DlogRole.ROLE_MANAGER:
246:                    desc = "管理员";
247:                    break;
248:                case DlogRole.ROLE_GUEST:
249:                    desc = "过客";
250:                    break;
251:                case DlogRole.ROLE_COMMON:
252:                    desc = "普通用户";
253:                    break;
254:                case DlogRole.ROLE_FRIEND:
255:                    desc = "我的好友";
256:                    break;
257:                case DlogRole.ROLE_BUDDY:
258:                    desc = "密友";
259:                    break;
260:                default:
261:                    desc = "未知";
262:                }
263:                return desc;
264:            }
265:
266:            /**
267:             * @param string
268:             */
269:            public void setDisplayName(String string) {
270:                displayName = string;
271:            }
272:
273:            /**
274:             * @param string
275:             */
276:            public void setEmail(String string) {
277:                email = string;
278:            }
279:
280:            /**
281:             * @param string
282:             */
283:            public void setHomePage(String string) {
284:                homePage = string;
285:            }
286:
287:            /**
288:             * @param i
289:             */
290:            public void setId(int i) {
291:                id = i;
292:            }
293:
294:            /**
295:             * @param date
296:             */
297:            public void setLastTime(Date date) {
298:                lastTime = date;
299:            }
300:
301:            /**
302:             * @param i
303:             */
304:            public void setLoginCount(int i) {
305:                loginCount = i;
306:            }
307:
308:            /**
309:             * @param string
310:             */
311:            public void setPassword(String string) {
312:                password = string;
313:            }
314:
315:            /**
316:             * @param date
317:             */
318:            public void setRegTime(Date date) {
319:                regTime = date;
320:            }
321:
322:            public String getRegDate() {
323:                if (regTime == null)
324:                    return null;
325:                return DATE_FORMAT.format(regTime);
326:            }
327:
328:            public String getLastDate() {
329:                if (lastTime == null)
330:                    return null;
331:                return DATE_FORMAT.format(lastTime);
332:            }
333:
334:            /**
335:             * @param string
336:             */
337:            public void setResume(String string) {
338:                resume = string;
339:            }
340:
341:            /**
342:             * @param i
343:             */
344:            public void setUserRole(int i) {
345:                userRole = i;
346:            }
347:
348:            /**
349:             * @return
350:             */
351:            public List getLogs() {
352:                return logs;
353:            }
354:
355:            public int getLogCount() {
356:                return logCount;
357:            }
358:
359:            /**
360:             * @return
361:             */
362:            public List getReplies() {
363:                return replies;
364:            }
365:
366:            /**
367:             * @param list
368:             */
369:            public void setLogs(List list) {
370:                logs = list;
371:            }
372:
373:            /**
374:             * @param list
375:             */
376:            public void setReplies(List list) {
377:                replies = list;
378:            }
379:
380:            /**
381:             * @return
382:             */
383:            public String getLoginName() {
384:                return loginName;
385:            }
386:
387:            /**
388:             * @param string
389:             */
390:            public void setLoginName(String string) {
391:                loginName = string;
392:            }
393:
394:            /**
395:             * @return
396:             */
397:            public int getMode() {
398:                return mode;
399:            }
400:
401:            /**
402:             * @param i
403:             */
404:            public void setMode(int i) {
405:                mode = i;
406:            }
407:
408:            /**
409:             * @return
410:             */
411:            public int getReplyCount() {
412:                return replyCount;
413:            }
414:
415:            /**
416:             * @param i
417:             */
418:            public void setLogCount(int i) {
419:                logCount = i;
420:            }
421:
422:            /**
423:             * @param i
424:             */
425:            public void setReplyCount(int i) {
426:                replyCount = i;
427:            }
428:
429:            /**
430:             * @return
431:             */
432:            public SiteForm getSite() {
433:                return site;
434:            }
435:
436:            /**
437:             * @param form
438:             */
439:            public void setSite(SiteForm form) {
440:                site = form;
441:            }
442:
443:            public String getPortrait() {
444:                return portrait;
445:            }
446:
447:            public void setPortrait(String portrait) {
448:                this .portrait = portrait;
449:            }
450:
451:            public DlogRole getRole() {
452:                return role;
453:            }
454:
455:            public void setRole(DlogRole role) {
456:                this .role = role;
457:            }
458:
459:            public String getCats() {
460:                return cats;
461:            }
462:
463:            public void setCats(String cats) {
464:                this .cats = cats;
465:            }
466:
467:            public int getBookMarkCount() {
468:                return bookMarkCount;
469:            }
470:
471:            public void setBookMarkCount(int bookMarkCount) {
472:                this .bookMarkCount = bookMarkCount;
473:            }
474:
475:            /**
476:             * 该方法由CategoryManager调用
477:             * @return
478:             */
479:            public int[] getOwnerCatids() {
480:                List ids = new ArrayList();
481:                if (cats != null) {
482:                    StringTokenizer st = new StringTokenizer(cats, ",");
483:                    while (st.hasMoreElements()) {
484:                        String sId = st.nextToken();
485:                        try {
486:                            Integer IId = new Integer(Integer.parseInt(sId));
487:                            if (!ids.contains(IId))
488:                                ids.add(IId);
489:                        } catch (Exception e) {
490:                        }
491:                    }
492:                }
493:                int[] nIds = new int[ids.size()];
494:                for (int i = 0; i < ids.size(); i++)
495:                    nIds[i] = ((Integer) ids.get(i)).intValue();
496:                return nIds;
497:            }
498:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.