| 1 6 7 package com.quikj.application.communicator.admin.controller; 8 9 import javax.servlet.http.HttpServletRequest ; 10 import org.apache.struts.action.*; 11 import java.util.*; 12 13 import com.quikj.application.communicator.admin.model.*; 14 15 19 public class AccountManagementForm extends ActionForm 20 { 21 22 23 private String name; 24 25 26 private String password; 27 28 29 private String verifyPassword; 30 31 32 private String submit; 33 34 35 private String additionalInfo; 36 37 38 private int level; 39 40 41 private String [] featureList; 42 43 44 private Object [] assignedFeatures; 45 46 private static int MIN_PASSWORD_LENGTH = 4; 47 48 49 private String domain; 50 51 52 public AccountManagementForm() 53 { 54 ArrayList configured_features = AdminConfig.getInstance().getApplications(); 55 featureList = new String [configured_features.size()]; 56 58 int count = 0; 59 for (Iterator i = configured_features.iterator(); i.hasNext(); count++) 60 { 61 featureList[count] = ((ApplicationElement)i.next()).getDisplayName(); 62 } 63 64 reset(); 65 } 66 67 71 public String getName() 72 { 73 return this.name; 74 } 75 76 80 public void setName(String name) 81 { 82 this.name = name.trim(); 83 } 84 85 89 public String getPassword() 90 { 91 return this.password; 92 } 93 94 98 public void setPassword(String password) 99 { 100 this.password = password; 101 } 102 103 107 public String getVerifyPassword() 108 { 109 return this.verifyPassword; 110 } 111 112 116 public void setVerifyPassword(String verifyPassword) 117 { 118 this.verifyPassword = verifyPassword; 119 } 120 121 125 public String getSubmit() 126 { 127 return this.submit; 128 } 129 130 134 public void setSubmit(String submit) 135 { 136 this.submit = submit; 137 } 138 139 143 public String getAdditionalInfo() 144 { 145 return this.additionalInfo; 146 } 147 148 152 public void setAdditionalInfo(String additionalInfo) 153 { 154 this.additionalInfo = additionalInfo.trim(); 155 } 156 157 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) 158 { 159 ActionErrors errors = new ActionErrors(); 161 162 if ((name == null) || (name.length() == 0)) 163 { 164 errors.add("name", new ActionError("error.account.no.name")); 165 } 166 167 if (submit.equals("Create") == true) 169 { 170 if ((password == null) || (password.length() == 0)) 171 { 172 errors.add("password", new ActionError("error.account.no.password")); 173 } 174 else 175 { 176 validatePassword(password, errors, "password"); 177 178 if (verifyPassword != null) 179 { 180 if (password.equals(verifyPassword) == false) 181 { 182 errors.add("password", new ActionError("error.account.password.mismatch")); 183 } 184 } 185 else 186 { 187 errors.add("password", new ActionError("error.account.password.mismatch")); 188 } 189 } 190 } 191 192 if (submit.equals("Modify") == true) 194 { 195 if ((password != null) && (password.length() > 0)) 196 { 197 validatePassword(password, errors, "password"); 198 199 if (verifyPassword != null) 200 { 201 if (password.equals(verifyPassword) == false) 202 { 203 errors.add("password", new ActionError("error.account.password.mismatch")); 204 } 205 } 206 else 207 { 208 errors.add("password", new ActionError("error.account.password.mismatch")); 209 } 210 } 211 } 212 213 if ((submit.equals("Modify") == true) || (submit.equals("Create") == true)) 215 { 216 if (level == AccountElement.LEVEL_CUSTOMER) 218 { 219 if ((domain == null) || (domain.length() == 0)) 220 { 221 errors.add("domain", new ActionError("error.account.no.domain")); 222 } 223 } 224 225 } 226 227 return errors; 228 } 229 230 public static void validatePassword(String password, ActionErrors errors, String fieldname) 231 { 232 password = password.trim(); 233 if (password.length() == 0) 234 { 235 errors.add(fieldname, new ActionError("error.account.password.hasblanks")); 236 } 237 else 238 { 239 int len = password.length(); 240 241 if (len < MIN_PASSWORD_LENGTH) 242 { 243 errors.add(fieldname, new ActionError("error.account.password.tooshort", new Integer (MIN_PASSWORD_LENGTH))); 244 } 245 246 boolean letter = false; 248 boolean digit = false; 249 250 for (int i = 0; i < len; i++) 251 { 252 char c = password.charAt(i); 253 if (Character.isDigit(c) == true) 254 { 255 digit = true; 256 } 257 else if (Character.isLetter(c) == true) 258 { 259 letter = true; 260 } 261 else if (Character.isSpaceChar(c) == true) 262 { 263 errors.add(fieldname, new ActionError("error.account.password.hasblanks")); 264 } 265 } 266 267 if ((letter == false) || (digit == false)) 268 { 269 errors.add(fieldname, new ActionError("error.account.password.content")); 270 } 271 } 272 } 273 274 public void reset() 275 { 276 password = null; 277 verifyPassword = null; 278 submit = "Find"; 279 additionalInfo = null; 280 level = AccountElement.LEVEL_CUSTOMER; 281 assignedFeatures = new Object [featureList.length]; 282 domain = null; 283 284 } 285 286 290 public int getLevel() 291 { 292 return this.level; 293 } 294 295 299 public void setLevel(int level) 300 { 301 this.level = level; 302 } 303 304 308 public String [] getFeatureList() 309 { 310 return this.featureList; 311 } 312 313 317 public Object [] getAssignedFeatures() 318 { 319 return this.assignedFeatures; 320 } 321 322 326 public void setAssignedFeatures(Object [] assignedFeatures) 327 { 328 this.assignedFeatures = assignedFeatures; 329 } 330 331 335 public String getDomain() 336 { 337 return this.domain; 338 } 339 340 344 public void setDomain(String domain) 345 { 346 this.domain = domain.trim(); 347 } 348 349 } 350 | Popular Tags |