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.
parent ac539686
...@@ -30,7 +30,7 @@ public class CityGmlZipArchive implements Serializable { ...@@ -30,7 +30,7 @@ public class CityGmlZipArchive implements Serializable {
private final String archiveNameRE; private final String archiveNameRE;
public static CityGmlZipArchive register(String zipFile) { public static CityGmlZipArchive register(String zipFile) throws MalformedZipFileException {
ArrayList<CityGmlZipEntry> archiveEntries = new ArrayList<>(); ArrayList<CityGmlZipEntry> archiveEntries = new ArrayList<>();
CityGmlZipArchive cgmlArchive = new CityGmlZipArchive(Path.of(zipFile)); CityGmlZipArchive cgmlArchive = new CityGmlZipArchive(Path.of(zipFile));
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) { try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) {
...@@ -47,17 +47,15 @@ public class CityGmlZipArchive implements Serializable { ...@@ -47,17 +47,15 @@ public class CityGmlZipArchive implements Serializable {
return cgmlArchive; return cgmlArchive;
} catch (IOException e) { } catch (IOException e) {
logger.error(Localization.getText("CityGmlZipArchive.ioError")); logger.error(Localization.getText("CityGmlZipArchive.ioError"));
logger.error(e.getMessage()); logger.debug(e.getMessage(), e);
logger.debug(e);
return null; return null;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.error(Localization.getText("CityGmlZipArchive.malformedZipFile")); logger.error(Localization.getText("CityGmlZipArchive.malformedZipFile"));
return null; throw new MalformedZipFileException(Localization.getText("CityGmlZipArchive.malformedZipFile"));
} catch (Exception e) { } catch (Exception e) {
logger.error(Localization.getText("CityGmlZipArchive.generalException")); logger.error(Localization.getText("CityGmlZipArchive.generalException"));
logger.error(e.getMessage()); logger.debug(e.getMessage(), e);
logger.debug(e); throw (e);
return null;
} }
} }
......
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 { ...@@ -20,7 +20,7 @@ public class ZipTest {
@Test @Test
public void testUnzipping() { public void testUnzipping() throws MalformedZipFileException {
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/mock_archive.zip"); CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/mock_archive.zip");
assertNotNull(cgmlArch); assertNotNull(cgmlArch);
cgmlArch.mountArchive(config); cgmlArch.mountArchive(config);
...@@ -65,7 +65,7 @@ public class ZipTest { ...@@ -65,7 +65,7 @@ public class ZipTest {
} }
@Test @Test
public void testEpsgParsing() { public void testEpsgParsing() throws MalformedZipFileException {
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/epsg.zip"); CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/epsg.zip");
assertNotNull(cgmlArch); assertNotNull(cgmlArch);
cgmlArch.mountArchive(config); cgmlArch.mountArchive(config);
...@@ -82,7 +82,7 @@ public class ZipTest { ...@@ -82,7 +82,7 @@ public class ZipTest {
} }
@Test @Test
public void testXMLValidation() { public void testXMLValidation() throws MalformedZipFileException {
ParserConfiguration valConfig = new ParserConfiguration(8, true); ParserConfiguration valConfig = new ParserConfiguration(8, true);
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/validate.zip"); CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/validate.zip");
assertNotNull(cgmlArch); assertNotNull(cgmlArch);
...@@ -94,7 +94,7 @@ public class ZipTest { ...@@ -94,7 +94,7 @@ public class ZipTest {
@Test @Test
public void testImplicitParsing() { public void testImplicitParsing() throws MalformedZipFileException {
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/implicit.zip"); CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/implicit.zip");
assertNotNull(cgmlArch); assertNotNull(cgmlArch);
cgmlArch.mountArchive(config); cgmlArch.mountArchive(config);
......
...@@ -14,9 +14,11 @@ import de.hft.stuttgart.citydoctor2.parser.*; ...@@ -14,9 +14,11 @@ import de.hft.stuttgart.citydoctor2.parser.*;
import de.hft.stuttgart.citydoctor2.utils.Localization; import de.hft.stuttgart.citydoctor2.utils.Localization;
import de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive; import de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive;
import de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry; import de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry;
import de.hft.stuttgart.citydoctor2.zip.MalformedZipFileException;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.chart.XYChart.Data; import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series; import javafx.scene.chart.XYChart.Series;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog; import javafx.scene.control.Dialog;
import javafx.scene.control.TreeItem; import javafx.scene.control.TreeItem;
...@@ -155,7 +157,20 @@ public class CityDoctorController { ...@@ -155,7 +157,20 @@ public class CityDoctorController {
boolean lowMemory) throws CityGmlParseException, InvalidGmlFileException { boolean lowMemory) throws CityGmlParseException, InvalidGmlFileException {
currentConfig = new ParserConfiguration(numberOfRoundingPlaces, useValidation, lowMemory); 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) { if (zipArchive != null) {
previousCheckers = new HashMap<>(); previousCheckers = new HashMap<>();
Platform.runLater(() -> { 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