Commit 988e20e4 authored by Riegel's avatar Riegel
Browse files

Refactor: Rework suppression of CityGmlParser logger

Replaced the static logging-suppression flag with an argument parameter
to prevent the emergence of a race condition.
2 merge requests!28Version 3.17.0 Release,!26Add ZIP-archive support
Showing with 18 additions and 33 deletions
+18 -33
...@@ -66,16 +66,13 @@ public class LibraryObject extends Geometry { ...@@ -66,16 +66,13 @@ public class LibraryObject extends Geometry {
Geometry geo = null; Geometry geo = null;
if (path.toFile().exists()) { if (path.toFile().exists()) {
try { try {
CityGmlParser.gagLogger(true); geo = getProtoGeometry(CityGmlParser.parseCityGmlFileSilently(path.toString(), config));
geo = getProtoGeometry(CityGmlParser.parseCityGmlFile(path.toString(), config));
} catch (CityGmlParseException e) { } catch (CityGmlParseException e) {
logger.error(String.format( logger.error(String.format(
"Encountered an error while parsing library object %s", path)); "Encountered an error while parsing library object %s", path));
logger.error(e.getStackTrace()); logger.error(e.getStackTrace());
} catch (InvalidGmlFileException e) { } catch (InvalidGmlFileException e) {
logger.error(e.getStackTrace()); logger.error(e.getStackTrace());
} finally {
CityGmlParser.gagLogger(false);
} }
} else { } else {
logger.error(String.format("Implicit geometry references non-existing library object file %s.", path)); logger.error(String.format("Implicit geometry references non-existing library object file %s.", path));
...@@ -94,9 +91,6 @@ public class LibraryObject extends Geometry { ...@@ -94,9 +91,6 @@ public class LibraryObject extends Geometry {
logger.error(String.format( logger.error(String.format(
"Encountered an error while parsing library object %s", entry.getFileName())); "Encountered an error while parsing library object %s", entry.getFileName()));
logger.error(e.getStackTrace()); logger.error(e.getStackTrace());
} finally {
//Gag logger again for next entry
CityGmlParser.gagLogger(true);
} }
return geo; return geo;
} }
......
...@@ -117,8 +117,6 @@ public class CityGmlParser { ...@@ -117,8 +117,6 @@ public class CityGmlParser {
private static CityGMLContext context; private static CityGMLContext context;
private static List<QName> chunkProperties = new ArrayList<>(); private static List<QName> chunkProperties = new ArrayList<>();
// Toggle to suppress logger output for parsing of libraryObjects
private static boolean gagged = false;
static { static {
System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
...@@ -155,18 +153,23 @@ public class CityGmlParser { ...@@ -155,18 +153,23 @@ public class CityGmlParser {
return context; 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) public static CityDoctorModel parseCityGmlFile(String file, ParserConfiguration config)
throws CityGmlParseException, InvalidGmlFileException { 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) public static CityDoctorModel parseCityGmlFile(String file, ParserConfiguration config, ProgressListener l)
throws CityGmlParseException, InvalidGmlFileException { 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, 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(); CityGMLContext context = getContext();
Path file = Paths.get(filePath); Path file = Paths.get(filePath);
if (config.getValidate()) { if (config.getValidate()) {
...@@ -184,7 +187,7 @@ public class CityGmlParser { ...@@ -184,7 +187,7 @@ public class CityGmlParser {
if (l != null) { if (l != null) {
ois.addListener(l::updateProgress); ois.addListener(l::updateProgress);
} }
return readAndKeepFeatures(config, file, in, ois); return readAndKeepFeatures(config, file, in, ois, verbose);
} }
} catch (CityGMLReadException | IOException e) { } catch (CityGMLReadException | IOException e) {
throw new CityGmlParseException("Failed to read CityGML file", e); throw new CityGmlParseException("Failed to read CityGML file", e);
...@@ -226,7 +229,7 @@ public class CityGmlParser { ...@@ -226,7 +229,7 @@ public class CityGmlParser {
if (l != null){ if (l != null){
ois.addListener(l::updateProgress); ois.addListener(l::updateProgress);
} }
return readAndKeepFeatures(config, entry, in, ois); return readAndKeepFeatures(config, entry, in, ois, false);
} }
} catch (CityGMLReadException | IOException e) { } catch (CityGMLReadException | IOException e) {
throw new CityGmlParseException("Failed to read CityGML file", e); throw new CityGmlParseException("Failed to read CityGML file", e);
...@@ -236,8 +239,8 @@ public class CityGmlParser { ...@@ -236,8 +239,8 @@ public class CityGmlParser {
} }
private static CityDoctorModel readAndKeepFeatures(ParserConfiguration config, CityGmlZipEntry entry, private static CityDoctorModel readAndKeepFeatures(ParserConfiguration config, CityGmlZipEntry entry,
CityGMLInputFactory inputFactory, ObservedInputStream ois) throws CityGMLReadException { CityGMLInputFactory inputFactory, ObservedInputStream ois, boolean verbose) throws CityGMLReadException {
return readAndKeepModel(new Citygml3FeatureMapper(config, entry), inputFactory, ois); return readAndKeepModel(new Citygml3FeatureMapper(config, entry), inputFactory, ois, verbose);
} }
private static List<String> validateStream(InputStream vis, CityGMLContext context) throws CityGmlParseException { private static List<String> validateStream(InputStream vis, CityGMLContext context) throws CityGmlParseException {
...@@ -422,21 +425,13 @@ public class CityGmlParser { ...@@ -422,21 +425,13 @@ public class CityGmlParser {
return writer; 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, private static CityDoctorModel readAndKeepFeatures(ParserConfiguration config, Path file,
CityGMLInputFactory inputFactory, ObservedInputStream ois) throws CityGMLReadException { CityGMLInputFactory inputFactory, ObservedInputStream ois, boolean verbose) throws CityGMLReadException {
return readAndKeepModel(new Citygml3FeatureMapper(config, file), inputFactory, ois); return readAndKeepModel(new Citygml3FeatureMapper(config, file), inputFactory, ois, verbose);
} }
private static CityDoctorModel readAndKeepModel(Citygml3FeatureMapper mapper, CityGMLInputFactory inputFactory, private static CityDoctorModel readAndKeepModel(Citygml3FeatureMapper mapper, CityGMLInputFactory inputFactory,
ObservedInputStream ois) throws CityGMLReadException{ ObservedInputStream ois, boolean verbose) throws CityGMLReadException{
try (CityGMLReader reader = inputFactory.createCityGMLReader(ois)) { try (CityGMLReader reader = inputFactory.createCityGMLReader(ois)) {
CityGMLVersion version = null; CityGMLVersion version = null;
// model is read in chunked mode // model is read in chunked mode
...@@ -471,12 +466,9 @@ public class CityGmlParser { ...@@ -471,12 +466,9 @@ public class CityGmlParser {
for (AbstractCityObject aco : acos) { for (AbstractCityObject aco : acos) {
cModel.getCityObjectMembers().add(new AbstractCityObjectProperty(aco)); cModel.getCityObjectMembers().add(new AbstractCityObjectProperty(aco));
} }
if (logger.isInfoEnabled() && !gagged) { if (logger.isInfoEnabled() && verbose) {
logger.info(Localization.getText("CityGmlParser.parsedObjects"), logger.info(Localization.getText("CityGmlParser.parsedObjects"),
mapper.getModel().getNumberOfFeatures()); mapper.getModel().getNumberOfFeatures());
} else if (gagged){
// Remove gag
gagged = false;
} }
mapper.setCityGMLVersion(version); mapper.setCityGMLVersion(version);
return mapper.getModel(); return mapper.getModel();
......
...@@ -42,7 +42,6 @@ public class CityGmlZipEntry implements Serializable { ...@@ -42,7 +42,6 @@ public class CityGmlZipEntry implements Serializable {
return; return;
} }
try{ try{
CityGmlParser.gagLogger(true);
this.model = CityGmlParser.parseCityGmlZipEntry(this, config); this.model = CityGmlParser.parseCityGmlZipEntry(this, config);
this.decompressed = true; this.decompressed = true;
} catch (CityGmlParseException | InvalidGmlFileException e) { } catch (CityGmlParseException | InvalidGmlFileException e) {
......
...@@ -108,7 +108,7 @@ public class CityDoctorController { ...@@ -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()) { if (!validationIssues.isEmpty()) {
StringJoiner sj = new StringJoiner("\n"); StringJoiner sj = new StringJoiner("\n");
validationIssues.stream().forEach(sj::add); validationIssues.stream().forEach(sj::add);
......
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