Search in sources :

Example 1 with Exporter

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();
    }
}
Also used : Configuration(net.sf.sdedit.config.Configuration) ImagePaintDevice(net.sf.sdedit.ui.ImagePaintDevice) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Exporter(net.sf.sdedit.server.Exporter) FileInputStream(java.io.FileInputStream) Bean(net.sf.sdedit.ui.components.configuration.Bean) Diagram(net.sf.sdedit.diagram.Diagram) FileOutputStream(java.io.FileOutputStream) TextHandler(net.sf.sdedit.text.TextHandler) File(java.io.File)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Configuration (net.sf.sdedit.config.Configuration)1 Diagram (net.sf.sdedit.diagram.Diagram)1 Exporter (net.sf.sdedit.server.Exporter)1 TextHandler (net.sf.sdedit.text.TextHandler)1 ImagePaintDevice (net.sf.sdedit.ui.ImagePaintDevice)1 Bean (net.sf.sdedit.ui.components.configuration.Bean)1