/** * This application reads references from an input file and * generates a html formatted reference file. * * author: Luc Longpré * 10/24/2005 */ import java.io.*; public class ReferenceApp { public static void main( String args[] ) throws IOException { String fileName; // the name of the file to open String line; // contains one line from the input file // the following are the different fields that can be in the input file String theAuthor; String theTitle; String theYear; String thePublisher; String theSchool; String theJournal; String theVolume; String theEdition; String theAddress; String thePages; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter input file name: "); fileName = in.readLine(); BufferedReader infile = new BufferedReader(new FileReader(fileName)); System.out.print("Enter output file name: "); fileName = in.readLine(); PrintWriter outfile = new PrintWriter(new FileWriter(fileName)); outfile.println("References\n" + "

References

\n"); line = infile.readLine(); while (line != null) { if (line.equals("book")) { theAuthor = ""; theYear = ""; thePublisher = ""; theTitle = ""; theEdition = ""; theVolume = ""; theAddress = ""; // int i=0; // try // { // System.out.println("A"); // if (i==1) // throw new IOException(); // i=1/i; // System.out.println("B"); // } // catch (IOException ioErr) // { // System.out.println("C"); // } // finally // { // System.out.println("D"); // } // System.out.println("E"); line = infile.readLine(); while (!line.equals("")) { if (line.equals("author")) theAuthor = infile.readLine(); else if (line.equals("year")) theYear = infile.readLine(); else if (line.equals("publisher")) thePublisher = infile.readLine(); else if (line.equals("title")) theTitle = infile.readLine(); else if (line.equals("volume")) theVolume = infile.readLine(); else if (line.equals("address")) theAddress = infile.readLine(); else if (line.equals("edition")) theEdition = infile.readLine(); line = infile.readLine(); } Book theBook = new Book(theAuthor, theTitle, thePublisher, theYear, theVolume, theAddress, theEdition); outfile.println(theBook.toString()+"

"); } else if (line.equals("article")) { theAuthor = ""; theYear = ""; theJournal = ""; theTitle = ""; theVolume = ""; thePages = ""; line = infile.readLine(); while (!line.equals("")) { if (line.equals("author")) theAuthor = infile.readLine(); else if (line.equals("year")) theYear = infile.readLine(); else if (line.equals("journal")) theJournal = infile.readLine(); else if (line.equals("title")) theTitle = infile.readLine(); else if (line.equals("volume")) theVolume = infile.readLine(); else if (line.equals("pages")) thePages = infile.readLine(); line = infile.readLine(); } Article theArticle = new Article(theAuthor, theTitle, theYear, theJournal, theVolume, thePages); outfile.println(theArticle.toString()+"

"); } else if (line.equals("phdthesis")) { theAuthor = ""; theYear = ""; theSchool = ""; theTitle = ""; theAddress = ""; line = infile.readLine(); while (!line.equals("")) { if (line.equals("author")) theAuthor = infile.readLine(); else if (line.equals("year")) theYear = infile.readLine(); else if (line.equals("school")) theSchool = infile.readLine(); else if (line.equals("title")) theTitle = infile.readLine(); else if (line.equals("address")) theAddress = infile.readLine(); line = infile.readLine(); } PhDThesis thePhDThesis = new PhDThesis(theAuthor, theTitle, theSchool, theYear, theAddress); outfile.println(thePhDThesis.toString()+"

"); } line = infile.readLine(); } System.out.println("done"); infile.close(); outfile.close(); } }