use of games.strategy.engine.data.export.GameDataExporter in project triplea by triplea-game.
the class ExportMenu method exportXmlFile.
private void exportXmlFile() {
final JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
final File rootDir = new File(SystemProperties.getUserDir());
final int round = gameData.getCurrentRound();
String defaultFileName = "xml_" + dateTimeFormatter.format(LocalDateTime.now()) + "_" + gameData.getGameName() + "_round_" + round;
defaultFileName = FileNameUtils.removeIllegalCharacters(defaultFileName);
defaultFileName = defaultFileName + ".xml";
chooser.setSelectedFile(new File(rootDir, defaultFileName));
if (chooser.showSaveDialog(frame) != JOptionPane.OK_OPTION) {
return;
}
final String xmlFile;
try {
gameData.acquireReadLock();
final GameDataExporter exporter = new GameDataExporter(gameData);
xmlFile = exporter.getXml();
} finally {
gameData.releaseReadLock();
}
try (Writer writer = Files.newBufferedWriter(chooser.getSelectedFile().toPath(), StandardCharsets.UTF_8)) {
writer.write(xmlFile);
} catch (final IOException e1) {
ClientLogger.logQuietly("Failed to write XML: " + chooser.getSelectedFile().getAbsolutePath(), e1);
}
}
Aggregations