1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.app.foprep;
20
21 import java.io.PrintWriter;
22
23 import javax.xml.transform.Result;
24 import javax.xml.transform.Source;
25 import javax.xml.transform.TransformerException;
26 import javax.xml.transform.stream.StreamResult;
27 import javax.xml.transform.stream.StreamSource;
28
29 import net.sourceforge.jeuclid.converter.Processor;
30
31 import org.apache.commons.cli.CommandLine;
32 import org.apache.commons.cli.CommandLineParser;
33 import org.apache.commons.cli.GnuParser;
34 import org.apache.commons.cli.HelpFormatter;
35 import org.apache.commons.cli.Option;
36 import org.apache.commons.cli.Options;
37 import org.apache.commons.cli.ParseException;
38
39
40
41
42
43
44 public final class Main {
45
46 private static final String STD_INOUT = "-";
47
48 private static final String OPTION_OUT = "out";
49
50 private static final String OPTION_IN = "in";
51
52 private Main() {
53
54 }
55
56
57
58
59
60
61
62 public static void main(final String[] args) {
63 final Options options = new Options();
64 final Option in = new Option(Main.OPTION_IN, true, "input (fo) file");
65 in.setRequired(true);
66 options.addOption(in);
67 final Option out = new Option(Main.OPTION_OUT, true,
68 "output (fo) file");
69 out.setRequired(true);
70 options.addOption(out);
71 final CommandLineParser parser = new GnuParser();
72 try {
73 final CommandLine cmd = parser.parse(options, args);
74 final String inputFile = cmd.getOptionValue(Main.OPTION_IN);
75 final String outputFile = cmd.getOptionValue(Main.OPTION_OUT);
76 final Result result;
77 if (Main.STD_INOUT.equals(outputFile)) {
78 result = new StreamResult(new PrintWriter(System.out));
79 } else {
80 result = new StreamResult(outputFile);
81 }
82 final Source source;
83 if (Main.STD_INOUT.equals(inputFile)) {
84 source = new StreamSource(System.in);
85 } else {
86 source = new StreamSource(inputFile);
87 }
88 Processor.getInstance().process(source, result);
89 } catch (final ParseException e1) {
90 System.out.println("Invalid command line:" + e1.getMessage());
91 new HelpFormatter().printHelp(
92 "foprep -in input.fo -out output.fo", options);
93 } catch (final TransformerException e) {
94 System.out.println("An error occurred during processing: "
95 + e.getMessage());
96 e.printStackTrace();
97 }
98 }
99 }