1 16 17 package org.apache.webapp.admin.resources; 18 19 import java.util.List ; 20 import java.util.ArrayList ; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import org.apache.struts.action.ActionError; 24 import org.apache.struts.action.ActionErrors; 25 import org.apache.struts.action.ActionForm; 26 import org.apache.struts.action.ActionMapping; 27 import org.apache.webapp.admin.LabelValueBean; 28 29 36 37 public final class DataSourceForm extends BaseForm { 38 39 40 42 43 45 46 49 private String url = null; 50 51 public String getUrl() { 52 return (this.url); 53 } 54 55 public void setUrl(String url) { 56 this.url = url; 57 } 58 59 62 private String jndiName = null; 63 64 public String getJndiName() { 65 return (this.jndiName); 66 } 67 68 public void setJndiName(String jndiName) { 69 this.jndiName = jndiName; 70 } 71 72 75 private String driverClass = null; 76 77 public String getDriverClass() { 78 return (this.driverClass); 79 } 80 81 public void setDriverClass(String driverClass) { 82 this.driverClass = driverClass; 83 } 84 85 86 89 private String username = null; 90 91 public String getUsername() { 92 return (this.username); 93 } 94 95 public void setUsername(String username) { 96 this.username = username; 97 } 98 99 100 103 private String password = null; 104 105 public String getPassword() { 106 return (this.password); 107 } 108 109 public void setPassword(String password) { 110 this.password = password; 111 } 112 113 114 117 private String active = null; 118 119 public String getActive() { 120 return (this.active); 121 } 122 123 public void setActive(String active) { 124 this.active = active; 125 } 126 127 130 private String idle = null; 131 132 public String getIdle() { 133 return (this.idle); 134 } 135 136 public void setIdle(String idle) { 137 this.idle = idle; 138 } 139 140 143 private String wait = null; 144 145 public String getWait() { 146 return (this.wait); 147 } 148 149 public void setWait(String wait) { 150 this.wait = wait; 151 } 152 153 156 private String resourcetype = null; 157 158 161 public String getResourcetype() { 162 return this.resourcetype; 163 } 164 165 168 public void setResourcetype(String resourcetype) { 169 this.resourcetype = resourcetype; 170 } 171 172 175 private String path = null; 176 177 180 public String getPath() { 181 return this.path; 182 } 183 184 187 public void setPath(String path) { 188 this.path = path; 189 } 190 191 194 private String host = null; 195 196 199 public String getHost() { 200 return this.host; 201 } 202 203 206 public void setHost(String host) { 207 this.host = host; 208 } 209 210 211 214 private String domain = null; 215 216 219 public String getDomain() { 220 return this.domain; 221 } 222 223 226 public void setDomain(String domain) { 227 this.domain = domain; 228 } 229 230 233 private String query = null; 234 235 public String getQuery() { 236 return (this.query); 237 } 238 239 public void setQuery(String query) { 240 this.query = query; 241 } 242 243 246 private String type = null; 247 248 public String getType() { 249 return (this.type); 250 } 251 252 public void setType(String type) { 253 this.type = type; 254 } 255 256 258 264 public void reset(ActionMapping mapping, HttpServletRequest request) { 265 266 super.reset(mapping, request); 267 url = null; 268 jndiName = null; 269 driverClass = null; 270 username = null; 271 password = null; 272 type = null; 273 274 active = null; 275 idle = null; 276 wait = null; 277 query = null; 278 } 279 280 290 291 private ActionErrors errors = null; 292 293 public ActionErrors validate(ActionMapping mapping, 294 HttpServletRequest request) { 295 296 errors = new ActionErrors(); 297 298 String submit = request.getParameter("submit"); 299 300 302 if ((url == null) || (url.length() < 1)) { 304 errors.add("url", 305 new ActionError("resources.error.url.required")); 306 } 307 308 if (( jndiName == null) || (jndiName.length() < 1)) { 310 errors.add("jndiName", 311 new ActionError("resources.error.jndiName.required")); 312 } 313 314 if ((driverClass == null) || (driverClass.length() < 1)) { 316 errors.add("driverClass", 317 new ActionError("resources.error.driverClass.required")); 318 } 319 320 if ((username == null) || (username.length() < 1)) { 322 errors.add("username", 323 new ActionError("users.error.username.required")); 324 } 325 326 333 numberCheck("active", active , false, 0, 10000); 335 numberCheck("idle", idle , false, 0, 10000); 336 numberCheck("wait", wait , false, 0, 10000); 337 338 if ((username != null) && (username.indexOf('"') >= 0)) { 340 errors.add("username", 341 new ActionError("users.error.quotes")); 342 } 343 344 if ((password != null) && (password.indexOf('"') > 0)) { 346 errors.add("password", 347 new ActionError("users.error.quotes")); 348 } 349 return (errors); 351 } 352 353 365 366 private void numberCheck(String field, String numText, boolean rangeCheck, 367 int min, int max) { 368 369 if ((numText == null) || (numText.length() < 1)) { 371 errors.add(field, new ActionError("resources.error."+field+".required")); 372 } else { 373 374 try { 376 int num = Integer.parseInt(numText); 377 if (rangeCheck) { 379 if ((num < min) || (num > max )) 380 errors.add( field, 381 new ActionError("resources.error."+ field +".range")); 382 } 383 } catch (NumberFormatException e) { 384 errors.add(field, 385 new ActionError("resources.integer.error")); 386 } 387 } 388 } 389 390 } 391 | Popular Tags |