Commit 5863dc7d authored by Riegel's avatar Riegel
Browse files

Refactor: Add error alerts for ZIP file parsing

Adds alerts to inform the user of Exceptions/Errors that occurred while
parsing a ZIP file, instead of silently failing and closing the
openFileDialog window.
2 merge requests!28Version 3.17.0 Release,!26Add ZIP-archive support
Showing with 39 additions and 12 deletions
+39 -12
......@@ -30,7 +30,7 @@ public class CityGmlZipArchive implements Serializable {
private final String archiveNameRE;
public static CityGmlZipArchive register(String zipFile) {
public static CityGmlZipArchive register(String zipFile) throws MalformedZipFileException {
ArrayList<CityGmlZipEntry> archiveEntries = new ArrayList<>();
CityGmlZipArchive cgmlArchive = new CityGmlZipArchive(Path.of(zipFile));
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) {
......@@ -47,17 +47,15 @@ public class CityGmlZipArchive implements Serializable {
return cgmlArchive;
} catch (IOException e) {
logger.error(Localization.getText("CityGmlZipArchive.ioError"));
logger.error(e.getMessage());
logger.debug(e);
logger.debug(e.getMessage(), e);
return null;
} catch (IllegalArgumentException e) {
logger.error(Localization.getText("CityGmlZipArchive.malformedZipFile"));
return null;
throw new MalformedZipFileException(Localization.getText("CityGmlZipArchive.malformedZipFile"));
} catch (Exception e) {
logger.error(Localization.getText("CityGmlZipArchive.generalException"));
logger.error(e.getMessage());
logger.debug(e);
return null;
logger.debug(e.getMessage(), e);
throw (e);
}
}
......
package de.hft.stuttgart.citydoctor2.zip;
import java.util.zip.ZipException;
public class MalformedZipFileException extends ZipException {
public MalformedZipFileException() {
super();
}
public MalformedZipFileException(String message) {
super(message);
}
}
......@@ -20,7 +20,7 @@ public class ZipTest {
@Test
public void testUnzipping() {
public void testUnzipping() throws MalformedZipFileException {
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/mock_archive.zip");
assertNotNull(cgmlArch);
cgmlArch.mountArchive(config);
......@@ -65,7 +65,7 @@ public class ZipTest {
}
@Test
public void testEpsgParsing() {
public void testEpsgParsing() throws MalformedZipFileException {
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/epsg.zip");
assertNotNull(cgmlArch);
cgmlArch.mountArchive(config);
......@@ -82,7 +82,7 @@ public class ZipTest {
}
@Test
public void testXMLValidation() {
public void testXMLValidation() throws MalformedZipFileException {
ParserConfiguration valConfig = new ParserConfiguration(8, true);
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/validate.zip");
assertNotNull(cgmlArch);
......@@ -94,7 +94,7 @@ public class ZipTest {
@Test
public void testImplicitParsing() {
public void testImplicitParsing() throws MalformedZipFileException {
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/implicit.zip");
assertNotNull(cgmlArch);
cgmlArch.mountArchive(config);
......
......@@ -14,9 +14,11 @@ import de.hft.stuttgart.citydoctor2.parser.*;
import de.hft.stuttgart.citydoctor2.utils.Localization;
import de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive;
import de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry;
import de.hft.stuttgart.citydoctor2.zip.MalformedZipFileException;
import javafx.application.Platform;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.TreeItem;
......@@ -155,7 +157,20 @@ public class CityDoctorController {
boolean lowMemory) throws CityGmlParseException, InvalidGmlFileException {
currentConfig = new ParserConfiguration(numberOfRoundingPlaces, useValidation, lowMemory);
zipArchive = CityGmlZipArchive.register(path);
try {
zipArchive = CityGmlZipArchive.register(path);
} catch (MalformedZipFileException e) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.ERROR, e.getMessage());
alert.showAndWait();
});
} catch (Exception e) {
Platform.runLater(() -> {
ExceptionDialog exDialog = new ExceptionDialog();
exDialog.show(e);
});
}
if (zipArchive != null) {
previousCheckers = new HashMap<>();
Platform.runLater(() -> {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment