| 1 2 package com.quikj.application.communicator.applications.webtalk.controller; 3 4 import javax.servlet.http.HttpServletRequest ; 5 import org.apache.struts.action.*; 6 import java.util.*; 7 8 12 public class RestrictedAccessUserManagementForm extends ActionForm 13 { 14 15 16 private String name; 17 18 19 private String password; 20 21 22 private String verifyPassword; 23 24 25 private String submit; 26 27 28 private String additionalInfo; 29 30 31 private String fullName; 32 33 34 private String email; 35 36 37 private HashMap infoParms; 38 39 private static int MIN_PASSWORD_LENGTH = 4; 40 41 42 43 public RestrictedAccessUserManagementForm() 44 { 45 reset(); 46 } 47 48 52 public String getName() 53 { 54 return this.name; 55 } 56 57 61 public void setName(String name) 62 { 63 this.name = name.trim(); 64 } 65 66 70 public String getPassword() 71 { 72 return this.password; 73 } 74 75 79 public void setPassword(String password) 80 { 81 this.password = password; 82 } 83 84 88 public String getVerifyPassword() 89 { 90 return this.verifyPassword; 91 } 92 93 97 public void setVerifyPassword(String verifyPassword) 98 { 99 this.verifyPassword = verifyPassword; 100 } 101 102 106 public String getSubmit() 107 { 108 return this.submit; 109 } 110 111 115 public void setSubmit(String submit) 116 { 117 this.submit = submit; 118 } 119 120 124 public String getAdditionalInfo() 125 { 126 return this.additionalInfo; 127 } 128 129 133 public void setAdditionalInfo(String additionalInfo) 134 { 135 this.additionalInfo = additionalInfo.trim(); 136 } 137 138 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) 139 { 140 ActionErrors errors = new ActionErrors(); 142 143 if ((name == null) || (name.length() == 0)) 144 { 145 errors.add("name", new ActionError("error.restr.accessuser.no.name")); 146 } 147 148 if (DataCheckUtility.followsTableIdRules(name) == false) 149 { 150 errors.add("name", new ActionError("error.restr.accessuser.invalid.id")); 151 } 152 153 if (submit.equals("Create") == true) 155 { 156 if ((password == null) || (password.length() == 0)) 157 { 158 errors.add("password", new ActionError("error.user.no.password")); 159 } 160 else 161 { 162 UserManagementForm.validatePassword(password, errors); 163 164 if (verifyPassword != null) 165 { 166 if (password.equals(verifyPassword) == false) 167 { 168 errors.add("password", new ActionError("error.user.password.mismatch")); 169 } 170 } 171 else 172 { 173 errors.add("password", new ActionError("error.user.password.mismatch")); 174 } 175 } 176 } 177 178 if (submit.equals("Modify") == true) 180 { 181 if ((password != null) && (password.length() > 0)) 182 { 183 UserManagementForm.validatePassword(password, errors); 184 185 if (verifyPassword != null) 186 { 187 if (password.equals(verifyPassword) == false) 188 { 189 errors.add("password", new ActionError("error.user.password.mismatch")); 190 } 191 } 192 else 193 { 194 errors.add("password", new ActionError("error.user.password.mismatch")); 195 } 196 } 197 } 198 199 if ((submit.equals("Create") == true) || (submit.equals("Modify") == true)) 200 { 201 processAdditionalInfo(getAdditionalInfo(), errors); 203 204 } 205 206 return errors; 207 } 208 209 private void processAdditionalInfo(String info, ActionErrors errors) 210 { 211 223 224 if (info != null) 225 { 226 info = info.trim(); 227 if (info.length() > 0) 228 { 229 StringTokenizer strtok = new StringTokenizer(info, "\n"); 230 int num_pairs = strtok.countTokens(); 231 232 infoParms = new HashMap(); 233 234 for (int i = 0; i < num_pairs; i++) 235 { 236 String pair = strtok.nextToken(); 237 238 StringTokenizer pairtok = new StringTokenizer(pair, "=", true); 239 int num_subparms = pairtok.countTokens(); 240 241 if (num_subparms != 3) 242 { 243 errors.add("additionalInfo", new ActionError("error.restr.accessuser.info.pairtokens", 244 new Integer (i + 1))); 245 246 continue; 247 } 248 249 String input_key = pairtok.nextToken().trim(); 250 pairtok.nextToken(); 251 String input_value = pairtok.nextToken().trim(); 252 253 if (num_pairs == 1) 254 { 255 if (input_key.equals("info") == false) 256 { 257 errors.add("additionalInfo", new ActionError("error.restr.accessuser.info.singlepairkey")); 258 259 continue; 260 } 261 } 262 263 String key = Utilities.deEscapeEqual(input_key); 264 String value = Utilities.deEscapeEqual(input_value); 265 266 if (infoParms.containsKey(key) == true) 267 { 268 errors.add("additionalInfo", new ActionError("error.restr.accessuser.info.duplicatekey", 269 new Integer (i + 1))); 270 271 continue; 272 } 273 274 infoParms.put(key, value); 275 } 276 } 277 } 278 } 279 280 public void reset() 281 { 282 name = null; 283 password = null; 284 verifyPassword = null; 285 submit = "Find"; 286 additionalInfo = null; 287 fullName = null; 288 email = null; 289 } 290 291 295 public String getFullName() 296 { 297 return this.fullName; 298 } 299 300 304 public void setFullName(String fullName) 305 { 306 this.fullName = fullName.trim(); 307 } 308 309 313 public String getEmail() 314 { 315 return this.email; 316 } 317 318 322 public void setEmail(String email) 323 { 324 this.email = email.trim(); 325 } 326 327 331 public HashMap getInfoParms() 332 { 333 return this.infoParms; 334 } 335 336 340 public void setInfoParms(HashMap info_parms) 341 { 342 infoParms = info_parms; 343 additionalInfo = null; 344 345 if (infoParms != null) 346 { 347 Set key_set = infoParms.keySet(); 348 StringBuffer buf = new StringBuffer (); 349 350 for (Iterator i = key_set.iterator(); i.hasNext();) 351 { 352 String key = (String ) i.next(); 353 String value = (String ) infoParms.get(key); 354 355 buf.append(Utilities.escapeEqual(key) + "=" + Utilities.escapeEqual(value)); 356 if (i.hasNext() == true) 357 { 358 buf.append('\n'); 359 } 360 } 361 362 additionalInfo = buf.toString(); 363 } 364 } 365 366 } 367 | Popular Tags |