public void run(CommandLine commandLine) {
String cls = commandLine.getOptionValue('c');
if (cls == null) {
throw new MissingParameterException("class");
}
Formatter formatter;
if (cls.equals("al")) {
Writer writer = getSingleWriter(commandLine);
formatter = new AlFormatter(writer);
} else if (cls.equals("txt")) {
if (commandLine.getArgs().length != 2) {
throw new WrongArgumentCountException("2", commandLine.getArgs().length);
}
String sourceFileName = commandLine.getArgs()[0];
String targetFileName = commandLine.getArgs()[1];
Writer sourceWriter = getWriter(getFileOutputStream(sourceFileName));
Writer targetWriter = getWriter(getFileOutputStream(targetFileName));
formatter = new PlaintextFormatter(sourceWriter, targetWriter);
} else if (cls.equals("tmx")) {
Writer writer = getSingleWriter(commandLine);
String languages = commandLine.getOptionValue('l');
if (languages == null) {
throw new MissingParameterException("languages");
}
String[] languageArray = languages.split(",");
if (languageArray.length != 2) {
throw new ParameterFormatException("languages");
}
formatter = new TmxFormatter(writer, languageArray[0], languageArray[1]);
} else if (cls.equals("presentation")) {
Writer writer = getSingleWriter(commandLine);
int width = createInt(commandLine, "width", PresentationFormatter.DEFAULT_WIDTH);
formatter = new PresentationFormatter(writer, width);
} else if (cls.equals("html")) {
Writer writer = getSingleWriter(commandLine);
formatter = new HtmlFormatter(writer);
} else if (cls.equals("info")) {
Writer writer = getSingleWriter(commandLine);
formatter = new InfoFormatter(writer);
} else {
throw new UnknownParameterException("class");
}
Parser parser = new AlParser(getIn());
List<Alignment> alignmentList = parser.parse();
formatter.format(alignmentList);
}