Beispiel #1
0
  /**
   * This parser handles the format under Self Service -> Faculty Center -> My Schedule on GET. A
   * sample record is as follows: "1 Photo 123456789 Doe,John M 4.00 Engr, Comp Sci, & Tech G2
   * 01/05/2015". Again, not all fields may be present.
   */
  private List<ImportedUser> parse2(String text) {
    List<ImportedUser> students = new ArrayList<ImportedUser>();

    Scanner scanner = new Scanner(text);
    scanner.useDelimiter("\\s+|\\r\\n|\\r|\\n");
    while (scanner.hasNext()) {
      String cin = scanner.next();
      if (!isCin(cin)) continue;

      String name = "";
      boolean nameFound = false;
      while (scanner.hasNext()) {
        String token = scanner.next();
        name += token + " ";
        if (token.matches(".+,.*")) {
          if (token.endsWith(",") && scanner.hasNext()) name += scanner.next();
          nameFound = true;
          break;
        }
      }

      while (nameFound && scanner.hasNext()) {
        String token = scanner.next();
        if (isUnits(token)) break;
        name += token + " ";
      }

      if (nameFound) {
        ImportedUser student = new ImportedUser();
        student.setCin(cin);
        student.setName(name);
        students.add(student);
      }
    }
    scanner.close();

    return students;
  }
Beispiel #2
0
  /**
   * This parser handles the format under CSULA Baseline -> CSULA Student Records -> Class Roster on
   * GET. A sample record is as follows: "1 123456789 Doe,John M 3.00 A- ETG CS MS G1". Note that
   * some fields like middle name, units, and grade may not be present, and some people's last name
   * has space in it.
   */
  private List<ImportedUser> parse1(String text) {
    List<ImportedUser> students = new ArrayList<ImportedUser>();

    Scanner scanner = new Scanner(text);
    scanner.useDelimiter("\\s+|\\r\\n|\\r|\\n");
    while (scanner.hasNext()) {
      String cin = scanner.next();
      if (!isCin(cin)) continue;

      String name = "";
      boolean nameFound = false;
      while (scanner.hasNext()) {
        String token = scanner.next();
        name += token + " ";
        if (token.matches(".+,.*")) {
          if (token.endsWith(",") && scanner.hasNext()) name += scanner.next();
          nameFound = true;
          break;
        }
      }

      String grade = null;
      boolean gradeFound = false;
      boolean unitsFound = false;
      while (nameFound && scanner.hasNext()) {
        String token = scanner.next();
        if (isUnits(token)) {
          unitsFound = true;
          continue;
        }
        if (isGrade(token)) {
          if (unitsFound) // this must be a grade
          {
            grade = token;
            gradeFound = true;
            break;
          } else
          // this could be a grade or a middle name
          {
            grade = token;
            continue;
          }
        }
        if (isProgram(token)) {
          if (grade != null) gradeFound = true;
          break;
        }

        name += token + " ";
      }

      if (nameFound) {
        ImportedUser student = new ImportedUser();
        student.setCin(cin);
        student.setName(name);
        if (gradeFound) student.setGrade(grade);
        students.add(student);
      }
    }
    scanner.close();

    return students;
  }