KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > authoring > struts > formbeans > UserFormEx


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18
19 package org.apache.roller.ui.authoring.struts.formbeans;
20
21 import org.apache.roller.RollerException;
22 import org.apache.roller.pojos.UserData;
23 import org.apache.roller.ui.authoring.struts.forms.UserForm;
24 import org.apache.roller.util.DateUtil;
25
26 import java.sql.Timestamp JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.Locale JavaDoc;
29
30 /**
31  * Extend form to add extra properties not in generated base.
32  * @struts.form name="userFormEx"
33  */

34 public class UserFormEx extends UserForm
35 {
36     private String JavaDoc mPasswordText = null;
37     private String JavaDoc mPasswordConfirm = null;
38     private boolean adminCreated = false;
39     private boolean dataFromSSO = false;
40
41     public UserFormEx()
42     {
43         super();
44     }
45
46     public UserFormEx( UserData userData, java.util.Locale JavaDoc locale ) throws RollerException
47     {
48         super(userData, locale);
49     }
50     
51     /**
52      * Don't call it "password" because browser will autofill.
53      * @return Returns the passwordText.
54      */

55     public String JavaDoc getPasswordText()
56     {
57         return mPasswordText;
58     }
59     
60     /**
61      * Don't call it "password" because browser will autofill.
62      * @param passwordText The passwordText to set.
63      */

64     public void setPasswordText(String JavaDoc passwordText)
65     {
66         mPasswordText = passwordText;
67     }
68     
69     /**
70      * @return Returns the passwordConfirm.
71      */

72     public String JavaDoc getPasswordConfirm()
73     {
74         return mPasswordConfirm;
75     }
76     
77     /**
78      * @param passwordConfirm The passwordConfirm to set.
79      */

80     public void setPasswordConfirm(String JavaDoc passwordConfirm)
81     {
82         mPasswordConfirm = passwordConfirm;
83     }
84     
85     /**
86      * Utility to convert from String to Date.
87      */

88     public void setDateCreatedAsString(String JavaDoc value)
89     {
90         if ( value == null || value.trim().length() == 0 )
91         {
92             this.setDateCreated(null);
93         }
94         else
95         {
96             try
97             {
98                 Date JavaDoc pubDate = DateUtil.parse(
99                         value, DateUtil.friendlyTimestampFormat());
100                 this.setDateCreated(new Timestamp JavaDoc(pubDate.getTime()));
101             }
102             catch (java.text.ParseException JavaDoc pe)
103             {
104                 // wasn't properly formatted
105
throw new RuntimeException JavaDoc("improperly formatted date", pe);
106             }
107         }
108     }
109
110     /**
111      * Returns a formatted pubTime string.
112      */

113     public String JavaDoc getDateCreatedAsString()
114     {
115         return DateUtil.friendlyTimestamp(this.getDateCreated());
116     }
117     
118     
119     /**
120      * Override to prevent password or dateCreated being copied over by form
121      * @see org.apache.roller.ui.authoring.struts.forms.UserForm#copyTo(
122      * org.apache.roller.pojos.UserData, java.util.Locale)
123      */

124     public void copyTo(UserData dataHolder, Locale JavaDoc locale)
125                     throws RollerException
126     {
127         String JavaDoc password = dataHolder.getPassword();
128         Date JavaDoc dateCreated = dataHolder.getDateCreated();
129         
130         super.copyTo(dataHolder, locale);
131         
132         dataHolder.setPassword(password);
133         dataHolder.setDateCreated(dateCreated);
134     }
135
136     /** True if user is being created by an admin */
137     public void setAdminCreated(boolean b) {
138         adminCreated = b;
139     }
140     /** True if user is being created by an admin */
141     public boolean getAdminCreated() {
142         return adminCreated;
143     }
144     
145     /** True if user data originally came from SSO */
146     public void setDataFromSSO(boolean b) {
147       dataFromSSO = b;
148     }
149     
150     /** True if user data originally came from SSO */
151     public boolean getDataFromSSO() {
152         return dataFromSSO;
153     }
154 }
155
156
Popular Tags