Commit 54df2199 authored by Matthias Betz's avatar Matthias Betz
Browse files

Added more translation

parent fb27a687
Pipeline #1143 passed with stage
in 1 minute and 57 seconds
......@@ -38,7 +38,7 @@ public abstract class Checkable implements Serializable {
private static final long serialVersionUID = -1707871839265057882L;
private static Logger logger = LogManager.getLogger(Checkable.class);
private static final Logger logger = LogManager.getLogger(Checkable.class);
private EnumMap<CheckId, CheckResult> checkResults = new EnumMap<>(CheckId.class);
private boolean isValidated = false;
......@@ -168,9 +168,9 @@ public abstract class Checkable implements Serializable {
*/
public void addCheckResult(CheckResult cr) {
checkResults.put(cr.getCheckIdentifier(), cr);
if (cr.getResultStatus() == ResultStatus.ERROR) {
if (cr.getResultStatus() == ResultStatus.ERROR && logger.isDebugEnabled()) {
logger.debug("{} has found an error of type {}", cr.getCheckIdentifier(), cr.getError().getErrorId());
} else if (cr.getResultStatus() == ResultStatus.WARNING) {
} else if (cr.getResultStatus() == ResultStatus.WARNING && logger.isDebugEnabled()) {
logger.debug("{} has found a warning of type {}", cr.getCheckIdentifier(), cr.getError().getErrorId());
}
}
......
......@@ -18,6 +18,8 @@
*/
package de.hft.stuttgart.citydoctor2.check;
import de.hft.stuttgart.citydoctor2.utils.Localization;
/**
* A unit description. Used in the parameters of a check to specify what type of
* value is required.
......@@ -27,7 +29,7 @@ package de.hft.stuttgart.citydoctor2.check;
*/
public enum Unit {
KWH("kWh"), METER("m"), SQUARE_METER("m²"), CUBIC_METER("m³"), RADIAN("Radian"), NONE(""), DEGREE("Degree");
KWH("kWh"), METER("m"), SQUARE_METER("m²"), CUBIC_METER("m³"), RADIAN(Localization.getText("Unit.Radian")), NONE(""), DEGREE(Localization.getText("Unit.Degree"));
private String representation;
......
......@@ -80,6 +80,7 @@ import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.datastructure.WaterObject;
import de.hft.stuttgart.citydoctor2.math.graph.KDTree;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.Localization;
import de.hft.stuttgart.citydoctor2.utils.Pair;
/**
......@@ -91,7 +92,7 @@ import de.hft.stuttgart.citydoctor2.utils.Pair;
*/
public class FeatureMapper extends FeatureWalker {
private static Logger logger = LogManager.getLogger(FeatureMapper.class);
private static final Logger logger = LogManager.getLogger(FeatureMapper.class);
private CityDoctorModel model;
private ParserConfiguration config;
......@@ -142,7 +143,9 @@ public class FeatureMapper extends FeatureWalker {
for (Pair<String, Geometry> link : linkedPolygons) {
ConcretePolygon concPoly = polygons.get(link.getValue0());
if (concPoly == null) {
logger.warn("Polygon {} is referenced but not found in feature polygons", link.getValue0());
if (logger.isWarnEnabled()) {
logger.warn(Localization.getText("FeatureMapper.polygonUnreferenced"), link.getValue0());
}
continue;
}
LinkedPolygon lPoly = new LinkedPolygon(concPoly, link.getValue1());
......
......@@ -54,6 +54,7 @@ import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.Localization;
import de.hft.stuttgart.citydoctor2.utils.Pair;
/**
......@@ -63,7 +64,7 @@ import de.hft.stuttgart.citydoctor2.utils.Pair;
*/
public class GeometryMapper extends GeometryWalker {
private static Logger logger = LogManager.getLogger(GeometryMapper.class);
private static final Logger logger = LogManager.getLogger(GeometryMapper.class);
private Geometry geom;
private ParserConfiguration config;
......@@ -128,14 +129,13 @@ public class GeometryMapper extends GeometryWalker {
@Override
public void visit(org.citygml4j.model.gml.geometry.primitives.Polygon gmlPoly) {
if (!gmlPoly.isSetExterior()) {
logger.warn("Found polygon without exterior ring, ignoring");
if (logger.isWarnEnabled()) {
logger.warn(Localization.getText("GeometryMapper.emptyPolygon"));
}
return;
}
ConcretePolygon cdPoly = new ConcretePolygon();
if (gmlPoly.isSetId()) {
cdPoly.setGmlId(new GmlId(gmlPoly.getId()));
polygons.put(gmlPoly.getId(), cdPoly);
}
addPolygonToAvailablePolygons(gmlPoly, cdPoly);
geom.addPolygon(cdPoly);
if (bs != null) {
// polygon is part of a boundary surface
......@@ -167,6 +167,14 @@ public class GeometryMapper extends GeometryWalker {
}
}
private void addPolygonToAvailablePolygons(org.citygml4j.model.gml.geometry.primitives.Polygon gmlPoly,
ConcretePolygon cdPoly) {
if (gmlPoly.isSetId()) {
cdPoly.setGmlId(new GmlId(gmlPoly.getId()));
polygons.put(gmlPoly.getId(), cdPoly);
}
}
private void mapRing(AbstractRingProperty gmlRing, LinearRing cdRing) {
AbstractRing ringGeometry = gmlRing.getRing();
if (ringGeometry.isSetId()) {
......
......@@ -72,6 +72,7 @@ import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.datastructure.CityObject;
import de.hft.stuttgart.citydoctor2.mapper.FeatureMapper;
import de.hft.stuttgart.citydoctor2.math.Vector3d;
import de.hft.stuttgart.citydoctor2.utils.Localization;
/**
* Utility class to parse CityGML files.
......@@ -97,12 +98,12 @@ public class CityGmlParser {
// urn:adv:crs:ETRS89_UTM32*DE_DHHN92_NH
private static final Pattern P_URN = Pattern.compile("urn:adv:crs:([^\\*]+)");
private static SAXParserFactory factory;
private static final SAXParserFactory FACTORY;
static {
factory = SAXParserFactory.newInstance();
FACTORY = SAXParserFactory.newInstance();
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
FACTORY.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (SAXNotRecognizedException | SAXNotSupportedException | ParserConfigurationException e) {
logger.catching(e);
}
......@@ -142,13 +143,15 @@ public class CityGmlParser {
mapper.setCityModel(cModel);
}
}
logger.info("Parsed model with {} objects", mapper.getModel().getNumberOfFeatures());
if (logger.isInfoEnabled()) {
logger.info(Localization.getText("CityGmlParser.parsedObjects"), mapper.getModel().getNumberOfFeatures());
}
return mapper.getModel();
}
}
} catch (CityGMLReadException e) {
if (e.getCause() instanceof SAXParseException) {
throw new InvalidGmlFileException("This is not a valid GML-File\n" + e.getCause().getMessage(), e);
throw new InvalidGmlFileException(Localization.getText("CityGmlParser.notValidGmlFile") + e.getCause().getMessage(), e);
}
throw new CityGmlParseException(e);
} catch (IOException | CityGMLBuilderException | ParserConfigurationException | SAXException | ADEException e) {
......@@ -159,7 +162,9 @@ public class CityGmlParser {
// fallback solution is to parse the whole file at once
// problems with memory consumption may arise
try {
logger.warn("Failed to read GML file in chunks, falling back to reading the complete file", e);
if (logger.isWarnEnabled()) {
logger.warn(Localization.getText("CityGmlParser.chunkReadFailed"), e);
}
return parseCityGmlFileComplete(file, config, l);
} catch (CityGMLBuilderException | CityGMLReadException | IOException e1) {
throw new CityGmlParseException(e1);
......@@ -249,7 +254,7 @@ public class CityGmlParser {
}
readFeatures(file, config, inputFactory, queue, ois, stream);
} catch (IOException e) {
logger.error("Error while reading city gml file\n{}", e.getMessage());
logger.error(Localization.getText("CityGmlParser.errorReadingGmlFile"), e.getMessage());
logger.catching(Level.ERROR, e);
}
});
......@@ -377,7 +382,7 @@ public class CityGmlParser {
queue.put(FeatureStream.POISON);
logger.debug("End of gml file stream");
} catch (CityGMLReadException e) {
logger.error("Error while reading city gml file\n" + e.getMessage(), e);
logger.error(Localization.getText("CityGmlParser.errorReadingGmlFile"), e.getMessage(), e);
} catch (InterruptedException e) {
logger.warn("Interrupted while streaming gml file");
Thread.currentThread().interrupt();
......@@ -393,61 +398,71 @@ public class CityGmlParser {
private static void parseEpsgCodeFromStream(InputStream is, ParserConfiguration config)
throws ParserConfigurationException, SAXException {
SAXParser parser = factory.newSAXParser();
SAXParser parser = FACTORY.newSAXParser();
CityGmlHandler handler = new CityGmlHandler();
try {
parser.parse(new InputSource(is), handler);
} catch (EnvelopeFoundException e) {
try {
if (handler.getEpsg() == null) {
return;
}
CoordinateReferenceSystem crs = crsFromSrsName(handler.getEpsg());
if (crs == null) {
// could not find a coordinate system for srsName
// assuming metric system
return;
}
ProjectionUnitExtractor extractor = new ProjectionUnitExtractor(crs.getProjection());
if (extractor.getUnit() == Units.METRES) {
// coordinate system is in meters, do not convert
logger.info("Coordinate system is in meters, no conversion done");
return;
}
parseMeterConversion(config, crs);
Vector3d low = handler.getLowerCorner();
Vector3d up = handler.getUpperCorner();
double centerLong = low.getX() + ((up.getX() - low.getX()) / 2);
double centerLat = low.getY() + ((up.getY() - low.getY()) / 2);
if (!crs.getName().equals("EPSG:4326")) {
// need to convert coordinates first to WGS84, then find UTM Zone
CoordinateReferenceSystem wgs84 = crsFromSrsName("EPSG:4326");
ProjCoordinate p1 = new ProjCoordinate();
p1.setValue(centerLong, centerLat);
ProjCoordinate p2 = new ProjCoordinate();
BasicCoordinateTransform bct = new BasicCoordinateTransform(crs, wgs84);
bct.transform(p1, p2);
centerLong = p2.x;
centerLat = p2.y;
}
int zone = (int) (31 + Math.round(centerLong / 6));
CoordinateReferenceSystem utm;
if (centerLat < 0) {
// south
utm = CRS_FACTORY.createFromParameters("UTM", "+proj=utm +zone=" + zone + " +south");
} else {
// north
utm = CRS_FACTORY.createFromParameters("UTM", "+proj=utm +zone=" + zone);
}
config.setCoordinateSystem(crs, utm);
parseCoordinateSystem(config, handler);
} catch (Exception e2) {
logger.debug("Exception while parsing for EPSG code", e2);
logger.warn("Could not read EPSG code, assuming metric system");
if (logger.isWarnEnabled()) {
logger.warn(Localization.getText("CityGmlParser.noEPSG"));
}
}
} catch (Exception e) {
logger.debug("Exception while parsing for EPSG code", e);
logger.warn("Could not read EPSG code, assuming metric system");
if (logger.isWarnEnabled()) {
logger.warn(Localization.getText("CityGmlParser.noEPSG"));
}
}
}
private static void parseCoordinateSystem(ParserConfiguration config, CityGmlHandler handler) {
if (handler.getEpsg() == null) {
return;
}
CoordinateReferenceSystem crs = crsFromSrsName(handler.getEpsg());
if (crs == null) {
// could not find a coordinate system for srsName
// assuming metric system
return;
}
ProjectionUnitExtractor extractor = new ProjectionUnitExtractor(crs.getProjection());
if (extractor.getUnit() == Units.METRES) {
// coordinate system is in meters, do not convert
if (logger.isInfoEnabled()) {
logger.info(Localization.getText("CityGmlParser.noConversionNeeded"));
}
return;
}
parseMeterConversion(config, crs);
Vector3d low = handler.getLowerCorner();
Vector3d up = handler.getUpperCorner();
double centerLong = low.getX() + ((up.getX() - low.getX()) / 2);
double centerLat = low.getY() + ((up.getY() - low.getY()) / 2);
if (!crs.getName().equals("EPSG:4326")) {
// need to convert coordinates first to WGS84, then find UTM Zone
CoordinateReferenceSystem wgs84 = crsFromSrsName("EPSG:4326");
ProjCoordinate p1 = new ProjCoordinate();
p1.setValue(centerLong, centerLat);
ProjCoordinate p2 = new ProjCoordinate();
BasicCoordinateTransform bct = new BasicCoordinateTransform(crs, wgs84);
bct.transform(p1, p2);
centerLong = p2.x;
centerLat = p2.y;
}
int zone = (int) (31 + Math.round(centerLong / 6));
CoordinateReferenceSystem utm;
if (centerLat < 0) {
// south
utm = CRS_FACTORY.createFromParameters("UTM", "+proj=utm +zone=" + zone + " +south");
} else {
// north
utm = CRS_FACTORY.createFromParameters("UTM", "+proj=utm +zone=" + zone);
}
config.setCoordinateSystem(crs, utm);
}
private static void parseMeterConversion(ParserConfiguration config, CoordinateReferenceSystem crs) {
......
......@@ -78,4 +78,32 @@ ValidationConfiguration.reenable={} has been disabled but {} depends on it, reen
ValidationConfiguration.missingSchematron={} is not an existing file, disabling schematron check
CheckContainer.error=Unexpected exception while executing check: {}
Checks.missingCheck=Could not find check for id: {}
OpenFileDialog.cancelBtn=Cancel
\ No newline at end of file
OpenFileDialog.cancelBtn=Cancel
CheckDialog.checksTab=Checks
CheckDialog.filterTab=Filter
CheckDialog.globalParametersLabel=Global Parameters
CheckDialog.availableChecksLabel=Available Checks
CheckDialog.geometricChecksLabel=Geometric Checks
CheckDialog.semanticChecksLabel=Semantic Checks
CheckDialog.schematronFileLabel=Schematron File:
CheckDialog.selectBtn=Select
CheckDialog.checkBtn=Check
CheckDialog.cancelBtn=Cancel
WriteReportDialog.writeBtn=Save
WriteReportDialog.cancelBtn=Cancel
WriteReportDialog.errorStatisticsLabel=Error Statistics
WriteReportDialog.saveImageBtn=Save Image...
WriteReportDialog.selectPdfBtn=Select
WriteReportDialog.selectXmlFile=Select
WriteReportDialog.xAxisLabel=Error
WriteReportDialog.yAxisLabel=Count
Unit.Radian=Radian
Unit.Degree=Degree
FeatureMapper.polygonUnreferenced=Polygon {} is referenced but not found in feature polygons
GeometryMapper.emptyPolygon=Found polygon without exterior ring, ignoring
CityGmlParser.parsedObjects=Parsed model with {} objects
CityGmlParser.chunkReadFailed=Failed to read GML file in chunks, falling back to reading the complete file
CityGmlParser.notValidGmlFile=This is not a valid GML-File\n
CityGmlParser.errorReadingGmlFile=Error while reading city gml file\n{}
CityGmlParser.noConversionNeeded=Coordinate system is in meters, no conversion done
CityGmlParser.noEPSG=Could not read EPSG code, assuming metric system
\ No newline at end of file
......@@ -76,4 +76,32 @@ ValidationConfiguration.reenable={} ist deaktiviert wird aber von {} ben\u00f6ti
ValidationConfiguration.missingSchematron={} existiert nicht, deaktiviere Schematron Pr\u00fcfung
CheckContainer.error=Unerwarteter Fehler bei der Ausf\u00fchrung von Pr\u00fcfung: {}
Checks.missingCheck=Konnte keine Pr\u00fcfung f\u00fcr id {} finden
OpenFileDialog.cancelBtn=Abbrechen
\ No newline at end of file
OpenFileDialog.cancelBtn=Abbrechen
CheckDialog.checksTab=Pr\u00fcfungen
CheckDialog.filterTab=Filter
CheckDialog.globalParametersLabel=Globale Parameter
CheckDialog.availableChecksLabel=Verf\u00fcgbare Pr\u00fcfungen
CheckDialog.geometricChecksLabel=Geometrische Pr\u00fcfungen
CheckDialog.semanticChecksLabel=Semantische Pr\u00fcfungen
CheckDialog.schematronFileLabel=Schematron Datei
CheckDialog.selectBtn=Ausw\u00e4hlen
CheckDialog.checkBtn=Pr\u00fcfen
CheckDialog.cancelBtn=Abbrechen
WriteReportDialog.writeBtn=Speichern
WriteReportDialog.cancelBtn=Abbrechen
WriteReportDialog.errorStatisticsLabel=Fehler Statistik
WriteReportDialog.saveImageBtn=Bild Speichern
WriteReportDialog.selectPdfBtn=Ausw\u00e4hlen
WriteReportDialog.selectXmlFile=Ausw\u00e4hlen
WriteReportDialog.xAxisLabel=Fehler
WriteReportDialog.yAxisLabel=Anzahl
Unit.Radian=Radiant
Unit.Degree=Grad
FeatureMapper.polygonUnreferenced=Polygon {} ist referenziert wurde aber nicht in gefunden
GeometryMapper.emptyPolygon=Polygon ohne externen Ring gefunden, ignoriere
CityGmlParser.parsedObjects=Modell mit {} Objekten gelesen
CityGmlParser.chunkReadFailed=Konnte Datei nicht in St\u00fccken lesen, versuche komplett zu lesen
CityGmlParser.notValidGmlFile=Dies ist keine korrekte CityGML Datei\n
CityGmlParser.errorReadingGmlFile=Fehler beim lesen der CityGML Datei\n{}
CityGmlParser.noConversionNeeded=Koordinatensystem in Metern, keine Konvertierung notwendig
CityGmlParser.noEPSG=Konnte EPSG Code nicht lesen, nehme metrisches System an
\ No newline at end of file
......@@ -181,7 +181,9 @@ public class Checker {
config = ValidationConfiguration.loadStandardValidationConfig();
}
checkCityModel(model, l);
logger.info(Localization.getText("Checker.checksFinished"));
if (logger.isInfoEnabled()) {
logger.info(Localization.getText("Checker.checksFinished"));
}
SvrlContentHandler handler = executeSchematronValidationIfAvailable(config, model.getFile());
if (handler != null) {
model.addGlobalErrors(handler.getGeneralErrors());
......@@ -212,7 +214,9 @@ public class Checker {
private static SvrlContentHandler executeSchematronValidationIfAvailable(ValidationConfiguration config,
File file) {
if (config.getSchematronFilePath() != null && !config.getSchematronFilePath().isEmpty()) {
logger.info(Localization.getText("Checker.schematronValidation"));
if (logger.isInfoEnabled()) {
logger.info(Localization.getText("Checker.schematronValidation"));
}
Processor processor = new Processor(false);
XsltCompiler xsltCompiler = processor.newXsltCompiler();
xsltCompiler.setURIResolver(new URIResolver() {
......@@ -254,7 +258,9 @@ public class Checker {
Destination dest = new SAXDestination(handler);
schematronTransformer.setDestination(dest);
schematronTransformer.transform();
logger.info(Localization.getText("Checker.finishedSchematron"));
if (logger.isInfoEnabled()) {
logger.info(Localization.getText("Checker.finishedSchematron"));
}
return handler;
} catch (SaxonApiException | ParserConfigurationException e) {
logger.catching(e);
......
......@@ -35,12 +35,6 @@ import org.apache.logging.log4j.Logger;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.CollectionNode;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.SequenceNode;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
......@@ -108,40 +102,7 @@ public class ValidationConfiguration implements Serializable {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(true);
Representer rep = new Representer() {
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
Tag customTag) {
if (propertyValue == null) {
return null;
} else {
NodeTuple tuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
Node valueNode = tuple.getValueNode();
if (Tag.NULL.equals(valueNode.getTag())) {
// skip 'null' values
return null;
}
if (valueNode instanceof CollectionNode) {
if (Tag.SEQ.equals(valueNode.getTag())) {
SequenceNode seq = (SequenceNode) valueNode;
if (seq.getValue().isEmpty()) {
// skip empty lists
return null;
}
}
if (Tag.MAP.equals(valueNode.getTag())) {
MappingNode seq = (MappingNode) valueNode;
if (seq.getValue().isEmpty()) {
// skip empty maps
return null;
}
}
}
return tuple;
}
}
};
Representer rep = new ValidationConfigurationRepresenter();
rep.addClassTag(ValidationConfiguration.class, Tag.MAP);
Yaml yaml = new Yaml(rep, options);
try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
......@@ -201,6 +162,19 @@ public class ValidationConfiguration implements Serializable {
return cConfig;
});
}
reenableNecessaryChecks();
if (schematronFilePath != null && !schematronFilePath.isEmpty()) {
File f = new File(schematronFilePath);
if (!f.exists() || !f.isFile()) {
schematronFilePath = null;
if (logger.isWarnEnabled()) {
logger.warn(Localization.getText("ValidationConfiguration.missingSchematron"), f.getAbsolutePath());
}
}
}
}
private void reenableNecessaryChecks() {
for (java.util.Map.Entry<CheckId, CheckConfiguration> e : checks.entrySet()) {
if (!e.getValue().isEnabled()) {
continue;
......@@ -210,18 +184,13 @@ public class ValidationConfiguration implements Serializable {
CheckConfiguration checkConfig = checks.get(dep);
if (!checkConfig.isEnabled()) {
checkConfig.setEnabled(true);
logger.warn(Localization.getText("ValidationConfiguration.reenable"), dep, c.getCheckId());
if (logger.isWarnEnabled()) {
logger.warn(Localization.getText("ValidationConfiguration.reenable"), dep, c.getCheckId());
}
}
}
insertMissingParametersWithDefaultParameters(e, c);
}
if (schematronFilePath != null && !schematronFilePath.isEmpty()) {
File f = new File(schematronFilePath);
if (!f.exists() || !f.isFile()) {
schematronFilePath = null;
logger.warn(Localization.getText("ValidationConfiguration.missingSchematron"), f.getAbsolutePath());
}
}
}
private void insertMissingParametersWithDefaultParameters(java.util.Map.Entry<CheckId, CheckConfiguration> e,
......
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.check;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.CollectionNode;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.SequenceNode;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
/**
* Representer for configuration yaml files. Removing null and empty values as
* well as class annotations
*
* @author Matthias Betz
*
*/
public class ValidationConfigurationRepresenter extends Representer {
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
Tag customTag) {
if (propertyValue == null) {
return null;
} else {
NodeTuple tuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
Node valueNode = tuple.getValueNode();
if (Tag.NULL.equals(valueNode.getTag())) {
// skip 'null' values
return null;
}
return handleCollections(tuple, valueNode);
}
}
private NodeTuple handleCollections(NodeTuple tuple, Node valueNode) {
if (valueNode instanceof CollectionNode) {
if (Tag.SEQ.equals(valueNode.getTag())) {
SequenceNode seq = (SequenceNode) valueNode;
if (seq.getValue().isEmpty()) {
// skip empty lists
return null;
}
}
if (Tag.MAP.equals(valueNode.getTag())) {
MappingNode seq = (MappingNode) valueNode;
if (seq.getValue().isEmpty()) {
// skip empty maps
return null;
}
}
}
return tuple;
}
}
......@@ -91,7 +91,9 @@ public class CheckContainer extends Check {
}
private void handleException(Exception e, Checkable c) {
logger.error(Localization.getText("CheckContainer.error"), check.getCheckId(), e);
if (logger.isErrorEnabled()) {
logger.error(Localization.getText("CheckContainer.error"), check.getCheckId(), e);
}
CheckError err = new UnknownCheckError(c, e, this);
CheckResult cr = new CheckResult(check.getCheckId(), ResultStatus.ERROR, err);
c.addCheckResult(cr);
......
......@@ -144,7 +144,7 @@ public class Checks {
*/
public Check getCheckForId(CheckId id) {
Check c = checkMap.get(id);
if (c == null) {
if (c == null && logger.isWarnEnabled()) {
logger.warn(Localization.getText("Checks.missingCheck"), id);
}
return c;
......
......@@ -65,7 +65,7 @@ public class NullAreaCheck extends Check {
defaultParameters = Collections.unmodifiableList(defParameters);
}
private double delta = 0.0001d;
private double delta = 0.0001;
public NullAreaCheck() {
super(CheckId.NULL_AREA);
......
......@@ -57,8 +57,8 @@ import de.hft.stuttgart.citydoctor2.tesselation.TesselatedPolygon;
public class PlanarCheck extends Check {
private static final String DISTANCE = "distance";
private static final String DELTA_NAME = "distanceTolerance";
private static final String RADIANT = "angleTolerance";
private static final String DISTANCE_TOLERANCE = "distanceTolerance";
private static final String ANGLE_TOLERANCE = "angleTolerance";
private static final String TYPE = "type";
private static final String TINY_EDGE_TOLERANCE = "tinyEdgeTolerance";
......@@ -80,8 +80,8 @@ public class PlanarCheck extends Check {
ArrayList<DefaultParameter> defParameters = new ArrayList<>(3);
defParameters.add(new DefaultParameter(TYPE, DISTANCE, Unit.NONE));
defParameters.add(new DefaultParameter(DELTA_NAME, "0.01", Unit.METER));
defParameters.add(new DefaultParameter(RADIANT, "0.1", Unit.RADIAN));
defParameters.add(new DefaultParameter(DISTANCE_TOLERANCE, "0.01", Unit.METER));
defParameters.add(new DefaultParameter(ANGLE_TOLERANCE, "1", Unit.DEGREE));
defParameters.add(new DefaultParameter(TINY_EDGE_TOLERANCE, "0.00000", Unit.METER));
defaultParameters = Collections.unmodifiableList(defParameters);
......@@ -89,7 +89,7 @@ public class PlanarCheck extends Check {
private String planarCheckType = DISTANCE;
private double rad = 0.1;
private double rad = Math.toRadians(1);
private double delta = 0.01;
private double tinyEdgeTolerance = 0.00000;
......@@ -100,17 +100,17 @@ public class PlanarCheck extends Check {
@Override
public void init(Map<String, String> parameters, ParserConfiguration config) {
if (parameters.containsKey(TYPE)) {
planarCheckType = parameters.get(TYPE);
planarCheckType = parameters.get(TYPE).toLowerCase();
} else {
planarCheckType = DISTANCE;
}
if (parameters.containsKey(RADIANT)) {
rad = Double.parseDouble(parameters.get(RADIANT));
if (parameters.containsKey(ANGLE_TOLERANCE)) {
rad = Math.toRadians(Double.parseDouble(parameters.get(ANGLE_TOLERANCE)));
} else {
rad = 0.1;
rad = Math.toRadians(1);
}
if (parameters.containsKey(DELTA_NAME)) {
delta = Double.parseDouble(parameters.get(DELTA_NAME));
if (parameters.containsKey(DISTANCE_TOLERANCE)) {
delta = Double.parseDouble(parameters.get(DISTANCE_TOLERANCE));
} else {
delta = 0.01;
}
......
......@@ -49,11 +49,11 @@ public class RoofSurfaceUnfragmentedCheck extends Check {
private static final String MAX_ANGLE_DEVIATION = "maxAngleDeviation";
private double maxAngleDeviation = 0.1;
private double maxAngleDeviation = Math.toRadians(1);
static {
ArrayList<DefaultParameter> defParameters = new ArrayList<>(3);
defParameters.add(new DefaultParameter(MAX_ANGLE_DEVIATION, "0.1", Unit.RADIAN));
defParameters.add(new DefaultParameter(MAX_ANGLE_DEVIATION, "1", Unit.DEGREE));
defaultParameters = Collections.unmodifiableList(defParameters);
ArrayList<CheckId> deps = new ArrayList<>();
......@@ -77,7 +77,7 @@ public class RoofSurfaceUnfragmentedCheck extends Check {
public void init(Map<String, String> params, ParserConfiguration config) {
String maxAngleString = params.get(MAX_ANGLE_DEVIATION);
if (maxAngleString != null) {
maxAngleDeviation = Double.parseDouble(maxAngleString);
maxAngleDeviation = Math.toRadians(Double.parseDouble(maxAngleString));
}
}
......
......@@ -34,7 +34,7 @@ public class Table {
private Element tableHeader;
private Element tableBody;
private Element table;
private Element tableElement;
private int columns;
......@@ -44,18 +44,18 @@ public class Table {
tableBlock.setAttribute("padding-after", "10");
tableBlock.setAttribute("keep-together", "always");
table = new Element("table", PdfReport.FO_NS);
tableBlock.addContent(table);
PdfReport.applySolidBorder(table);
table.setAttribute("table-layout", "fixed");
table.setAttribute("width", "100%");
tableElement = new Element("table", PdfReport.FO_NS);
tableBlock.addContent(tableElement);
PdfReport.applySolidBorder(tableElement);
tableElement.setAttribute("table-layout", "fixed");
tableElement.setAttribute("width", "100%");
tableHeader = new Element("table-header", PdfReport.FO_NS);
table.addContent(tableHeader);
tableElement.addContent(tableHeader);
tableHeader.setAttribute("background-color", TABLE_HEADER_COLOR);
tableBody = new Element("table-body", PdfReport.FO_NS);
table.addContent(tableBody);
tableElement.addContent(tableBody);
}
public void setTableColumnWidth(int... width) {
......@@ -69,7 +69,7 @@ public class Table {
for (int i = 1; i <= width.length; i++) {
int w = width[i - 1];
Element tableColumn = new Element("table-column", PdfReport.FO_NS);
table.addContent(i - 1, tableColumn);
tableElement.addContent(i - 1, tableColumn);
tableColumn.setAttribute("column-number", "" + i);
tableColumn.setAttribute("column-width", w + "%");
}
......
Markdown is supported
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