001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * This file creating date: Feb 17, 2003 / 10:25:04 PM
040: * The JForum Project
041: * http://www.jforum.net
042: *
043: * $Id: User.java,v 1.21 2007/07/25 03:08:15 rafaelsteil Exp $
044: */
045: package net.jforum.entities;
046:
047: import java.io.Serializable;
048: import java.text.SimpleDateFormat;
049: import java.util.ArrayList;
050: import java.util.Date;
051: import java.util.HashMap;
052: import java.util.List;
053: import java.util.Map;
054:
055: import net.jforum.SessionFacade;
056: import net.jforum.util.preferences.ConfigKeys;
057: import net.jforum.util.preferences.SystemGlobals;
058:
059: /**
060: * Represents a single user in the system.
061: * An user is every person which uses the forum. Well,
062: * every registered user. Anonymous users does not have
063: * a specific ID, for example. This class contains all information
064: * about some user configuration options and preferences.
065: *
066: * @author Rafael Steil
067: */
068: public class User implements Serializable {
069: private int id;
070: private int themeId;
071: private int level;
072: private int totalPosts;
073: private boolean attachSignatureEnabled = true;
074: private int rankId = 1;
075: private boolean htmlEnabled = true;
076: private boolean bbCodeEnabled = true;
077: private boolean smiliesEnabled = true;
078: private boolean avatarEnabled = true;
079: private boolean privateMessagesEnabled = true;
080: private boolean viewOnlineEnabled = true;
081: private boolean notifyPrivateMessagesEnabled = true;
082: private boolean notifyOnMessagesEnabled = true;
083: private boolean notifyAlways;
084: private boolean notifyText;
085: private String username;
086: private String password;
087: private Date lastVisit;
088: private Date registrationDate;
089: private String avatar;
090: private boolean isExternalAvatar;
091: private String email;
092: private String icq;
093: private String webSite;
094: private String from;
095: private String signature;
096: private String aim;
097: private String yim;
098: private String msnm;
099: private String occupation;
100: private String interests;
101: private String biography;
102: private String gender;
103: private String timeZone;
104: private String lang;
105: private String dateFormat;
106: private boolean viewEmailEnabled = true;
107: private List groupsList;
108: private int privateMessagesCount;
109: private KarmaStatus karma;
110: private int active;
111: private String activationKey;
112: private int deleted;
113: private String firstName;
114: private String lastName;
115: private Map extra = new HashMap();
116:
117: public User(int userId) {
118: this .id = userId;
119: }
120:
121: /**
122: * Default Constructor
123: */
124: public User() {
125: this .groupsList = new ArrayList();
126: }
127:
128: public void addExtra(String name, Object value) {
129: this .extra.put(name, value);
130: }
131:
132: public Object getExtra(String name) {
133: return this .extra.get(name);
134: }
135:
136: public void setFirstName(String name) {
137: this .firstName = name;
138: }
139:
140: public String getFirstName() {
141: return this .firstName;
142: }
143:
144: public void setLastName(String name) {
145: this .lastName = name;
146: }
147:
148: public String getLastNmame() {
149: return this .lastName;
150: }
151:
152: public String getName() {
153: return this .firstName + " " + this .lastName;
154: }
155:
156: public boolean isDeleted() {
157: return this .deleted == 1;
158: }
159:
160: public void setDeleted(int deleted) {
161: this .deleted = deleted;
162: }
163:
164: /**
165: * Gets the AIM identification
166: *
167: * @return String with the AIM ID
168: */
169: public String getAim() {
170: return this .aim;
171: }
172:
173: /**
174: * Gets the avatar of the user
175: *
176: * @return String with the avatar
177: */
178: public String getAvatar() {
179: return this .avatar;
180: }
181:
182: /**
183: * Checks if avatar is enabled
184: *
185: * @return boolean value
186: */
187: public boolean isAvatarEnabled() {
188: return this .avatarEnabled;
189: }
190:
191: /**
192: * Checks if BB code is enabled
193: *
194: * @return boolean value
195: */
196: public boolean isBbCodeEnabled() {
197: return this .bbCodeEnabled;
198: }
199:
200: /**
201: * Gets the format to represent dates and time
202: *
203: * @return String with the format
204: */
205: public String getDateFormat() {
206: return this .dateFormat;
207: }
208:
209: /**
210: * Gets the user email
211: *
212: * @return String with the email
213: */
214: public String getEmail() {
215: return this .email;
216: }
217:
218: /**
219: * Gets the user location ( where he lives )
220: *
221: * @return String with the location
222: */
223: public String getFrom() {
224: return this .from;
225: }
226:
227: /**
228: * Gets the user gender
229: *
230: * @return String value. Possible values are <code>M</code> or <code>F</code>
231: */
232: public String getGender() {
233: return this .gender;
234: }
235:
236: /**
237: * Checks if HTML code is enabled by default in user messages
238: *
239: * @return boolean value
240: */
241: public boolean isHtmlEnabled() {
242: return this .htmlEnabled;
243: }
244:
245: /**
246: * Gets the ICQ UIM
247: *
248: * @return String with the UIN
249: */
250: public String getIcq() {
251: return this .icq;
252: }
253:
254: /**
255: * Gets the user id
256: *
257: * @return int value with the id
258: */
259: public int getId() {
260: return this .id;
261: }
262:
263: /**
264: * Gets the user interests
265: *
266: * @return String literal
267: */
268: public String getInterests() {
269: return this .interests;
270: }
271:
272: /**
273: * Gets the user language
274: *
275: * @return String value with the language chosen
276: */
277: public String getLang() {
278: return this .lang;
279: }
280:
281: /**
282: * Gets the last visit time the user was in the forum
283: *
284: * @return long value representing the time
285: */
286: public Date getLastVisit() {
287: return this .lastVisit;
288: }
289:
290: /**
291: * Gets the user leve
292: *
293: * @return int value with the level
294: */
295: public int getLevel() {
296: return this .level;
297: }
298:
299: /**
300: * Checks if notification of new private messages is enabled
301: *
302: * @return boolean value
303: */
304: public boolean isNotifyPrivateMessagesEnabled() {
305: return this .notifyPrivateMessagesEnabled;
306: }
307:
308: /**
309: * Gets the OCC
310: *
311: * @return String
312: */
313: public String getOccupation() {
314: return this .occupation;
315: }
316:
317: /**
318: * Gets the user password
319: *
320: * @return String with the password ( in plain/text )
321: */
322: public String getPassword() {
323: return this .password;
324: }
325:
326: /**
327: * Checks if user permits other people to sent private messages to him
328: *
329: * @return boolean value
330: */
331: public boolean isPrivateMessagesEnabled() {
332: return this .privateMessagesEnabled;
333: }
334:
335: /**
336: * Gets the ranking ID of the user
337: *
338: * @return int
339: */
340: public int getRankId() {
341: return this .rankId;
342: }
343:
344: /**
345: * Gets the registration date of the user
346: *
347: * @return String value with the registration date
348: */
349: public String getRegistrationDate() {
350: SimpleDateFormat df = new SimpleDateFormat(SystemGlobals
351: .getValue(ConfigKeys.DATE_TIME_FORMAT));
352:
353: return df.format(this .registrationDate);
354: }
355:
356: /**
357: * Gets the user signature
358: *
359: * @return String literal with the signature
360: */
361: public String getSignature() {
362: return this .signature;
363: }
364:
365: /**
366: * Checks if smilies are enabled
367: *
368: * @return boolean value
369: */
370: public boolean isSmiliesEnabled() {
371: return this .smiliesEnabled;
372: }
373:
374: /**
375: * Gets the id of the theme chosen by the user
376: *
377: * @return int value with the theme ID
378: */
379: public int getThemeId() {
380: return this .themeId;
381: }
382:
383: /**
384: * Gets the timezone
385: *
386: * @return String value with the timezone
387: */
388: public String getTimeZone() {
389: return this .timeZone;
390: }
391:
392: /**
393: * Gets the total number of messages posted by the user
394: *
395: * @return int value with the total of messages
396: */
397: public int getTotalPosts() {
398: return this .totalPosts;
399: }
400:
401: /**
402: * Gets the username
403: *
404: * @return String with the username
405: */
406: public String getUsername() {
407: return this .username;
408: }
409:
410: /**
411: * Checks if the user permits other people to see he online
412: *
413: * @return boolean value
414: */
415: public boolean isViewOnlineEnabled() {
416: return this .viewOnlineEnabled;
417: }
418:
419: /**
420: * Gets the user website address
421: *
422: * @return String with the URL
423: */
424: public String getWebSite() {
425: return this .webSite;
426: }
427:
428: /**
429: * Gets the Yahoo messenger ID
430: *
431: * @return String with the ID
432: */
433: public String getYim() {
434: return this .yim;
435: }
436:
437: /**
438: * Is the user's email authenticated?
439: *
440: * @return integer 1 if true
441: */
442: public boolean isActive() {
443: return this .active == 1;
444: }
445:
446: /**
447: * Gets the Yahoo messenger ID
448: *
449: * @return String with the activation key that is created during user registration
450: */
451: public String getActivationKey() {
452: return this .activationKey;
453: }
454:
455: /**
456: * Sets the aim.
457: *
458: * @param aim The aim ID to set
459: */
460: public void setAim(String aim) {
461: this .aim = aim;
462: }
463:
464: /**
465: * Sets the avatar.
466: *
467: * @param avatar The avatar to set
468: */
469: public void setAvatar(String avatar) {
470: this .avatar = avatar;
471:
472: if (avatar != null
473: && avatar.toLowerCase().startsWith("http://")) {
474: this .isExternalAvatar = true;
475: }
476: }
477:
478: /**
479: * Indicates if the avatar points to an external URL
480: * @return <code>true</code> if the avatar is some external image
481: */
482: public boolean isExternalAvatar() {
483: return this .isExternalAvatar;
484: }
485:
486: /**
487: * Sets avatar status
488: *
489: * @param avatarEnabled <code>true</code> or <code>false</code>
490: */
491: public void setAvatarEnabled(boolean avatarEnabled) {
492: this .avatarEnabled = avatarEnabled;
493: }
494:
495: /**
496: * Sets the status for BB codes
497: *
498: * @param bbCodeEnabled <code>true</code> or <code>false</code>
499: */
500: public void setBbCodeEnabled(boolean bbCodeEnabled) {
501: this .bbCodeEnabled = bbCodeEnabled;
502: }
503:
504: /**
505: * Sets the date format.
506: *
507: * @param dateFormat The date format to set
508: */
509: public void setDateFormat(String dateFormat) {
510: this .dateFormat = dateFormat;
511: }
512:
513: /**
514: * Sets the email.
515: *
516: * @param email The email to set
517: */
518: public void setEmail(String email) {
519: this .email = email;
520: }
521:
522: /**
523: * Sets the user location ( where he lives )
524: *
525: * @param from The location
526: */
527: public void setFrom(String from) {
528: this .from = from;
529: }
530:
531: /**
532: * Sets the gender.
533: *
534: * @param gender The gender to set. Possible values must be <code>M</code> or <code>F</code>
535: */
536: public void setGender(String gender) {
537: this .gender = gender;
538: }
539:
540: /**
541: * Enable or not HTML code into the messages
542: *
543: * @param htmlEnabled <code>true</code> or <code>false</code>
544: */
545: public void setHtmlEnabled(boolean htmlEnabled) {
546: this .htmlEnabled = htmlEnabled;
547: }
548:
549: /**
550: * Sets the icq UIN
551: *
552: * @param icq The icq to set
553: */
554: public void setIcq(String icq) {
555: this .icq = icq;
556: }
557:
558: /**
559: * Sets the user id.
560: *
561: * @param id The user id to set
562: */
563: public void setId(int id) {
564: this .id = id;
565: }
566:
567: /**
568: * Sets the interests.
569: *
570: * @param interests The interests to set
571: */
572: public void setInterests(String interests) {
573: this .interests = interests;
574: }
575:
576: /**
577: * Sets the language.
578: *
579: * @param lang The lang to set
580: */
581: public void setLang(String lang) {
582: this .lang = lang;
583: }
584:
585: /**
586: * Sets the last visit time
587: *
588: * @param lastVisit Last visit time, represented as a long value
589: */
590: public void setLastVisit(Date lastVisit) {
591: this .lastVisit = lastVisit;
592: }
593:
594: /**
595: * Sets the level.
596: *
597: * @param level The level to set
598: */
599: public void setLevel(int level) {
600: this .level = level;
601: }
602:
603: /**
604: * Sets the status for notification of new private messages
605: *
606: * @param notifyPrivateMessagesEnabled <code>true</code> or <code>false</code>
607: */
608: public void setNotifyPrivateMessagesEnabled(
609: boolean notifyPrivateMessagesEnabled) {
610: this .notifyPrivateMessagesEnabled = notifyPrivateMessagesEnabled;
611: }
612:
613: /**
614: * Sets the occ.
615: *
616: * @param occ The occ to set
617: */
618: public void setOccupation(String occupation) {
619: this .occupation = occupation;
620: }
621:
622: /**
623: * Sets the password.
624: *
625: * @param password The password to set
626: */
627: public void setPassword(String password) {
628: this .password = password;
629: }
630:
631: /**
632: * Enable or not private messages to the user
633: *
634: * @param privateMessagesEnabled <code>true</code> or <code>false</code>
635: */
636: public void setPrivateMessagesEnabled(boolean privateMessagesEnabled) {
637: this .privateMessagesEnabled = privateMessagesEnabled;
638: }
639:
640: /**
641: * Sets the ranking id
642: *
643: * @param rankId The id of the ranking
644: */
645: public void setRankId(int rankId) {
646: this .rankId = rankId;
647: }
648:
649: /**
650: * Sets the registration date.
651: *
652: * @param registrationDate The registration date to set
653: */
654: public void setRegistrationDate(Date registrationDate) {
655: this .registrationDate = registrationDate;
656: }
657:
658: /**
659: * Sets the signature.
660: *
661: * @param signature The signature to set
662: */
663: public void setSignature(String signature) {
664: this .signature = signature;
665: }
666:
667: /**
668: * Enable or not smilies in messages
669: *
670: * @param smilesEnabled <code>true</code> or <code>false</code>
671: */
672: public void setSmiliesEnabled(boolean smilesEnabled) {
673: this .smiliesEnabled = smilesEnabled;
674: }
675:
676: /**
677: * Sets the theme id
678: *
679: * @param themeId The theme Id to set
680: */
681: public void setThemeId(int themeId) {
682: this .themeId = themeId;
683: }
684:
685: /**
686: * Sets the Timezone.
687: *
688: * @param timeZone The Timezone to set
689: */
690: public void setTimeZone(String timeZone) {
691: this .timeZone = timeZone;
692: }
693:
694: /**
695: * Sets the total number of posts by the user
696: *
697: * @param totalPosts int value with the total of messages posted by the user
698: */
699: public void setTotalPosts(int totalPosts) {
700: this .totalPosts = totalPosts;
701: }
702:
703: /**
704: * Sets the username.
705: *
706: * @param username The username to set
707: */
708: public void setUsername(String username) {
709: this .username = username;
710: }
711:
712: /**
713: * Sets the viewOnlineEnabled.
714: * @param viewOnlineEnabled The viewOnlineEnabled to set
715: */
716: public void setViewOnlineEnabled(boolean viewOnlineEnabled) {
717: this .viewOnlineEnabled = viewOnlineEnabled;
718: }
719:
720: /**
721: * Sets the webSite.
722: *
723: * @param webSite The webSite to set
724: */
725: public void setWebSite(String webSite) {
726: this .webSite = webSite;
727: }
728:
729: /**
730: * Sets the Yahoo messenger ID
731: *
732: * @param yim The yim to set
733: */
734: public void setYim(String yim) {
735: this .yim = yim;
736: }
737:
738: /**
739: * @return
740: */
741: public String getMsnm() {
742: return this .msnm;
743: }
744:
745: /**
746: * @param string
747: */
748: public void setMsnm(String string) {
749: this .msnm = string;
750: }
751:
752: /**
753: * @return
754: */
755: public boolean isNotifyOnMessagesEnabled() {
756: return this .notifyOnMessagesEnabled;
757: }
758:
759: /**
760: * @param b
761: */
762: public void setNotifyOnMessagesEnabled(boolean b) {
763: this .notifyOnMessagesEnabled = b;
764: }
765:
766: /**
767: * @return
768: */
769: public boolean isViewEmailEnabled() {
770: return this .viewEmailEnabled;
771: }
772:
773: /**
774: * @param b
775: */
776: public void setViewEmailEnabled(boolean b) {
777: this .viewEmailEnabled = b;
778: }
779:
780: /**
781: * @return
782: */
783: public boolean getAttachSignatureEnabled() {
784: return this .attachSignatureEnabled;
785: }
786:
787: /**
788: * @param b
789: */
790: public void setAttachSignatureEnabled(boolean b) {
791: this .attachSignatureEnabled = b;
792: }
793:
794: /**
795: * @return
796: */
797: public List getGroupsList() {
798: return this .groupsList;
799: }
800:
801: /**
802: * @return Returns the privateMessagesCount.
803: */
804: public int getPrivateMessagesCount() {
805: return this .privateMessagesCount;
806: }
807:
808: /**
809: * @param privateMessagesCount The privateMessagesCount to set.
810: */
811: public void setPrivateMessagesCount(int privateMessagesCount) {
812: this .privateMessagesCount = privateMessagesCount;
813: }
814:
815: /**
816: * @return Returns the hasPrivateMessages.
817: */
818: public boolean hasPrivateMessages() {
819: return this .privateMessagesCount > 0;
820: }
821:
822: /**
823: * Set when user authenticates his email after user registration
824: */
825: public void setActive(int active) {
826: this .active = active;
827: }
828:
829: public void setActivationKey(String activationKey) {
830: this .activationKey = activationKey;
831: }
832:
833: public void setKarma(KarmaStatus karma) {
834: this .karma = karma;
835: }
836:
837: public KarmaStatus getKarma() {
838: return this .karma;
839: }
840:
841: /**
842: * Is the user online?
843: *
844: * @return true if user is in Session
845: */
846: public boolean isOnline() {
847: return (SessionFacade.isUserInSession(this .id) != null);
848: }
849:
850: /**
851: * Gets the user's biography
852: * @return the user biography
853: */
854: public String getBiography() {
855: return biography;
856: }
857:
858: /**
859: * Sets the user's biography
860: * @param biography the user's biography
861: */
862: public void setBiography(String biography) {
863: this .biography = biography;
864: }
865:
866: /**
867: * @return the notifyAlways
868: */
869: public boolean notifyAlways() {
870: return this .notifyAlways;
871: }
872:
873: /**
874: * @return the notifyText
875: */
876: public boolean notifyText() {
877: return this .notifyText;
878: }
879:
880: /**
881: * @param notifyAlways the notifyAlways to set
882: */
883: public void setNotifyAlways(boolean notifyAlways) {
884: this .notifyAlways = notifyAlways;
885: }
886:
887: /**
888: * @param notifyText the notifyText to set
889: */
890: public void setNotifyText(boolean notifyText) {
891: this.notifyText = notifyText;
892: }
893: }
|