mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
https://github.com/itplr-kosit/validator/issues/100 Make createReport optional
This commit is contained in:
parent
02a2b526fc
commit
874a01fa22
5 changed files with 79 additions and 31 deletions
|
|
@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- (API) Possibility to use preconfigured Saxon `Processor` instance for validation
|
||||
|
||||
### Changed
|
||||
|
||||
- (CORE) [#100](https://github.com/itplr-kosit/validator/issues/100) Make createReport optional
|
||||
- (DAEMON) UI rewrite based on [Docusaurs](https://docusaurus.io)
|
||||
- (
|
||||
API) [ResolvingConfigurationStrategy.java#getProcessor()](de/kosit/validationtool/api/ResolvingConfigurationStrategy)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
28
src/main/resources/transform/identity.xsl
Normal file
28
src/main/resources/transform/identity.xsl
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<!--
|
||||
~ 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="2.0">
|
||||
<xsl:template match="element()">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="@*,node()"/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="attribute()|text()|comment()|processing-instruction()">
|
||||
<xsl:copy/>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
Loading…
Add table
Add a link
Reference in a new issue