use of net.sf.sdedit.server.Exporter in project abstools by abstools.
the class Main method createImage.
private static void createImage(CommandLine cmd) throws IOException, XMLException, SyntaxError, SemanticError {
File inFile = new File(getInputFiles(cmd)[0]);
File outFile = new File(cmd.getOptionValue('o'));
String type = "png";
if (cmd.getOptionValue('t') != null) {
type = cmd.getOptionValue('t').toLowerCase();
}
String format = "A4";
if (cmd.getOptionValue('f') != null) {
format = cmd.getOptionValue('f').toUpperCase();
}
String orientation = "Portrait";
if (cmd.getOptionValue('r') != null) {
orientation = cmd.getOptionValue('r').toLowerCase();
if (orientation.length() > 0) {
orientation = orientation.substring(0, 1).toUpperCase() + orientation.substring(1);
}
}
InputStream in = null;
OutputStream out = null;
in = new FileInputStream(inFile);
try {
out = new FileOutputStream(outFile);
try {
Pair<String, Bean<Configuration>> pair = DiagramLoader.load(in, ConfigurationManager.getGlobalConfiguration().getFileEncoding());
TextHandler th = new TextHandler(pair.getFirst());
Bean<Configuration> conf = pair.getSecond();
configure(conf, cmd);
if (type.equals("png")) {
ImagePaintDevice paintDevice = new ImagePaintDevice();
new Diagram(conf.getDataObject(), th, paintDevice).generate();
paintDevice.writeToStream(out);
} else {
Exporter paintDevice = Exporter.getExporter(type, orientation, format, out);
new Diagram(conf.getDataObject(), th, paintDevice).generate();
paintDevice.export();
}
out.flush();
} finally {
out.close();
}
} finally {
in.close();
}
}
Aggregations