private static void handleExportAttributesToJAR(Element e, GUI gui, File toDir) { /* Checks configuration for EXPORT attributes: * copy: file copy file to exported JAR, update file path. * discard: remove config element */ for (Element c : ((List<Element>) e.getChildren()).toArray(new Element[0])) { Attribute a = c.getAttribute("EXPORT"); if (a != null && a.getValue().equals("copy")) { /* Copy file to JAR */ File file = gui.restorePortablePath(new File(c.getText())); if (!file.exists()) { throw new RuntimeException("File not found: " + file); } byte[] data = ArrayUtils.readFromFile(file); if (data == null) { throw new RuntimeException("Could not copy file: " + file); } String newFilename = file.getName(); while (new File(toDir, newFilename).exists()) { newFilename += "-1"; } boolean ok = ArrayUtils.writeToFile(new File(toDir, newFilename), data); if (!ok) { throw new RuntimeException("Error when copying file: " + file); } logger.info( "Simconfig: Copied file: " + file.getAbsolutePath() + " -> " + ("[CONFIG_DIR]/" + newFilename)); ((Element) c).setText("[CONFIG_DIR]/" + newFilename); } else if (a != null && a.getValue().equals("discard")) { /* Remove config element */ e.removeChild(c.getName()); logger.info("Simconfig: Discarded element '" + c.getName() + "': " + c.getText()); continue; } else if (a != null) { throw new RuntimeException("Unknown EXPORT attribute value: " + a.getValue()); } /* Recursive search */ handleExportAttributesToJAR(c, gui, toDir); } }