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 {
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;
}
......
......@@ -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();
......
......@@ -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) {
......
......@@ -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);
......
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