diff --git a/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/datastructure/LibraryObject.java b/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/datastructure/LibraryObject.java index 331661328cf458f9ff79b29dc3c01f574efcbfe9..b696b510bb40c22d5ad5701433c8c64f93d87adf 100644 --- a/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/datastructure/LibraryObject.java +++ b/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/datastructure/LibraryObject.java @@ -66,16 +66,13 @@ public class LibraryObject extends Geometry { Geometry geo = null; if (path.toFile().exists()) { try { - CityGmlParser.gagLogger(true); - geo = getProtoGeometry(CityGmlParser.parseCityGmlFile(path.toString(), config)); + geo = getProtoGeometry(CityGmlParser.parseCityGmlFileSilently(path.toString(), config)); } catch (CityGmlParseException e) { logger.error(String.format( "Encountered an error while parsing library object %s", path)); logger.error(e.getStackTrace()); } catch (InvalidGmlFileException e) { logger.error(e.getStackTrace()); - } finally { - CityGmlParser.gagLogger(false); } } else { logger.error(String.format("Implicit geometry references non-existing library object file %s.", path)); @@ -94,9 +91,6 @@ public class LibraryObject extends Geometry { logger.error(String.format( "Encountered an error while parsing library object %s", entry.getFileName())); logger.error(e.getStackTrace()); - } finally { - //Gag logger again for next entry - CityGmlParser.gagLogger(true); } return geo; } 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 567e60b8f3b959ef042ba889a06df4fb927ef35d..660370bbf9bb20680351379bca64449603a1ff68 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 @@ -117,8 +117,6 @@ public class CityGmlParser { private static CityGMLContext context; private static List<QName> chunkProperties = new ArrayList<>(); - // Toggle to suppress logger output for parsing of libraryObjects - private static boolean gagged = false; static { System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); @@ -155,18 +153,23 @@ public class CityGmlParser { return context; } + public static CityDoctorModel parseCityGmlFileSilently(String file, ParserConfiguration config) + throws CityGmlParseException, InvalidGmlFileException { + return parseCityGmlFile(file, config, null, null, false); + } + public static CityDoctorModel parseCityGmlFile(String file, ParserConfiguration config) throws CityGmlParseException, InvalidGmlFileException { - return parseCityGmlFile(file, config, null, null); + return parseCityGmlFile(file, config, null, null, true); } public static CityDoctorModel parseCityGmlFile(String file, ParserConfiguration config, ProgressListener l) throws CityGmlParseException, InvalidGmlFileException { - return parseCityGmlFile(file, config, l, null); + return parseCityGmlFile(file, config, l, null, true); } public static CityDoctorModel parseCityGmlFile(String filePath, ParserConfiguration config, ProgressListener l, - GMLValidationHandler handler) throws CityGmlParseException, InvalidGmlFileException { + GMLValidationHandler handler, boolean verbose) throws CityGmlParseException, InvalidGmlFileException { CityGMLContext context = getContext(); Path file = Paths.get(filePath); if (config.getValidate()) { @@ -184,7 +187,7 @@ public class CityGmlParser { if (l != null) { ois.addListener(l::updateProgress); } - return readAndKeepFeatures(config, file, in, ois); + return readAndKeepFeatures(config, file, in, ois, verbose); } } catch (CityGMLReadException | IOException e) { throw new CityGmlParseException("Failed to read CityGML file", e); @@ -226,7 +229,7 @@ public class CityGmlParser { if (l != null){ ois.addListener(l::updateProgress); } - return readAndKeepFeatures(config, entry, in, ois); + return readAndKeepFeatures(config, entry, in, ois, false); } } catch (CityGMLReadException | IOException e) { throw new CityGmlParseException("Failed to read CityGML file", e); @@ -236,8 +239,8 @@ public class CityGmlParser { } private static CityDoctorModel readAndKeepFeatures(ParserConfiguration config, CityGmlZipEntry entry, - CityGMLInputFactory inputFactory, ObservedInputStream ois) throws CityGMLReadException { - return readAndKeepModel(new Citygml3FeatureMapper(config, entry), inputFactory, ois); + CityGMLInputFactory inputFactory, ObservedInputStream ois, boolean verbose) throws CityGMLReadException { + return readAndKeepModel(new Citygml3FeatureMapper(config, entry), inputFactory, ois, verbose); } private static List<String> validateStream(InputStream vis, CityGMLContext context) throws CityGmlParseException { @@ -422,21 +425,13 @@ public class CityGmlParser { return writer; } - /** - * Suppresses logger output of {@link #readAndKeepFeatures} for the next parse. - * Used to prevent logging spam while resolving implicit geometries and zip-files. - */ - public static void gagLogger(boolean value){ - gagged = value; - } - private static CityDoctorModel readAndKeepFeatures(ParserConfiguration config, Path file, - CityGMLInputFactory inputFactory, ObservedInputStream ois) throws CityGMLReadException { - return readAndKeepModel(new Citygml3FeatureMapper(config, file), inputFactory, ois); + CityGMLInputFactory inputFactory, ObservedInputStream ois, boolean verbose) throws CityGMLReadException { + return readAndKeepModel(new Citygml3FeatureMapper(config, file), inputFactory, ois, verbose); } private static CityDoctorModel readAndKeepModel(Citygml3FeatureMapper mapper, CityGMLInputFactory inputFactory, - ObservedInputStream ois) throws CityGMLReadException{ + ObservedInputStream ois, boolean verbose) throws CityGMLReadException{ try (CityGMLReader reader = inputFactory.createCityGMLReader(ois)) { CityGMLVersion version = null; // model is read in chunked mode @@ -471,12 +466,9 @@ public class CityGmlParser { for (AbstractCityObject aco : acos) { cModel.getCityObjectMembers().add(new AbstractCityObjectProperty(aco)); } - if (logger.isInfoEnabled() && !gagged) { + if (logger.isInfoEnabled() && verbose) { logger.info(Localization.getText("CityGmlParser.parsedObjects"), mapper.getModel().getNumberOfFeatures()); - } else if (gagged){ - // Remove gag - gagged = false; } mapper.setCityGMLVersion(version); return mapper.getModel(); diff --git a/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java b/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java index 707091d16ad2ff6d8a513cd186b1180c25ce81ed..b1f3215ea242217bbb240c2dff58ed1a19543fd0 100644 --- a/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java +++ b/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/zip/CityGmlZipEntry.java @@ -42,7 +42,6 @@ public class CityGmlZipEntry implements Serializable { return; } try{ - CityGmlParser.gagLogger(true); this.model = CityGmlParser.parseCityGmlZipEntry(this, config); this.decompressed = true; } catch (CityGmlParseException | InvalidGmlFileException e) { diff --git a/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/CityDoctorController.java b/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/CityDoctorController.java index b8fa7c0914b229fc5ad51a22cda14cf6b3bceffa..dbe8f8bc5fa730578b5f0592626b82656406a873 100644 --- a/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/CityDoctorController.java +++ b/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/CityDoctorController.java @@ -108,7 +108,7 @@ public class CityDoctorController { } }; } - model = CityGmlParser.parseCityGmlFile(path, currentConfig, l, handler); + model = CityGmlParser.parseCityGmlFile(path, currentConfig, l, handler, true); if (!validationIssues.isEmpty()) { StringJoiner sj = new StringJoiner("\n"); validationIssues.stream().forEach(sj::add);