KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > user > Edit


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

25
26 package net.killingar.forum.actions.user;
27
28 public class Edit extends net.killingar.forum.actions.user.View
29 {
30     // Private --------------------------------------------------------
31
protected String JavaDoc newpassword, newpassword2;
32     protected int year = 1900, month = 0, date = 1;
33
34     boolean modify = false;
35
36     // Attributes -----------------------------------------------------
37

38     // Types ----------------------------------------------------------
39

40     // Setters --------------------------------------------------------
41
public void setName(String JavaDoc in) { user.name = in; modify = true; }
42     public void setIcq(String JavaDoc in) { user.icq = in; modify = true; }
43     public void setTelephone(String JavaDoc in) { user.telephone = in; modify = true; }
44     public void setMobilephone(String JavaDoc in) { user.mobilephone = in; modify = true; }
45     public void setAddress(String JavaDoc in) { user.address = in; modify = true; }
46     public void setOther(String JavaDoc in) { user.other = in; modify = true; }
47     public void setRealName(String JavaDoc in) { user.realName = in; modify = true; }
48     public void setPublicEmail(String JavaDoc in) { user.publicEmail = in; modify = true; }
49     public void setRestrictedEmail(String JavaDoc in) { user.restrictedEmail = in; modify = true; }
50     public void setSecretEmail(String JavaDoc in) { user.secretEmail = in; modify = true; }
51
52     public void setYear(int in) { year = in; modify = true; }
53     public void setMonth(int in) { month = in; modify = true; }
54     public void setDate(int in) { date = in; modify = true; }
55
56   public void setNewpassword(String JavaDoc in) { newpassword = in; modify = true; }
57     public void setNewpassword2(String JavaDoc in) { newpassword2 = in; modify = true; }
58
59     // Getters --------------------------------------------------------
60
public int getYear() { return 1900+user.birthdate.getYear(); }
61     public int getMonth() { return user.birthdate.getMonth(); }
62     public int getDate() { return user.birthdate.getDate(); }
63
64     // Implementation -------------------------------------------------
65
public Edit()
66     {
67         user = new UserData();
68     }
69
70   protected void doValidation()
71   {
72         super.doValidation();
73
74         if (newpassword != null && !newpassword.equals(newpassword2))
75         addError("newpassword2", "passwords do not match");
76     }
77
78     protected String JavaDoc doExecute()
79     {
80         user.ID = userID;
81
82         try
83         {
84             String JavaDoc r = INPUT;
85
86             if (modify)
87             {
88                 user.birthdate = new java.sql.Date JavaDoc(year-1900, month, date);
89
90                 manager.changeUser(user, newpassword);
91
92                 r = SUCCESS;
93             }
94
95             user = new UserData(manager, manager.getUser(userID));
96
97             user.groups = manager.getGroupsOfUser(userID);
98
99             user.email = net.killingar.forum.internal.Utils.unHTML(user.email );
100             user.icq = net.killingar.forum.internal.Utils.unHTML(user.icq );
101             user.telephone = net.killingar.forum.internal.Utils.unHTML(user.telephone );
102             user.mobilephone = net.killingar.forum.internal.Utils.unHTML(user.mobilephone );
103             user.address = net.killingar.forum.internal.Utils.unHTML(user.address );
104             user.other = net.killingar.forum.internal.Utils.unHTML(user.other );
105             user.realName = net.killingar.forum.internal.Utils.unHTML(user.realName );
106             user.publicEmail = net.killingar.forum.internal.Utils.unHTML(user.publicEmail );
107             user.restrictedEmail = net.killingar.forum.internal.Utils.unHTML(user.restrictedEmail);
108             user.secretEmail = net.killingar.forum.internal.Utils.unHTML(user.secretEmail );
109             if (user.birthdate == null)
110                 user.birthdate = new java.sql.Date JavaDoc(year-1900, month, date);
111
112             year = user.birthdate.getYear()+1900;
113             month = user.birthdate.getMonth();
114             date = user.birthdate.getDay();
115
116             return r;
117         }
118         catch (Exception JavaDoc e)
119         {
120             e.printStackTrace();
121             addErrorMessage("executing "+getClass().toString()+" action failed, exception thrown: "+e.toString());
122             return ERROR;
123         }
124     }
125 }
Popular Tags