KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > entities > User


1 /*
2  * Copyright (c) Rafael Steil
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms,
6  * with or without modification, are permitted provided
7  * that the following conditions are met:
8  *
9  * 1) Redistributions of source code must retain the above
10  * copyright notice, this list of conditions and the
11  * following disclaimer.
12  * 2) Redistributions in binary form must reproduce the
13  * above copyright notice, this list of conditions and
14  * the following disclaimer in the documentation and/or
15  * other materials provided with the distribution.
16  * 3) Neither the name of "Rafael Steil" nor
17  * the names of its contributors may be used to endorse
18  * or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
22  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
32  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
34  * IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
38  *
39  * This file creating date: Feb 17, 2003 / 10:25:04 PM
40  * The JForum Project
41  * http://www.jforum.net
42  *
43  * $Id: User.java,v 1.18 2005/10/28 16:35:14 almilli Exp $
44  */

45 package net.jforum.entities;
46
47 import java.io.Serializable JavaDoc;
48 import java.text.SimpleDateFormat JavaDoc;
49 import java.util.ArrayList JavaDoc;
50 import java.util.Date JavaDoc;
51 import java.util.HashMap JavaDoc;
52 import java.util.List JavaDoc;
53 import java.util.Map JavaDoc;
54
55 import net.jforum.SessionFacade;
56 import net.jforum.util.preferences.ConfigKeys;
57 import net.jforum.util.preferences.SystemGlobals;
58
59 /**
60  * Represents a single user in the system.
61  * An user is every person which uses the forum. Well,
62  * every registered user. Anonymous users does not have
63  * a specific ID, for example. This class contains all information
64  * about some user configuration options and preferences.
65  *
66  * @author Rafael Steil
67  */

68 public class User implements Serializable JavaDoc
69 {
70     private int id;
71     private int themeId;
72     private int level;
73     private int totalPosts;
74     private boolean attachSignatureEnabled = true;
75     private int rankId = 1;
76     private boolean htmlEnabled = true;
77     private boolean bbCodeEnabled = true;
78     private boolean smiliesEnabled = true;
79     private boolean avatarEnabled = true;
80     private boolean privateMessagesEnabled = true;
81     private boolean viewOnlineEnabled = true;
82     private boolean notifyPrivateMessagesEnabled = true;
83     private boolean notifyOnMessagesEnabled = true;
84     private String JavaDoc username;
85     private String JavaDoc password;
86     private Date JavaDoc lastVisit;
87     private Date JavaDoc registrationDate;
88     private String JavaDoc avatar;
89     private boolean isExternalAvatar;
90     private String JavaDoc email;
91     private String JavaDoc icq;
92     private String JavaDoc webSite;
93     private String JavaDoc from;
94     private String JavaDoc signature;
95     private String JavaDoc aim;
96     private String JavaDoc yim;
97     private String JavaDoc msnm;
98     private String JavaDoc occupation;
99     private String JavaDoc interests;
100     private String JavaDoc biography;
101     private String JavaDoc gender;
102     private String JavaDoc timeZone;
103     private String JavaDoc lang;
104     private String JavaDoc dateFormat;
105     private boolean viewEmailEnabled = true;
106     private List JavaDoc groupsList;
107     private int privateMessagesCount;
108     private KarmaStatus karma;
109     private int active;
110     private String JavaDoc activationKey;
111     private int deleted;
112     private String JavaDoc firstName;
113     private String JavaDoc lastName;
114     private Map JavaDoc extra = new HashMap JavaDoc();
115     
116     /**
117      * Default Constructor
118      */

119     public User()
120     {
121         this.groupsList = new ArrayList JavaDoc();
122     }
123     
124     public void addExtra(String JavaDoc name, Object JavaDoc value)
125     {
126         this.extra.put(name, value);
127     }
128     
129     public Object JavaDoc getExtra(String JavaDoc name)
130     {
131         return this.extra.get(name);
132     }
133     
134     public void setFirstName(String JavaDoc name)
135     {
136         this.firstName = name;
137     }
138     
139     public String JavaDoc getFirstName()
140     {
141         return this.firstName;
142     }
143     
144     public void setLastName(String JavaDoc name)
145     {
146         this.lastName = name;
147     }
148     
149     public String JavaDoc getLastNmame()
150     {
151         return this.lastName;
152     }
153     
154     public String JavaDoc getName()
155     {
156         return this.firstName + " " + this.lastName;
157     }
158     
159     public boolean isDeleted() {
160         return this.deleted == 1;
161     }
162     
163     public void setDeleted(int deleted){
164         this.deleted = deleted;
165     }
166     
167     /**
168      * Gets the AIM identification
169      *
170      * @return String with the AIM ID
171      */

172     public String JavaDoc getAim() {
173         return this.aim;
174     }
175
176     /**
177      * Gets the avatar of the user
178      *
179      * @return String with the avatar
180      */

181     public String JavaDoc getAvatar() {
182         return this.avatar;
183     }
184
185     /**
186      * Checks if avatar is enabled
187      *
188      * @return boolean value
189      */

190     public boolean isAvatarEnabled() {
191         return this.avatarEnabled;
192     }
193
194     /**
195      * Checks if BB code is enabled
196      *
197      * @return boolean value
198      */

199     public boolean isBbCodeEnabled() {
200         return this.bbCodeEnabled;
201     }
202
203     /**
204      * Gets the format to represent dates and time
205      *
206      * @return String with the format
207      */

208     public String JavaDoc getDateFormat() {
209         return this.dateFormat;
210     }
211
212     /**
213      * Gets the user email
214      *
215      * @return String with the email
216      */

217     public String JavaDoc getEmail() {
218         return this.email;
219     }
220
221     /**
222      * Gets the user location ( where he lives )
223      *
224      * @return String with the location
225      */

226     public String JavaDoc getFrom() {
227         return this.from;
228     }
229
230     /**
231      * Gets the user gender
232      *
233      * @return String value. Possible values are <code>M</code> or <code>F</code>
234      */

235     public String JavaDoc getGender() {
236         return this.gender;
237     }
238
239     /**
240      * Checks if HTML code is enabled by default in user messages
241      *
242      * @return boolean value
243      */

244     public boolean isHtmlEnabled() {
245         return this.htmlEnabled;
246     }
247
248     /**
249      * Gets the ICQ UIM
250      *
251      * @return String with the UIN
252      */

253     public String JavaDoc getIcq() {
254         return this.icq;
255     }
256
257     /**
258      * Gets the user id
259      *
260      * @return int value with the id
261      */

262     public int getId() {
263         return this.id;
264     }
265
266     /**
267      * Gets the user interests
268      *
269      * @return String literal
270      */

271     public String JavaDoc getInterests() {
272         return this.interests;
273     }
274
275     /**
276      * Gets the user language
277      *
278      * @return String value with the language chosen
279      */

280     public String JavaDoc getLang() {
281         return this.lang;
282     }
283
284     /**
285      * Gets the last visit time the user was in the forum
286      *
287      * @return long value representing the time
288      */

289     public Date JavaDoc getLastVisit() {
290         return this.lastVisit;
291     }
292
293     /**
294      * Gets the user leve
295      *
296      * @return int value with the level
297      */

298     public int getLevel() {
299         return this.level;
300     }
301
302     /**
303      * Checks if notification of new private messages is enabled
304      *
305      * @return boolean value
306      */

307     public boolean isNotifyPrivateMessagesEnabled() {
308         return this.notifyPrivateMessagesEnabled;
309     }
310
311     /**
312      * Gets the OCC
313      *
314      * @return String
315      */

316     public String JavaDoc getOccupation() {
317         return this.occupation;
318     }
319
320     /**
321      * Gets the user password
322      *
323      * @return String with the password ( in plain/text )
324      */

325     public String JavaDoc getPassword() {
326         return this.password;
327     }
328
329     /**
330      * Checks if user permits other people to sent private messages to him
331      *
332      * @return boolean value
333      */

334     public boolean isPrivateMessagesEnabled() {
335         return this.privateMessagesEnabled;
336     }
337
338     /**
339      * Gets the ranking ID of the user
340      *
341      * @return int
342      */

343     public int getRankId() {
344         return this.rankId;
345     }
346
347     /**
348      * Gets the registration date of the user
349      *
350      * @return String value with the registration date
351      */

352     public String JavaDoc getRegistrationDate()
353     {
354         SimpleDateFormat JavaDoc df = new SimpleDateFormat JavaDoc(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
355
356         return df.format(this.registrationDate);
357     }
358
359     /**
360      * Gets the user signature
361      *
362      * @return String literal with the signature
363      */

364     public String JavaDoc getSignature() {
365         return this.signature;
366     }
367
368     /**
369      * Checks if smilies are enabled
370      *
371      * @return boolean value
372      */

373     public boolean isSmiliesEnabled() {
374         return this.smiliesEnabled;
375     }
376     
377     /**
378      * Gets the id of the theme chosen by the user
379      *
380      * @return int value with the theme ID
381      */

382     public int getThemeId() {
383         return this.themeId;
384     }
385
386     /**
387      * Gets the timezone
388      *
389      * @return String value with the timezone
390      */

391     public String JavaDoc getTimeZone() {
392         return this.timeZone;
393     }
394
395     /**
396      * Gets the total number of messages posted by the user
397      *
398      * @return int value with the total of messages
399      */

400     public int getTotalPosts() {
401         return this.totalPosts;
402     }
403
404     /**
405      * Gets the username
406      *
407      * @return String with the username
408      */

409     public String JavaDoc getUsername() {
410         return this.username;
411     }
412
413     /**
414      * Checks if the user permits other people to see he online
415      *
416      * @return boolean value
417      */

418     public boolean isViewOnlineEnabled() {
419         return this.viewOnlineEnabled;
420     }
421
422     /**
423      * Gets the user website address
424      *
425      * @return String with the URL
426      */

427     public String JavaDoc getWebSite() {
428         return this.webSite;
429     }
430
431     /**
432      * Gets the Yahoo messenger ID
433      *
434      * @return String with the ID
435      */

436     public String JavaDoc getYim() {
437         return this.yim;
438     }
439
440     /**
441      * Is the user's email authenticated?
442      *
443      * @return integer 1 if true
444      */

445     public boolean isActive(){
446         return this.active == 1;
447     }
448     
449     /**
450      * Gets the Yahoo messenger ID
451      *
452      * @return String with the activation key that is created during user registration
453      */

454     public String JavaDoc getActivationKey(){
455         return this.activationKey;
456     }
457     
458     /**
459      * Sets the aim.
460      *
461      * @param aim The aim ID to set
462      */

463     public void setAim(String JavaDoc aim) {
464         this.aim = aim;
465     }
466
467     /**
468      * Sets the avatar.
469      *
470      * @param avatar The avatar to set
471      */

472     public void setAvatar(String JavaDoc avatar) {
473         this.avatar = avatar;
474         
475         if (avatar != null && avatar.toLowerCase().startsWith("http://")) {
476             this.isExternalAvatar = true;
477         }
478     }
479
480     /**
481      * Indicates if the avatar points to an external URL
482      * @return <code>true</code> if the avatar is some external image
483      */

484     public boolean isExternalAvatar() {
485         return this.isExternalAvatar;
486     }
487
488     /**
489      * Sets avatar status
490      *
491      * @param avatarEnabled <code>true</code> or <code>false</code>
492      */

493     public void setAvatarEnabled(boolean avatarEnabled) {
494         this.avatarEnabled = avatarEnabled;
495     }
496
497     /**
498      * Sets the status for BB codes
499      *
500      * @param bbCodeEnabled <code>true</code> or <code>false</code>
501      */

502     public void setBbCodeEnabled(boolean bbCodeEnabled) {
503         this.bbCodeEnabled = bbCodeEnabled;
504     }
505
506     /**
507      * Sets the date format.
508      *
509      * @param dateFormat The date format to set
510      */

511     public void setDateFormat(String JavaDoc dateFormat) {
512         this.dateFormat = dateFormat;
513     }
514
515     /**
516      * Sets the email.
517      *
518      * @param email The email to set
519      */

520     public void setEmail(String JavaDoc email) {
521         this.email = email;
522     }
523
524     /**
525      * Sets the user location ( where he lives )
526      *
527      * @param from The location
528      */

529     public void setFrom(String JavaDoc from) {
530         this.from = from;
531     }
532
533     /**
534      * Sets the gender.
535      *
536      * @param gender The gender to set. Possible values must be <code>M</code> or <code>F</code>
537      */

538     public void setGender(String JavaDoc gender) {
539         this.gender = gender;
540     }
541
542     /**
543      * Enable or not HTML code into the messages
544      *
545      * @param htmlEnabled <code>true</code> or <code>false</code>
546      */

547     public void setHtmlEnabled(boolean htmlEnabled) {
548         this.htmlEnabled = htmlEnabled;
549     }
550
551     /**
552      * Sets the icq UIN
553      *
554      * @param icq The icq to set
555      */

556     public void setIcq(String JavaDoc icq) {
557         this.icq = icq;
558     }
559
560     /**
561      * Sets the user id.
562      *
563      * @param id The user id to set
564      */

565     public void setId(int id) {
566         this.id = id;
567     }
568
569     /**
570      * Sets the interests.
571      *
572      * @param interests The interests to set
573      */

574     public void setInterests(String JavaDoc interests) {
575         this.interests = interests;
576     }
577
578     /**
579      * Sets the language.
580      *
581      * @param lang The lang to set
582      */

583     public void setLang(String JavaDoc lang) {
584         this.lang = lang;
585     }
586
587     /**
588      * Sets the last visit time
589      *
590      * @param lastVisit Last visit time, represented as a long value
591      */

592     public void setLastVisit(Date JavaDoc lastVisit) {
593         this.lastVisit = lastVisit;
594     }
595
596     /**
597      * Sets the level.
598      *
599      * @param level The level to set
600      */

601     public void setLevel(int level) {
602         this.level = level;
603     }
604
605     /**
606      * Sets the status for notification of new private messages
607      *
608      * @param notifyPrivateMessagesEnabled <code>true</code> or <code>false</code>
609      */

610     public void setNotifyPrivateMessagesEnabled(boolean notifyPrivateMessagesEnabled) {
611         this.notifyPrivateMessagesEnabled = notifyPrivateMessagesEnabled;
612     }
613
614     /**
615      * Sets the occ.
616      *
617      * @param occ The occ to set
618      */

619     public void setOccupation(String JavaDoc occupation) {
620         this.occupation = occupation;
621     }
622
623     /**
624      * Sets the password.
625      *
626      * @param password The password to set
627      */

628     public void setPassword(String JavaDoc password) {
629         this.password = password;
630     }
631
632     /**
633      * Enable or not private messages to the user
634      *
635      * @param privateMessagesEnabled <code>true</code> or <code>false</code>
636      */

637     public void setPrivateMessagesEnabled(boolean privateMessagesEnabled) {
638         this.privateMessagesEnabled = privateMessagesEnabled;
639     }
640
641     /**
642      * Sets the ranking id
643      *
644      * @param rankId The id of the ranking
645      */

646     public void setRankId(int rankId) {
647         this.rankId = rankId;
648     }
649
650     /**
651      * Sets the registration date.
652      *
653      * @param registrationDate The registration date to set
654      */

655     public void setRegistrationDate(Date JavaDoc registrationDate) {
656         this.registrationDate = registrationDate;
657     }
658
659     /**
660      * Sets the signature.
661      *
662      * @param signature The signature to set
663      */

664     public void setSignature(String JavaDoc signature) {
665         this.signature = signature;
666     }
667
668     /**
669      * Enable or not smilies in messages
670      *
671      * @param smilesEnabled <code>true</code> or <code>false</code>
672      */

673     public void setSmiliesEnabled(boolean smilesEnabled) {
674         this.smiliesEnabled = smilesEnabled;
675     }
676
677     /**
678      * Sets the theme id
679      *
680      * @param themeId The theme Id to set
681      */

682     public void setThemeId(int themeId) {
683         this.themeId = themeId;
684     }
685
686     /**
687      * Sets the Timezone.
688      *
689      * @param timeZone The Timezone to set
690      */

691     public void setTimeZone(String JavaDoc timeZone) {
692         this.timeZone = timeZone;
693     }
694
695     /**
696      * Sets the total number of posts by the user
697      *
698      * @param totalPosts int value with the total of messages posted by the user
699      */

700     public void setTotalPosts(int totalPosts) {
701         this.totalPosts = totalPosts;
702     }
703
704     /**
705      * Sets the username.
706      *
707      * @param username The username to set
708      */

709     public void setUsername(String JavaDoc username) {
710         this.username = username;
711     }
712
713     /**
714      * Sets the viewOnlineEnabled.
715      * @param viewOnlineEnabled The viewOnlineEnabled to set
716      */

717     public void setViewOnlineEnabled(boolean viewOnlineEnabled) {
718         this.viewOnlineEnabled = viewOnlineEnabled;
719     }
720
721     /**
722      * Sets the webSite.
723      *
724      * @param webSite The webSite to set
725      */

726     public void setWebSite(String JavaDoc webSite) {
727         this.webSite = webSite;
728     }
729
730     /**
731      * Sets the Yahoo messenger ID
732      *
733      * @param yim The yim to set
734      */

735     public void setYim(String JavaDoc yim) {
736         this.yim = yim;
737     }
738
739     /**
740      * @return
741      */

742     public String JavaDoc getMsnm() {
743         return this.msnm;
744     }
745
746     /**
747      * @param string
748      */

749     public void setMsnm(String JavaDoc string) {
750         this.msnm = string;
751     }
752
753     /**
754      * @return
755      */

756     public boolean isNotifyOnMessagesEnabled() {
757         return this.notifyOnMessagesEnabled;
758     }
759
760     /**
761      * @param b
762      */

763     public void setNotifyOnMessagesEnabled(boolean b) {
764         this.notifyOnMessagesEnabled = b;
765     }
766
767     /**
768      * @return
769      */

770     public boolean isViewEmailEnabled() {
771         return this.viewEmailEnabled;
772     }
773
774     /**
775      * @param b
776      */

777     public void setViewEmailEnabled(boolean b) {
778         this.viewEmailEnabled = b;
779     }
780
781     /**
782      * @return
783      */

784     public boolean getAttachSignatureEnabled() {
785         return this.attachSignatureEnabled;
786     }
787
788     /**
789      * @param b
790      */

791     public void setAttachSignatureEnabled(boolean b) {
792         this.attachSignatureEnabled = b;
793     }
794
795     /**
796      * @return
797      */

798     public List JavaDoc getGroupsList() {
799         return this.groupsList;
800     }
801
802     /**
803      * @return Returns the privateMessagesCount.
804      */

805     public int getPrivateMessagesCount()
806     {
807         return this.privateMessagesCount;
808     }
809     /**
810      * @param privateMessagesCount The privateMessagesCount to set.
811      */

812     public void setPrivateMessagesCount(int privateMessagesCount)
813     {
814         this.privateMessagesCount = privateMessagesCount;
815     }
816     /**
817      * @return Returns the hasPrivateMessages.
818      */

819     public boolean hasPrivateMessages()
820     {
821         return this.privateMessagesCount > 0;
822     }
823     
824     /**
825      * Set when user authenticates his email after user registration
826     */

827     public void setActive(int active){
828         this.active = active;
829     }
830     
831     public void setActivationKey(String JavaDoc activationKey){
832         this.activationKey = activationKey;
833     }
834     
835     public void setKarma(KarmaStatus karma)
836     {
837         this.karma = karma;
838     }
839     
840     public KarmaStatus getKarma()
841     {
842         return this.karma;
843     }
844     
845     /**
846      * Is the user online?
847      *
848      * @return true if user is in Session
849      */

850     public boolean isOnline()
851     {
852         return (SessionFacade.isUserInSession(this.id) != null);
853     }
854
855     /**
856      * Gets the user's biography
857      * @return the user biography
858      */

859     public String JavaDoc getBiography() {
860         return biography;
861     }
862
863     /**
864      * Sets the user's biography
865      * @param biography the user's biography
866      */

867     public void setBiography(String JavaDoc biography) {
868         this.biography = biography;
869     }
870 }
871
Popular Tags