Project

General

Profile

« Previous | Next » 

Revision 2085

Validate user input data in registration servlet

View differences:

HarvesterRegistration.java
53 53
  /*
54 54
   * Object methods
55 55
   */
56
   
57
   
58
  /**
59
   * Checks validity of user input values.
60
   * 
61
   * @param out             the PrintWriter output object
62
   * @param documentListURL the Harvest Document List URL specified by the user
63
   * @param updateFrequency the Harvest Frequency specified by the user
64
   * @return validValues    true if all values are valid, else false
65
   */
66
  private boolean checkValues(PrintWriter out,
67
                              String documentListURL,
68
                              int updateFrequency
69
                             ) {
70
    boolean validValues = true;
56 71

  
72
    // Check validity of the Harvest Document List URL field    
73
    if (documentListURL.equals("")) {
74
      out.println(
75
              "A value must be specified in the Harvest Document List URL field"
76
                 );
77
      validValues = false;
78
    }
79

  
80
    // Check validity of the Harvest Frequency field    
81
    if ((updateFrequency < 1) || (updateFrequency > 99)) {
82
      out.println("Harvest Frequency should be in the range 1 to 99");
83
      validValues = false;
84
    }
85
    
86
    return validValues;
87
  }
88
  
89
  
57 90
  /**
58 91
   * Closes the database connection.
59 92
   * 
......
364 397
    out.println("<pre>Email address:             </pre>");
365 398
    out.println("<INPUT TYPE=TEXT NAME=contactEmail VALUE=");
366 399
    out.println(contactEmail + ">");
367
    out.println("<BR>");
400
    out.println("<BR><BR>");
368 401
    out.println("<pre>Harvest Document List URL: </pre>");
369 402
    out.println("<INPUT TYPE=TEXT NAME=documentListURL VALUE=");
370 403
    out.println(documentListURL + ">");
371
    out.println("<BR>");
404
    out.println("<BR><BR>");
372 405
    out.println("<pre>Harvest Frequency (1-99):  </pre>");
373 406
    out.println("<INPUT TYPE=TEXT NAME=updateFrequency ");
374 407
    out.println("MAXLENGTH=2 SIZE=2 VALUE=");
375 408
    out.println(updateFrequency + ">");
376
    out.println("<BR>");
409
    out.println("<BR><BR>");
377 410
    out.println("<pre>Unit:                      </pre>");
378 411
    out.println("<INPUT TYPE=RADIO ");
379 412
    if (unit.equals("days")) out.println("CHECKED ");
......
384 417
    out.println("<INPUT TYPE=RADIO ");
385 418
    if (unit.equals("months")) out.println("CHECKED ");
386 419
    out.println("NAME=unit VALUE=months>month(s)");
387
    out.println("<BR><BR>");
420
    out.println("<BR><BR><BR>");
388 421
    out.println("<INPUT TYPE=SUBMIT NAME=register VALUE=Register>");
389 422
    out.println("<INPUT TYPE=SUBMIT NAME=unregister VALUE=Unregister>");
390 423
    out.println("</BODY>");
......
415 448
    HttpSession httpSession;
416 449
    String ldapDN;
417 450
    String ldapPwd;
451
    PrintWriter out;
418 452
    ParameterParser parameterParser = new ParameterParser(req);
419 453
    String register;
420 454
    String unit;
421 455
    String unregister;
422 456
    int updateFrequency;
457
    boolean validValues;
423 458

  
424
   httpSession = req.getSession(false);
459
    httpSession = req.getSession(false);
425 460
    
426 461
    if (httpSession == null) {
427 462
      System.out.println("User did not log in.");
......
442 477
    remove = (unregister.equalsIgnoreCase("Unregister"));
443 478
    siteScheduleID = getSiteScheduleID(conn, ldapDN);
444 479
    dateLastHarvest = getDateLastHarvest(conn, siteScheduleID);
445
    
480

  
446 481
    res.setContentType("text/plain");
447
    PrintWriter out = res.getWriter();
482
    out = res.getWriter();
448 483

  
484
    if (!remove) {    
485
      validValues = checkValues(out, documentListURL, updateFrequency);
486
      
487
      if (!validValues) {
488
        return;
489
      }
490
    }
491
    
449 492
    if (siteScheduleID == 0) {
450 493
      if (remove) {
451 494
        // The user clicked Unregister, but no existing record was found

Also available in: Unified diff