1 6 7 package com.raptus.owxv3.modules.usermgr; 8 9 10 import java.util.*; 11 import javax.servlet.http.HttpServletRequest ; 12 import org.apache.struts.action.*; 13 14 import com.raptus.owxv3.*; 15 import com.raptus.owxv3.api.*; 16 17 18 22 public class EAUserMgrEditBean extends OmniaWebBean 23 { 24 27 protected List roles = null; 28 29 32 protected List allroles = null; 33 36 protected String name = null; 37 38 41 protected String password = null; 42 43 46 protected String email = null; 47 48 51 protected String locale = null; 52 53 56 protected String username = null; 57 58 61 public EAUserMgrEditBean() 62 { 63 this.newuser = false; 64 } 65 66 69 protected boolean newuser=true; 70 71 76 public boolean isNewUser() 77 { 78 return newuser; 79 } 80 81 public String getNewUser() 82 { 83 return ""+newuser; 84 } 85 86 public void setNewUser(boolean newuser) 87 { 88 this.newuser = newuser; 89 } 90 91 public void setNewUser(String newuser) 92 { 93 this.newuser = Boolean.valueOf(newuser).booleanValue(); 94 } 95 96 101 public String getLocale() { return locale; } 102 103 108 public void setLocale(String locale) { this.locale = locale; } 109 110 115 public String getPassword() { return password; } 116 117 122 public void setPassword(String password) { this.password = password; } 123 124 129 public String getUsername() { return username; } 130 131 136 public void setUsername(String username) { this.username = username; } 137 138 143 public String getEmail() { return email; } 144 145 150 public void setEmail(String email) {this.email = email;} 151 152 157 public String getName() { return name; } 158 159 164 public void setName(String name) { this.name = name; } 165 166 173 public ActionErrors validate(HttpServletRequest request) 174 { 175 ActionErrors ret=new ActionErrors(); 176 177 if(name==null||name.length()<1) 179 { 180 ret.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.usermgr.error.NoUserName")); 181 } 182 183 if(username==null||username.length()<1) 185 { 186 ret.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.usermgr.error.NoLoginName")); 187 } 188 189 if(email==null||email.length()<1) 191 { 192 ret.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.usermgr.error.NoEmailAddress")); 193 } 194 195 if(password==null||password.length()<1) 197 { 198 ret.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.usermgr.error.NoPassword")); 199 } 200 201 if(locale==null||locale.length()<1) 203 { 204 ret.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.usermgr.error.NoLocale")); 205 } 206 207 if(makeLocale(locale) == null) 208 { 209 ret.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.usermgr.error.InvalidLocale")); 210 } 211 212 if(!isValidEmail(email)) 213 { 214 ret.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.usermgr.error.InvalidEmail")); 215 } 216 217 return ret; 218 } 219 220 223 public void reset() 224 { 225 this.email = null; 226 this.locale = null; 227 this.name = null; 228 this.password = null; 229 this.username = null; 230 this.newuser = false; 231 this.roles = null; 232 } 233 234 239 public List getRoles() 240 { 241 if(roles == null) 242 { 243 return new ArrayList(); 244 } 245 else 246 { 247 return roles; 248 } 249 } 250 251 252 257 public List getAllRoles() 258 { 259 if(allroles == null) 260 { 261 return new ArrayList(); 262 } 263 else 264 { 265 return allroles; 266 } 267 } 268 269 274 public void setRoles(String [] roles) 275 { 276 this.roles = new ArrayList(); 277 for(int i=0;i<roles.length;i++) 278 { 279 this.roles.add(roles[i]); 280 } 281 } 282 283 288 public void setAllRoles(List allroles) 289 { 290 this.allroles = allroles; 291 } 292 293 public String [] split(String str, String delim) 294 { 295 StringTokenizer st = new StringTokenizer(str, delim); 296 String [] res = new String [st.countTokens()]; 297 int i=0; 298 while(st.hasMoreTokens()) 299 { 300 res[i++] = st.nextToken(); 301 } 302 303 return res; 304 } 305 306 public Locale makeLocale(String locale) 307 { 308 VModuleManager vmm = VModuleManager.getInstance(); 309 String [] locales = vmm.getVModule("usermgr").getLocales(); 310 boolean found = false; 311 for(int i=0;i<locales.length;i++) 312 { 313 if(locales[i].equals(locale)) 314 { 315 found = true; 316 break; 317 } 318 } 319 320 if(!found) 321 { 322 return null; 324 } 325 326 Locale result = null; 327 String sres[] = split(locale, "_"); 328 if(sres.length==1) 329 { 330 result = new Locale(sres[0]); 331 } 332 else 333 { 334 result = new Locale(sres[0],sres[1]); 335 } 336 return result; 337 } 338 339 protected boolean isValidEmail(String email) 340 { 341 if(email == null) 342 { 343 return false; 344 } 345 346 if(email.indexOf("@")<0) 347 { 348 return false; 349 } 350 351 if(email.endsWith("@")) 352 { 353 return false; 354 } 355 356 if(email.endsWith(".")) 357 { 358 return false; 359 } 360 361 return true; 362 } 363 } 364 | Popular Tags |