load one file, given an open BufferedReader
Exam theExam = new Exam();
String inputLine;
StringTokenizer st;
if ((inputLine = is.readLine()) == null ||
!inputLine.startsWith("X"))
throw new IllegalArgumentException("File " + "testdata" +
" does not begin with X line!");
if ((st = new StringTokenizer(inputLine)).countTokens() != 4)
throw new IllegalArgumentException("File " + "testdata" +
" begins with invalid X line!");
st.nextToken();
theExam.crsNum = Integer.parseInt(st.nextToken());
theExam.examName = st.nextToken().charAt(0);
theExam.examVers = st.nextToken();
System.out.println("Loading Course " + theExam.crsNum + ", " +
"Exam " + theExam.examName + ", Version " + theExam.examVers);
if ((inputLine = is.readLine()) == null ||
!inputLine.startsWith("T "))
throw new IllegalArgumentException("File " + "testdata" +
" does not have T line second!");
theExam.setCourseTitle(inputLine.substring(2));
Vector al = new Vector();
theExam.setListData(al);
Q curQ = null;
while ((inputLine = is.readLine()) != null) {
// System.out.println(inputLine);
if (inputLine.length() == 0)
continue;
switch(inputLine.charAt(0)) {
case '#":
continue;
case 'Q":
// System.out.println("It's a question: " + inputLine);
curQ = new Q(4);
al.addElement(curQ);
curQ.setQText(inputLine.substring(4).trim(), true); // STRTOK ME
break;
case 'R":
// System.out.println("It's an answer!");
int n = inputLine.charAt(2) - 'A"; // A->0, B->1, etc.
if (n < 0)
break;
curQ.setAns(n, true);
break;
case 'O": // chapter objectives
// System.out.println("It's the chapter objective!");
int on = Integer.parseInt(inputLine.substring(2).trim());
if (on >= 0)
curQ.setObjective(on);
break;
case 'A":
case 'B":
case 'C":
case 'D":
int an = inputLine.charAt(0) - 'A"; // A->0, B->1, etc.
curQ.setAnsText(an, inputLine.substring(2), true);
break;
default:
// left over, presume multi-line question
if (curQ == null || curQ.getQText() == null) {
System.err.println("XamDataAccessor: ignoring " +
inputLine);
continue;
}
curQ.setQText(curQ.getQText() + "\n" + inputLine, true);
break;
}
}
is.close();
return theExam;