From f8ac427e82b7e613e7ef80c5cea3fe4688dc222f Mon Sep 17 00:00:00 2001 From: Matthias Betz Date: Mon, 16 Nov 2020 16:14:26 +0100 Subject: [PATCH] validation changes to support healing streaming --- .../citydoctor2/parser/CityGmlParser.java | 23 ++++++++++++++++++- .../stuttgart/citydoctor2/check/Checker.java | 18 +++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java b/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java index 168fda5..77cddc1 100644 --- a/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java +++ b/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java @@ -220,7 +220,9 @@ public class CityGmlParser { CityGMLBuilder builder = context.createCityGMLBuilder(CityGmlParser.class.getClassLoader()); CityGMLInputFactory inputFactory = builder.createCityGMLInputFactory(); inputFactory.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_FEATURE); - inputFactory.setProperty(CityGMLInputFactory.USE_VALIDATION, config.getValidate()); + if (config != null) { + inputFactory.setProperty(CityGMLInputFactory.USE_VALIDATION, config.getValidate()); + } inputFactory.setProperty(CityGMLInputFactory.FAIL_ON_MISSING_ADE_SCHEMA, false); inputFactory.setProperty(CityGMLInputFactory.EXCLUDE_FROM_SPLITTING, new QName[] { new QName("WallSurface"), new QName("RoofSurface"), new QName("GroundSurface"), @@ -359,6 +361,25 @@ public class CityGmlParser { } return null; } + + public static CityModel parseOnlyCityModel(File inputFile) throws CityGmlParseException { + try { + CityGMLInputFactory inputFactory = setupGmlReader(null); + try (CityGMLReader reader = inputFactory.createCityGMLReader(inputFile)) { + while (reader.hasNext()) { + CityGML chunk = reader.nextFeature(); + if (chunk instanceof CityModel) { + CityModel cModel = (CityModel) chunk; + cModel.unsetCityObjectMember(); + return cModel; + } + } + } + } catch (CityGMLBuilderException | CityGMLReadException | ADEException e) { + throw new CityGmlParseException(e); + } + throw new CityGmlParseException("Did not find any CityModel in CityGML file"); + } private static void readFeatures(File file, ParserConfiguration config, CityGMLInputFactory inputFactory, ArrayBlockingQueue queue, ObservedInputStream ois, FeatureStream stream) { diff --git a/CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/Checker.java b/CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/Checker.java index 7449f95..7086dc5 100644 --- a/CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/Checker.java +++ b/CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/Checker.java @@ -210,8 +210,12 @@ public class Checker { } isValidated = true; } + + public ValidationConfiguration getConfig() { + return config; + } - private static SvrlContentHandler executeSchematronValidationIfAvailable(ValidationConfiguration config, + public static SvrlContentHandler executeSchematronValidationIfAvailable(ValidationConfiguration config, File file) { if (config.getSchematronFilePath() != null && !config.getSchematronFilePath().isEmpty()) { if (logger.isInfoEnabled()) { @@ -493,11 +497,11 @@ public class Checker { try (BufferedOutputStream xmlBos = getXmlOutputMaybe(xmlOutput); BufferedOutputStream pdfBos = getPdfOutputMaybe(pdfOutput)) { XmlStreamReporter xmlReporter = null; - if (xmlOutput != null) { + if (xmlBos != null) { xmlReporter = new XmlStreamReporter(xmlBos, stream.getFileName(), config); } PdfStreamReporter pdfReporter = null; - if (pdfOutput != null) { + if (pdfBos != null) { pdfReporter = new PdfStreamReporter(pdfBos, stream.getFileName(), config, logoLocation); } CityObject co = null; @@ -515,7 +519,7 @@ public class Checker { } } - private static void writeReport(StreamReporter reporter, SvrlContentHandler handler) + public static void writeReport(StreamReporter reporter, SvrlContentHandler handler) throws CheckReportWriteException { if (reporter != null) { if (handler != null) { @@ -530,15 +534,15 @@ public class Checker { } } - private static BufferedOutputStream getPdfOutputMaybe(String pdfOutput) throws FileNotFoundException { + public static BufferedOutputStream getPdfOutputMaybe(String pdfOutput) throws FileNotFoundException { return pdfOutput != null ? new BufferedOutputStream(new FileOutputStream(pdfOutput)) : null; } - private static BufferedOutputStream getXmlOutputMaybe(String xmlOutput) throws FileNotFoundException { + public static BufferedOutputStream getXmlOutputMaybe(String xmlOutput) throws FileNotFoundException { return xmlOutput != null ? new BufferedOutputStream(new FileOutputStream(xmlOutput)) : null; } - private void checkFeature(XmlStreamReporter xmlReporter, PdfStreamReporter pdfReporter, CityObject co) { + public void checkFeature(XmlStreamReporter xmlReporter, PdfStreamReporter pdfReporter, CityObject co) { if (logger.isDebugEnabled()) { logger.debug(Localization.getText("Checker.checkFeature"), co); } -- GitLab