make report optional

This commit is contained in:
apenski 2022-11-09 16:34:07 +01:00
parent 9f3ded6e5b
commit 55ec1dc560
4 changed files with 73 additions and 30 deletions

View file

@ -69,6 +69,8 @@ public class ConfigurationLoader {
private static final String SUPPORTED_MAJOR_VERSION_SCHEMA = "http://www.xoev.de/de/validator/framework/1/scenarios";
protected final Map<String, Object> parameters = new HashMap<>();
/**
* URL, die auf die scenerio.xml Datei zeigt.
*/
@ -84,16 +86,6 @@ public class ConfigurationLoader {
protected ResolvingConfigurationStrategy resolvingConfigurationStrategy;
protected final Map<String, Object> parameters = new HashMap<>();
URI getScenarioRepository() {
if (this.scenarioRepository == null) {
log.info("Creating default scenario repository (alongside scenario definition)");
return RelativeUriResolver.resolve(URI.create("."), this.scenarioDefinition);
}
return this.scenarioRepository;
}
private static void checkVersion(final URI scenarioDefinition, final Processor processor) {
try {
final Result<XdmNode, XMLSyntaxError> result = new DocumentParseAction(processor)
@ -132,6 +124,38 @@ public class ConfigurationLoader {
}
private static List<Scenario> initializeScenarios(final Scenarios def, final ContentRepository contentRepository) {
return def.getScenario().stream().map(s -> initialize(s, contentRepository)).collect(Collectors.toList());
}
private static Scenario initialize(final ScenarioType def, final ContentRepository repository) {
final Scenario s = new Scenario(def);
s.setMatchExecutable(repository.createMatchExecutable(def));
s.setSchema(repository.createSchema(def));
s.setSchematronValidations(repository.createSchematronTransformations(def));
if (def.getCreateReport() != null) {
s.setReportTransformation(repository.createReportTransformation(def));
} else {
log.warn("No report configured. Will provide an internal format as report!");
s.setReportTransformation(repository.createIdentityTransformation());
}
s.setFactory(repository.getResolvingConfigurationStrategy());
s.setUriResolver(repository.getResolver());
s.setUnparsedTextURIResolver(repository.getUnparsedTextURIResolver());
if (def.getAcceptMatch() != null) {
s.setAcceptExecutable(repository.createAccepptExecutable(def));
}
return s;
}
URI getScenarioRepository() {
if (this.scenarioRepository == null) {
log.info("Creating default scenario repository (alongside scenario definition)");
return RelativeUriResolver.resolve(URI.create("."), this.scenarioDefinition);
}
return this.scenarioRepository;
}
public Configuration build(final Processor processor) {
final ResolvingConfigurationStrategy resolving = getResolvingConfigurationStrategy();
final ContentRepository contentRepository = new ContentRepository(processor, resolving, getScenarioRepository());
@ -150,10 +174,6 @@ public class ConfigurationLoader {
return (configuration);
}
private static List<Scenario> initializeScenarios(final Scenarios def, final ContentRepository contentRepository) {
return def.getScenario().stream().map(s -> initialize(s, contentRepository)).collect(Collectors.toList());
}
private ResolvingConfigurationStrategy getResolvingConfigurationStrategy() {
if (this.resolvingConfigurationStrategy != null) {
log.info("Custom resolving strategy supplied. Please take care of xml security!");
@ -179,21 +199,6 @@ public class ConfigurationLoader {
}
private static Scenario initialize(final ScenarioType def, final ContentRepository repository) {
final Scenario s = new Scenario(def);
s.setMatchExecutable(repository.createMatchExecutable(def));
s.setSchema(repository.createSchema(def));
s.setSchematronValidations(repository.createSchematronTransformations(def));
s.setReportTransformation(repository.createReportTransformation(def));
s.setFactory(repository.getResolvingConfigurationStrategy());
s.setUriResolver(repository.getResolver());
s.setUnparsedTextURIResolver(repository.getUnparsedTextURIResolver());
if (def.getAcceptMatch() != null) {
s.setAcceptExecutable(repository.createAccepptExecutable(def));
}
return s;
}
/**
* Sets actual {@link ResolvingMode}, when the validator needs to resolve stuff on startup.
*

View file

@ -17,6 +17,7 @@
package de.kosit.validationtool.impl;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@ -265,4 +266,18 @@ public class ContentRepository {
public Transformation createSchematronTransformation(final ValidateWithSchematron validateWithSchematron) {
return createTransformation(validateWithSchematron.getResource());
}
public Transformation createIdentityTransformation() {
final URL url = ContentRepository.class.getClassLoader().getResource("transform/identity.xsl");
try ( final InputStream input = url.openStream() ) {
final XsltCompiler xsltCompiler = getProcessor().newXsltCompiler();
final XsltExecutable executable = xsltCompiler.compile(new StreamSource(input));
final ResourceType resource = new ResourceType();
resource.setName("identity");
resource.setLocation(url.toString());
return new Transformation(executable, resource);
} catch (final IOException | SaxonApiException e) {
throw new IllegalStateException("Error creating identity transformation", e);
}
}
}

View file

@ -81,7 +81,7 @@
<xs:element name="match" type="xs:string" />
<xs:element name="validateWithXmlSchema" type="s:ValidateWithXmlSchema" />
<xs:element name="validateWithSchematron" maxOccurs="unbounded" minOccurs="0" type="s:ValidateWithSchematron" />
<xs:element name="createReport" type="s:CreateReportType" />
<xs:element name="createReport" type="s:CreateReportType" minOccurs="0"/>
<xs:element name="acceptMatch" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation>

View file

@ -0,0 +1,23 @@
<!--
~ Copyright 2017-2022 Koordinierungsstelle für IT-Standards (KoSIT)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>