diff --git a/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/CityGmlZipEntry.java b/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/CityGmlZipEntry.java index 247ebe4de82ed2c178a04803f8804905fef8db99..b60591bef174c16e8c961207d688980658c94b8b 100644 --- a/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/CityGmlZipEntry.java +++ b/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/CityGmlZipEntry.java @@ -9,23 +9,15 @@ import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Enumeration; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; public class CityGmlZipEntry { private static final Logger logger = LogManager.getLogger(CityGmlZipEntry.class); - public enum ZipEntryErrorType { - INVALID_CITY_GML_FILE, EXCESSIVE_FILESIZE, IO_ERROR - } - private String fileName; private String archivePath; private CityDoctorModel model; @@ -40,8 +32,7 @@ public class CityGmlZipEntry { cgzEntry.fileName = entry.getName(); cgzEntry.archivePath = archivePath; if ((double) entry.getSize() /1024/1024 > 20) { - cgzEntry.erroneousEntry = true; - cgzEntry.errorType = ZipEntryErrorType.EXCESSIVE_FILESIZE; + return new ErroneousEntry(entry, ZipEntryErrorType.EXCESSIVE_FILESIZE); } else { try { Files.copy(is, Path.of(tempDir.toString(), entry.getName())); @@ -49,21 +40,25 @@ public class CityGmlZipEntry { cgzEntry.model = CityGmlParser.parseCityGmlFile(tempDir.toString() + File.separator + entry.getName(), config); } catch (CityGmlParseException | InvalidGmlFileException e) { logger.error(e); - cgzEntry.erroneousEntry = true; - cgzEntry.errorType = ZipEntryErrorType.INVALID_CITY_GML_FILE; + return new ErroneousEntry(entry, ZipEntryErrorType.INVALID_CITY_GML_FILE); } catch (IOException e){ logger.error(e); - cgzEntry.erroneousEntry = true; - cgzEntry.errorType = ZipEntryErrorType.IO_ERROR; + return new ErroneousEntry(entry, ZipEntryErrorType.IO_ERROR); } } return cgzEntry; } + private CityGmlZipEntry(String filename, CityDoctorModel model){ + this.fileName = filename; + this.model = model; + } + + protected CityGmlZipEntry(ZipEntry entry) { + this.fileName = entry.getName(); + this.model = null; + } public void validateModel(){ - if(erroneousEntry){ - return; - } Checker checker = new Checker(this.getModel()); checker.runChecks(); validated = true; @@ -73,31 +68,12 @@ public class CityGmlZipEntry { return validated; } - public void setIsLibraryObject(boolean isLibraryObject) { - this.isLibraryObject = isLibraryObject; - } - public String getFileName() { return fileName; } - public String getArchivePath() { - return archivePath; - } - public CityDoctorModel getModel() { return model; } - public ZipEntryErrorType getErrorType() { - return errorType; - } - - public boolean isLibraryObject() { - return isLibraryObject; - } - - public boolean isErroneousEntry() { - return erroneousEntry; - } } diff --git a/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/ErroneousEntry.java b/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/ErroneousEntry.java new file mode 100644 index 0000000000000000000000000000000000000000..c3be0a8aade3f8999d5237f270aaee4bf3bec9d0 --- /dev/null +++ b/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/ErroneousEntry.java @@ -0,0 +1,29 @@ +package de.hft.stuttgart.citydoctor2.ziploader; + +import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel; + +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +public class ErroneousEntry extends CityGmlZipEntry { + + + + private ZipEntryErrorType errorType = null; + + public ErroneousEntry(ZipEntry entry, ZipEntryErrorType errorType){ + super(entry); + } + + @Override + public void validateModel(){} + + @Override + public CityDoctorModel getModel(){ + return null; + } + + public ZipEntryErrorType getErrorType() { + return errorType; + } +} diff --git a/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/ZipEntryErrorType.java b/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/ZipEntryErrorType.java new file mode 100644 index 0000000000000000000000000000000000000000..d1d4faefe7c9123171c8cad4bd9b7b9871a62752 --- /dev/null +++ b/CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/ZipEntryErrorType.java @@ -0,0 +1,5 @@ +package de.hft.stuttgart.citydoctor2.ziploader; + +public enum ZipEntryErrorType { + INVALID_CITY_GML_FILE, EXCESSIVE_FILESIZE, IO_ERROR +}