001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * any nuclear facility.
035: */
036:
037: package com.sun.portal.app.communityportlets.faces;
038:
039: import com.sun.portal.community.RoleId;
040:
041: /**
042: * A object represent a user.
043: */
044: public class User {
045: private String id = null;
046: private String first = null; // First name.
047: private String last = null; // Last name.
048: private boolean selected = false; // Used only when maintaining state.
049: private String name = null;
050: private String email = null;
051: private boolean foundInAuthModule;
052: private RoleId roleId = RoleId.VISITOR_ROLE;
053:
054: /**
055: * Creates a new instance of Membership
056: */
057: public User(String id, String name, String email, RoleId roleId) {
058: this .id = id;
059: this .name = name;
060: this .email = email;
061: this .setRoleId(roleId);
062: }
063:
064: /**
065: * Default constructor.
066: * @param id The id of a user.
067: * @param name Name of a user
068: */
069: public User(String id, String name) {
070: this .id = id;
071: if (name == null || name.length() == 0) {
072: this .name = id;
073: } else {
074: this .name = name;
075: }
076: }
077:
078: /**
079: * Get Id.
080: * @return return user id.
081: */
082: public String getId() {
083: return id;
084: }
085:
086: /**
087: * Return uid if the id was in the form of DN.
088: * For example, uid=John,ou=People,o=sun,o=com
089: * @return uid
090: */
091: public String getUid() {
092: int s = id.indexOf("=") + 1;
093: int e = id.indexOf(",");
094: if (s > 0 && e > 0 && e > s) {
095: return id.substring(s, e);
096: } else {
097: return id;
098: }
099: }
100:
101: /**
102: * Get full name.
103: * @return The user's full name
104: */
105: public String getName() {
106: return name;
107: }
108:
109: /**
110: * Set full name.
111: * @param value user's full name
112: */
113: public void setName(String value) {
114: name = value;
115: }
116:
117: /**
118: * Get first name.
119: * @return user's first name
120: */
121: public String getFirst() {
122: return first;
123: }
124:
125: /**
126: * Set first name.
127: * @param value user's first name
128: */
129: public void setFirst(String value) {
130: first = value;
131: }
132:
133: /**
134: * Get last name.
135: * @return user's last name
136: */
137: public String getLast() {
138: return last;
139: }
140:
141: /**
142: * Set last name.
143: * @param value user's last name
144: */
145: public void setLast(String value) {
146: last = value;
147: }
148:
149: /**
150: * Get selected property -- see Select util.
151: * @return true - if a user is slelected.
152: */
153: public boolean isSelected() {
154: return selected;
155: }
156:
157: /**
158: * Set selected property -- see Select util.
159: * @param value true - if the item was selected
160: */
161: public void setSelected(boolean value) {
162: selected = value;
163: }
164:
165: /**
166: * Getting a user's email
167: * @return user's email
168: */
169: public String getEmail() {
170: return email;
171: }
172:
173: /**
174: * Setting a user's email
175: * @param email user's email
176: */
177: public void setEmail(String email) {
178: this .email = email;
179: }
180:
181: public boolean isFoundInAuthModule() {
182: return foundInAuthModule;
183: }
184:
185: public void setFoundInAuthModule(boolean foundInAuthModule) {
186: this .foundInAuthModule = foundInAuthModule;
187: }
188:
189: /**
190: * Return user's role in current community.
191: * @return Role in current community
192: */
193: public RoleId getRoleId() {
194: return roleId;
195: }
196:
197: public void setRoleId(RoleId roleId) {
198: this .roleId = roleId;
199: }
200:
201: /**
202: * Status of a user being visitor
203: * @return true - if a user is not assoicated with any role in current community.
204: */
205: public boolean isVisitor() {
206: return (RoleId.VISITOR_ROLE.equals(roleId));
207: }
208: }
|