KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Profile


1 import whisper.PublicKey;
2
3 /** A user profile.
4 * The fields are public, to avoid writing monotonous get/set methods.*/

5 public final class Profile{
6     public String JavaDoc JabberID=new String JavaDoc("");
7     public String JavaDoc FullName=new String JavaDoc("");
8     public String JavaDoc NickName=new String JavaDoc("");
9     public String JavaDoc Birthday=new String JavaDoc("");
10     public String JavaDoc Email=new String JavaDoc("");
11     public String JavaDoc HomePage=new String JavaDoc("");
12     public String JavaDoc Phone=new String JavaDoc("");
13     public String JavaDoc Street=new String JavaDoc("");
14     public String JavaDoc City=new String JavaDoc("");
15     public String JavaDoc State=new String JavaDoc("");
16     public String JavaDoc PostCode=new String JavaDoc("");
17     public String JavaDoc Country=new String JavaDoc("");
18     public String JavaDoc Company=new String JavaDoc("");
19     public String JavaDoc Department=new String JavaDoc("");
20     public String JavaDoc Position=new String JavaDoc("");
21     public String JavaDoc Role=new String JavaDoc("");
22     public String JavaDoc Notes=new String JavaDoc("");
23     
24     /** Creates a new blank profile.*/
25     public Profile(){
26         // nothing to do
27
}
28     
29     /** Creates a new profile based on a vcard.
30     * @param vcard A vCard to base the profile on.
31     * @exception IllegalArgumentException If vcard does not contain a valid vCard.*/

32     public Profile(VCard vcard) throws IllegalArgumentException JavaDoc{
33         setFromVCard(vcard);
34     }
35     
36     public void setFromVCard(VCard vcard){
37         JabberID=n2e(vcard.getJabberID());
38         if(vcard.getFullName()!=null){
39             FullName=vcard.getFullName();
40         }
41         else{
42             FullName=n2e(vcard.getName_Prefix()+" "+vcard.getName_Given())+" "+n2e(vcard.getName_Family()+" "+vcard.getName_Suffix());
43         }
44         NickName=n2e(vcard.getNickname());
45         Birthday=n2e(vcard.getBirthday());
46         if(vcard.getEmail_Work()!=null){
47             Email=vcard.getEmail_Work();
48         }
49         else{
50             Email=n2e(vcard.getEmail_Home());
51         }
52         HomePage=n2e(vcard.getURL());
53         if(vcard.getTel_Work_Voice()!=null){
54             Phone=vcard.getTel_Work_Voice();
55         }
56         else{
57             Phone=n2e(vcard.getTel_Home_Voice());
58         }
59         if(vcard.hasWorkAddress()){
60             Street=n2e(vcard.getAddress_Work_House())+n2e(vcard.getAddress_Work_Street());
61             City=n2e(vcard.getAddress_Work_Locality());
62             State=n2e(vcard.getAddress_Work_Region());
63             PostCode=n2e(vcard.getAddress_Work_PCode());
64             Country=n2e(vcard.getAddress_Work_Country());
65         }
66         else{
67             if(vcard.hasHomeAddress()){
68                 Street=n2e(vcard.getAddress_Home_House())+n2e(vcard.getAddress_Home_Street());
69                 City=n2e(vcard.getAddress_Home_Locality());
70                 State=n2e(vcard.getAddress_Home_Region());
71                 PostCode=n2e(vcard.getAddress_Home_PCode());
72                 Country=n2e(vcard.getAddress_Home_Country());
73             }
74         }
75         Company=n2e(vcard.getOrg_Name());
76         Department=n2e(vcard.getOrg_Unit());
77         Position=n2e(vcard.getTitle());
78         Role=n2e(vcard.getRole());
79         Notes=n2e(vcard.getDescription());
80     }
81     
82     public VCard asVcard(){
83         VCard v=new VCard();
84         v.setFullName(t(FullName));
85         v.setNickname(t(NickName));
86         v.setBirthday(t(Birthday));
87         v.setURL(t(HomePage));
88         v.setAddress_Work_Street(t(Street));
89         v.setAddress_Work_Locality(t(City));
90         v.setAddress_Work_Region(t(State));
91         v.setAddress_Work_PCode(t(PostCode));
92         v.setAddress_Work_Country(t(Country));
93         v.setTel_Work_Voice(t(Phone));
94         v.setEmail_Work(t(Email));
95         v.setDescription(t(Notes));
96         v.setJabberID(t(JabberID));
97         v.setOrg_Name(t(Company));
98         v.setOrg_Unit(t(Department));
99         v.setRole(t(Role));
100         v.setTitle(t(Position));
101         return v;
102     }
103     
104     private String JavaDoc t(String JavaDoc s){
105         if(s==null){return null;}
106         if(s.equals("")){
107             return null;
108         }
109         return s;
110     }
111     
112     private String JavaDoc n2e(String JavaDoc s){
113         if(s!=null){
114             return s;
115         }
116         return ("");
117     }
118 }
Popular Tags