package eu.greenlightning.nsdg;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.*;

import javax.xml.stream.XMLStreamException;

import eu.greenlightning.nsdg.elements.Element;
import eu.greenlightning.nsdg.xml.ParserException;
import eu.greenlightning.nsdg.xml.XMLParser;

public class NassiShneidermanDiagramGenerator {

	public static void main(String[] args) {
		if (args.length != 1) {
			System.out.println("Usage: java -jar nsdg.jar <path-to-xml-file>");
			System.out.println("Copyright © 2014 Green Lightning");
			return;
		}

		Path path = Paths.get(args[0]);

		if (!Files.exists(path)) {
			System.out.println("The file '" + path + "' does not exist.");
			return;
		}

		Element diagram;

		try (XMLParser parser = new XMLParser(path)) {
			diagram = parser.parseDiagram();
		} catch (ParserException e) {
			System.out.println(e.getMessage());
			return;
		} catch (IOException | XMLStreamException e) {
			System.out.println("An error occured while parsing the xml file.");
			System.out.println();
			e.printStackTrace();
			return;
		}

		Path imagePath = getImagePath(path);

		try (OutputStream out = Files.newOutputStream(imagePath)) {
			new ImageSaver().save(diagram, out);
		} catch (IOException e) {
			System.out.println("An error occured while saving the image.");
			System.out.println();
			e.printStackTrace();
			return;
		}

		System.out.println("Done writing " + imagePath + "!");
	}

	private static Path getImagePath(Path path) {
		return path.subpath(0, path.getNameCount() - 1).resolve(
			path.getFileName().toString().replace(".xml", ".png"));
	}

}

@@ -411,12 +411,12 @@
 gth 
-!= 1
+== 0
 ) %7B%0A
@@ -557,24 +557,221 @@
 eturn;%0A%09%09%7D%0A%0A
+%09%09for (int i = 0; i %3C args.length; i++) %7B%0A%09%09%09handle(args%5Bi%5D);%0A%09%09%09System.out.println();%0A%09%09%7D%0A%09%7D%0A%0A%09private static void handle(String argument) %7B%0A%09%09System.out.println(%22Handling '%22 + argument + %22':%22);%0A%0A
 %09%09Path path 
@@ -789,12 +789,13 @@
 (arg
-s%5B0%5D
+ument
 );%0A%0A
@@ -1034,32 +1034,32 @@
 rException e) %7B%0A
-
 %09%09%09System.out.pr
@@ -1064,16 +1064,28 @@
 println(
+%22Error: %22 + 
 e.getMes

Handle multiple arguments.