KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > website > formbeans > UserFormEx


1
2 package org.roller.presentation.website.formbeans;
3
4 import org.roller.RollerException;
5 import org.roller.pojos.UserData;
6 import org.roller.presentation.forms.UserForm;
7 import org.roller.util.DateUtil;
8
9 import java.sql.Timestamp JavaDoc;
10 import java.util.Date JavaDoc;
11 import java.util.Locale JavaDoc;
12
13 /**
14  * Extend form to add extra properties not in generated base.
15  * @struts.form name="userFormEx"
16  */

17 public class UserFormEx extends UserForm
18 {
19     private String JavaDoc mTheme = null;
20     private String JavaDoc mLocale = null;
21     private String JavaDoc mTimezone = null;
22     private String JavaDoc mPasswordText = null;
23     private String JavaDoc mPasswordConfirm = null;
24     private boolean adminCreated = false;
25
26     public UserFormEx()
27     {
28         super();
29     }
30
31     public UserFormEx( UserData userData, java.util.Locale JavaDoc locale ) throws RollerException
32     {
33         super(userData, locale);
34     }
35
36     public String JavaDoc getTheme()
37     {
38         return mTheme;
39     }
40
41     public void setTheme( String JavaDoc theme )
42     {
43         mTheme = theme;
44     }
45     public String JavaDoc getLocale()
46     {
47         return mLocale;
48     }
49
50     public void setLocale(String JavaDoc locale)
51     {
52         mLocale = locale;
53     }
54
55     public String JavaDoc getTimezone()
56     {
57         return mTimezone;
58     }
59
60     public void setTimezone(String JavaDoc timezone)
61     {
62         mTimezone = timezone;
63     }
64     
65     /**
66      * Don't call it "password" because browser will autofill.
67      * @return Returns the passwordText.
68      */

69     public String JavaDoc getPasswordText()
70     {
71         return mPasswordText;
72     }
73     
74     /**
75      * Don't call it "password" because browser will autofill.
76      * @param passwordText The passwordText to set.
77      */

78     public void setPasswordText(String JavaDoc passwordText)
79     {
80         mPasswordText = passwordText;
81     }
82     
83     /**
84      * @return Returns the passwordConfirm.
85      */

86     public String JavaDoc getPasswordConfirm()
87     {
88         return mPasswordConfirm;
89     }
90     
91     /**
92      * @param passwordConfirm The passwordConfirm to set.
93      */

94     public void setPasswordConfirm(String JavaDoc passwordConfirm)
95     {
96         mPasswordConfirm = passwordConfirm;
97     }
98     
99     /**
100      * Utility to convert from String to Date.
101      */

102     public void setDateCreatedAsString(String JavaDoc value)
103     {
104         if ( value == null || value.trim().length() == 0 )
105         {
106             this.setDateCreated(null);
107         }
108         else
109         {
110             try
111             {
112                 Date JavaDoc pubDate = DateUtil.parse(
113                         value, DateUtil.friendlyTimestampFormat());
114                 this.setDateCreated(new Timestamp JavaDoc(pubDate.getTime()));
115             }
116             catch (java.text.ParseException JavaDoc pe)
117             {
118                 // wasn't proper format, try others
119
Date JavaDoc pubDate = DateUtil.parseFromFormats(value);
120                 this.setDateCreated( new Timestamp JavaDoc(pubDate.getTime()) );
121             }
122         }
123     }
124
125     /**
126      * Returns a formatted pubTime string.
127      */

128     public String JavaDoc getDateCreatedAsString()
129     {
130         return DateUtil.friendlyTimestamp(this.getDateCreated());
131     }
132     
133     
134     /**
135      * Override to prevent password or dateCreated being copied over by form
136      * @see org.roller.presentation.forms.UserForm#copyTo(
137      * org.roller.pojos.UserData, java.util.Locale)
138      */

139     public void copyTo(UserData dataHolder, Locale JavaDoc locale)
140                     throws RollerException
141     {
142         String JavaDoc password = dataHolder.getPassword();
143         Date JavaDoc dateCreated = dataHolder.getDateCreated();
144         
145         super.copyTo(dataHolder, locale);
146         
147         dataHolder.setPassword(password);
148         dataHolder.setDateCreated(dateCreated);
149     }
150
151     /** True if user is being created by an admin */
152     public void setAdminCreated(boolean b) {
153         adminCreated = b;
154     }
155     /** True if user is being created by an admin */
156     public boolean getAdminCreated() {
157         return adminCreated;
158     }
159 }
160
161
Popular Tags