01: package fit;
02:
03: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
04: // Released under the terms of the GNU General Public License version 2 or later.
05:
06: import java.io.*;
07: import java.util.*;
08:
09: public class FileRunner {
10:
11: public String input;
12: public Parse tables;
13: public Fixture fixture = new Fixture();
14: public PrintWriter output;
15:
16: public static void main(String argv[]) {
17: try {
18: new FileRunner().run(argv);
19: } catch (Exception e) {
20: System.err.println(e.getMessage());
21: System.exit(-1);
22: }
23: }
24:
25: public void run(String argv[]) throws IOException {
26: args(argv);
27: process();
28: exit();
29: }
30:
31: public void process() {
32: try {
33: if (input.indexOf("<wiki>") >= 0) {
34: tables = new Parse(input, new String[] { "wiki",
35: "table", "tr", "td" });
36: fixture.doTables(tables.parts);
37: } else {
38: tables = new Parse(input, new String[] { "table", "tr",
39: "td" });
40: fixture.doTables(tables);
41: }
42: } catch (Exception e) {
43: exception(e);
44: }
45: tables.print(output);
46: }
47:
48: public void args(String[] argv) throws IOException {
49: if (argv.length != 2) {
50: System.err
51: .println("usage: java fit.FileRunner input-file output-file");
52: System.exit(-1);
53: }
54: File in = new File(argv[0]);
55: File out = new File(argv[1]);
56: fixture.summary.put("input file", in.getAbsolutePath());
57: fixture.summary
58: .put("input update", new Date(in.lastModified()));
59: fixture.summary.put("output file", out.getAbsolutePath());
60: input = read(in);
61: output = new PrintWriter(
62: new BufferedWriter(new FileWriter(out)));
63: }
64:
65: protected String read(File input) throws IOException {
66: char chars[] = new char[(int) (input.length())];
67: FileReader in = new FileReader(input);
68: in.read(chars);
69: in.close();
70: return new String(chars);
71: }
72:
73: protected void exception(Exception e) {
74: tables = new Parse("body",
75: "Unable to parse input. Input ignored.", null, null);
76: fixture.exception(tables, e);
77: }
78:
79: protected void exit() {
80: output.close();
81: System.err.println(fixture.counts());
82: System.exit(fixture.counts.wrong + fixture.counts.exceptions);
83: }
84:
85: }
|