mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
06-FixCompilationWarningsMain
This commit is contained in:
parent
a1965e7079
commit
adb4effcf9
17 changed files with 76 additions and 50 deletions
|
|
@ -129,7 +129,7 @@ class InternalCheck extends DefaultCheck {
|
||||||
}
|
}
|
||||||
|
|
||||||
void printResults(final Map<String, Result> results) {
|
void printResults(final Map<String, Result> results) {
|
||||||
final PrintWriter writer = new PrintWriter(System.out);// NOSONAR
|
final PrintWriter writer = new PrintWriter(System.out); // NOSONAR
|
||||||
writer.write("Results:\n");
|
writer.write("Results:\n");
|
||||||
writer.write(createResultGrid(results).render());
|
writer.write(createResultGrid(results).render());
|
||||||
writer.write(createStatusLine(results));
|
writer.write(createStatusLine(results));
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,7 @@ public class Grid {
|
||||||
* @param def {@link ColumnDefinition}s
|
* @param def {@link ColumnDefinition}s
|
||||||
*/
|
*/
|
||||||
public Grid(final ColumnDefinition... def) {
|
public Grid(final ColumnDefinition... def) {
|
||||||
Stream.of(def).forEach(this::addColumn);
|
this.definitions.addAll(Arrays.asList(def));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateGridStart() {
|
private String generateGridStart() {
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ public class ConfigurationLoader {
|
||||||
final XdmNode root = findRoot(doc);
|
final XdmNode root = findRoot(doc);
|
||||||
final String frameworkVersion = root.getAttributeValue(new QName("frameworkVersion"));
|
final String frameworkVersion = root.getAttributeValue(new QName("frameworkVersion"));
|
||||||
return startsWith(frameworkVersion, SUPPORTED_MAJOR_VERSION)
|
return startsWith(frameworkVersion, SUPPORTED_MAJOR_VERSION)
|
||||||
&& root.getNodeName().getNamespaceURI().equals(SUPPORTED_MAJOR_VERSION_SCHEMA);
|
&& root.getNodeName().getNamespace().equals(SUPPORTED_MAJOR_VERSION_SCHEMA);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Scenario createFallback(final Scenarios scenarios, final ContentRepository repository) {
|
private static Scenario createFallback(final Scenarios scenarios, final ContentRepository repository) {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ import lombok.Getter;
|
||||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxErrorSeverity;
|
import de.kosit.validationtool.model.reportInput.XMLSyntaxErrorSeverity;
|
||||||
|
|
||||||
import net.sf.saxon.s9api.MessageListener2;
|
import net.sf.saxon.s9api.MessageListener;
|
||||||
import net.sf.saxon.s9api.QName;
|
import net.sf.saxon.s9api.QName;
|
||||||
import net.sf.saxon.s9api.XdmNode;
|
import net.sf.saxon.s9api.XdmNode;
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ import net.sf.saxon.s9api.XdmNode;
|
||||||
* @author Andreas Penski
|
* @author Andreas Penski
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class CollectingErrorEventHandler implements ValidationEventHandler, ErrorHandler, MessageListener2, ErrorListener {
|
public class CollectingErrorEventHandler implements ValidationEventHandler, ErrorHandler, MessageListener, ErrorListener {
|
||||||
|
|
||||||
private static final int DEFAULT_ABORT_COUNT = 50;
|
private static final int DEFAULT_ABORT_COUNT = 50;
|
||||||
|
|
||||||
|
|
@ -132,14 +132,15 @@ public class CollectingErrorEventHandler implements ValidationEventHandler, Erro
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void message(final XdmNode content, final QName errorCode, final boolean terminate, final SourceLocator locator) {
|
public void message(final XdmNode content, final boolean terminate, final SourceLocator locator) {
|
||||||
final XMLSyntaxError e = new XMLSyntaxError();
|
final XMLSyntaxError e = new XMLSyntaxError();
|
||||||
if (locator != null) {
|
if (locator != null) {
|
||||||
e.setColumnNumber(locator.getColumnNumber());
|
e.setColumnNumber(locator.getColumnNumber());
|
||||||
e.setRowNumber(locator.getLineNumber());
|
e.setRowNumber(locator.getLineNumber());
|
||||||
}
|
}
|
||||||
e.setMessage("Error procesing" + content.getStringValue());
|
e.setMessage("Error processing" + content.getStringValue());
|
||||||
e.setSeverityCode(terminate ? XMLSyntaxErrorSeverity.SEVERITY_FATAL_ERROR : XMLSyntaxErrorSeverity.SEVERITY_WARNING);
|
e.setSeverityCode(terminate ? XMLSyntaxErrorSeverity.SEVERITY_FATAL_ERROR : XMLSyntaxErrorSeverity.SEVERITY_WARNING);
|
||||||
|
this.errors.add(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -121,14 +121,16 @@ public class ContentRepository {
|
||||||
* @param uri die URI der XSL Definition
|
* @param uri die URI der XSL Definition
|
||||||
* @return ein XSLT Executable
|
* @return ein XSLT Executable
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public XsltExecutable loadXsltScript(final URI uri) {
|
public XsltExecutable loadXsltScript(final URI uri) {
|
||||||
log.info("Loading XSLT script from {}", uri);
|
log.info("Loading XSLT script from {}", uri);
|
||||||
final XsltCompiler xsltCompiler = getProcessor().newXsltCompiler();
|
final XsltCompiler xsltCompiler = getProcessor().newXsltCompiler();
|
||||||
final CollectingErrorEventHandler listener = new CollectingErrorEventHandler();
|
final CollectingErrorEventHandler listener = new CollectingErrorEventHandler();
|
||||||
try {
|
try {
|
||||||
xsltCompiler.setErrorListener(listener);
|
xsltCompiler.setErrorReporter(er -> log.error(listener.getErrorDescription()));
|
||||||
if (getResolver() != null) {
|
if (getResolver() != null) {
|
||||||
// otherwise use default resolver
|
// otherwise use default resolver
|
||||||
|
// TODO: Replace call to deprecated method.
|
||||||
xsltCompiler.setURIResolver(getResolver());
|
xsltCompiler.setURIResolver(getResolver());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,9 @@ public class ConversionService {
|
||||||
/**
|
/**
|
||||||
* Exception while serializing/deserializing with jaxb.
|
* Exception while serializing/deserializing with jaxb.
|
||||||
*/
|
*/
|
||||||
public class ConversionExeption extends RuntimeException {
|
public class ConversionException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7950889507519996452L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
@ -63,7 +65,7 @@ public class ConversionService {
|
||||||
* @param message the message.
|
* @param message the message.
|
||||||
* @param cause the cause
|
* @param cause the cause
|
||||||
*/
|
*/
|
||||||
public ConversionExeption(final String message, final Exception cause) {
|
public ConversionException(final String message, final Exception cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +74,7 @@ public class ConversionService {
|
||||||
*
|
*
|
||||||
* @param message the message.
|
* @param message the message.
|
||||||
*/
|
*/
|
||||||
public ConversionExeption(final String message) {
|
public ConversionException(final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -97,13 +99,13 @@ public class ConversionService {
|
||||||
|
|
||||||
private void checkInputEmpty(final URI xml) {
|
private void checkInputEmpty(final URI xml) {
|
||||||
if (xml == null) {
|
if (xml == null) {
|
||||||
throw new ConversionExeption("Can not unmarshal from empty input");
|
throw new ConversionException("Can not unmarshal from empty input");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void checkTypeEmpty(final Class<T> type) {
|
private <T> void checkTypeEmpty(final Class<T> type) {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
throw new ConversionExeption("Can not unmarshal without type information. Need to specify a target type");
|
throw new ConversionException("Can not unmarshal without type information. Need to specify a target type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,13 +185,13 @@ public class ConversionService {
|
||||||
u.setEventHandler(handler2Use);
|
u.setEventHandler(handler2Use);
|
||||||
final T value = u.unmarshal(xsr, type).getValue();
|
final T value = u.unmarshal(xsr, type).getValue();
|
||||||
if (defaultHandler != null && defaultHandler.hasErrors()) {
|
if (defaultHandler != null && defaultHandler.hasErrors()) {
|
||||||
throw new ConversionExeption(
|
throw new ConversionException(
|
||||||
String.format("Schema errors while reading content from %s: %s", xml, defaultHandler.getErrorDescription()));
|
String.format("Schema errors while reading content from %s: %s", xml, defaultHandler.getErrorDescription()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
} catch (final JAXBException | XMLStreamException e) {
|
} catch (final JAXBException | XMLStreamException e) {
|
||||||
throw new ConversionExeption(String.format("Can not unmarshal to type %s from %s", type.getSimpleName(), xml.toString()), e);
|
throw new ConversionException(String.format("Can not unmarshal to type %s from %s", type.getSimpleName(), xml.toString()), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,9 +206,10 @@ public class ConversionService {
|
||||||
return writeXml(model, null, null);
|
return writeXml(model, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> String writeXml(final T model, final Schema schema, final ValidationEventHandler handler) {
|
public <T> String writeXml(final T model, final Schema schema, final ValidationEventHandler handler) {
|
||||||
if (model == null) {
|
if (model == null) {
|
||||||
throw new ConversionExeption("Can not serialize null");
|
throw new ConversionException("Can not serialize null");
|
||||||
}
|
}
|
||||||
try ( final StringWriter w = new StringWriter() ) {
|
try ( final StringWriter w = new StringWriter() ) {
|
||||||
final JAXBIntrospector introspector = getJaxbContext().createJAXBIntrospector();
|
final JAXBIntrospector introspector = getJaxbContext().createJAXBIntrospector();
|
||||||
|
|
@ -219,7 +222,8 @@ public class ConversionService {
|
||||||
final XMLOutputFactory xof = XMLOutputFactory.newFactory();
|
final XMLOutputFactory xof = XMLOutputFactory.newFactory();
|
||||||
final XMLStreamWriter xmlStreamWriter = xof.createXMLStreamWriter(w);
|
final XMLStreamWriter xmlStreamWriter = xof.createXMLStreamWriter(w);
|
||||||
if (null == introspector.getElementName(model)) {
|
if (null == introspector.getElementName(model)) {
|
||||||
final JAXBElement jaxbElement = new JAXBElement(createQName(model), model.getClass(), model);
|
// TODO: Replace unchecked cast.
|
||||||
|
final JAXBElement<T> jaxbElement = new JAXBElement<>(createQName(model), (Class<T>) model.getClass(), model);
|
||||||
marshaller.marshal(jaxbElement, xmlStreamWriter);
|
marshaller.marshal(jaxbElement, xmlStreamWriter);
|
||||||
} else {
|
} else {
|
||||||
marshaller.marshal(model, xmlStreamWriter);
|
marshaller.marshal(model, xmlStreamWriter);
|
||||||
|
|
@ -227,7 +231,7 @@ public class ConversionService {
|
||||||
xmlStreamWriter.flush();
|
xmlStreamWriter.flush();
|
||||||
return w.toString();
|
return w.toString();
|
||||||
} catch (final JAXBException | IOException | XMLStreamException e) {
|
} catch (final JAXBException | IOException | XMLStreamException e) {
|
||||||
throw new ConversionExeption(String.format("Error serializing Object %s", model.getClass().getName()), e);
|
throw new ConversionException(String.format("Error serializing Object %s", model.getClass().getName()), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -238,7 +242,7 @@ public class ConversionService {
|
||||||
return u.unmarshal(source, type).getValue();
|
return u.unmarshal(source, type).getValue();
|
||||||
|
|
||||||
} catch (final JAXBException e) {
|
} catch (final JAXBException e) {
|
||||||
throw new ConversionExeption(String.format("Can not unmarshal to type %s: %s", type.getSimpleName(),
|
throw new ConversionException(String.format("Can not unmarshal to type %s: %s", type.getSimpleName(),
|
||||||
StringUtils.abbreviate(source.getSystemId(), MAX_LOG_CONTENT)), e);
|
StringUtils.abbreviate(source.getSystemId(), MAX_LOG_CONTENT)), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import static de.kosit.validationtool.impl.DateFactory.createTimestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -145,8 +146,13 @@ public class DefaultCheck implements Check {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<XmlError> convertErrors(final Collection<XMLSyntaxError> errors) {
|
private static List<XmlError> convertErrors(final Collection<XMLSyntaxError> errors) {
|
||||||
// noinspection unchecked
|
List<XmlError> rv = new LinkedList<>();
|
||||||
return (List<XmlError>) (List<?>) errors;
|
for (XMLSyntaxError error : errors) {
|
||||||
|
if (error != null) {
|
||||||
|
rv.add(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import net.sf.saxon.s9api.XdmNode;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
||||||
public class ScenarioRepository {
|
public final class ScenarioRepository {
|
||||||
|
|
||||||
public static final String DEFAULT = "default";
|
public static final String DEFAULT = "default";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ public abstract class AbstractInput implements Input, LazyReadInput {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InputStream wrap(final InputStream stream) {
|
protected InputStream wrap(final InputStream stream) throws IOException {
|
||||||
InputStream result = stream;
|
InputStream result = stream;
|
||||||
if (!isHashcodeComputed()) {
|
if (!isHashcodeComputed()) {
|
||||||
result = StreamHelper.wrapDigesting(this, result, getDigestAlgorithm());
|
result = StreamHelper.wrapDigesting(this, result, getDigestAlgorithm());
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package de.kosit.validationtool.impl.input;
|
package de.kosit.validationtool.impl.input;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import javax.xml.transform.Source;
|
import javax.xml.transform.Source;
|
||||||
|
|
@ -47,7 +48,7 @@ public class ByteArrayInput extends AbstractInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Source getSource() {
|
public Source getSource() throws IOException {
|
||||||
final InputStream stream = wrap(new ByteArrayInputStream(this.content));
|
final InputStream stream = wrap(new ByteArrayInputStream(this.content));
|
||||||
return new StreamSource(stream, getName());
|
return new StreamSource(stream, getName());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ import net.sf.saxon.om.TreeInfo;
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SourceInput extends AbstractInput {
|
public final class SourceInput extends AbstractInput {
|
||||||
|
|
||||||
private final Source source;
|
private final Source source;
|
||||||
|
|
||||||
|
|
@ -133,14 +133,16 @@ public class SourceInput extends AbstractInput {
|
||||||
return this.source instanceof JAXBSource;
|
return this.source instanceof JAXBSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Source wrappedSource() {
|
private Source wrappedSource() throws IOException {
|
||||||
Source result = this.source;
|
Source result = this.source;
|
||||||
if (isStreamSource()) {
|
if (isStreamSource()) {
|
||||||
final StreamSource ss = (StreamSource) this.source;
|
final StreamSource ss = (StreamSource) this.source;
|
||||||
if (ss.getInputStream() != null) {
|
if (ss.getInputStream() != null) {
|
||||||
result = new StreamSource(wrap(ss.getInputStream()), this.source.getSystemId());
|
result = new StreamSource(wrap(ss.getInputStream()), this.source.getSystemId());
|
||||||
} else if (ss.getReader() != null) {
|
} else if (ss.getReader() != null) {
|
||||||
result = new StreamSource(wrap(new ReaderInputStream(ss.getReader(), Charset.defaultCharset())), this.source.getSystemId());
|
result = new StreamSource(
|
||||||
|
wrap(ReaderInputStream.builder().setReader(ss.getReader()).setCharset(Charset.defaultCharset()).get()),
|
||||||
|
this.source.getSystemId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import javax.xml.transform.stream.StreamSource;
|
import javax.xml.transform.stream.StreamSource;
|
||||||
|
|
||||||
import org.apache.commons.io.input.CountingInputStream;
|
import org.apache.commons.io.input.BoundedInputStream;
|
||||||
|
|
||||||
import de.kosit.validationtool.api.Input;
|
import de.kosit.validationtool.api.Input;
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class StreamHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class, which generates the hashcode while reading the stream e.g. for parsing the document. This allows
|
* Helper class, which generates the hashcode while reading the stream e.g. for parsing the document. This allows
|
||||||
* generating the hashcode without an aditional reading step.
|
* generating the hashcode without an additional reading step.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("squid:S4929") // efficient read is done by internally used stream
|
@SuppressWarnings("squid:S4929") // efficient read is done by internally used stream
|
||||||
private static class DigestingInputStream extends FilterInputStream {
|
private static class DigestingInputStream extends FilterInputStream {
|
||||||
|
|
@ -96,15 +96,15 @@ public class StreamHelper {
|
||||||
|
|
||||||
private final LazyReadInput reference;
|
private final LazyReadInput reference;
|
||||||
|
|
||||||
public CountInputStream(final LazyReadInput input, final InputStream stream) {
|
public CountInputStream(final LazyReadInput input, final InputStream stream) throws IOException {
|
||||||
super(new org.apache.commons.io.input.CountingInputStream(stream));
|
super(BoundedInputStream.builder().setInputStream(stream).get());
|
||||||
this.reference = input;
|
this.reference = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
super.close();
|
super.close();
|
||||||
this.reference.setLength(((CountingInputStream) this.in).getByteCount());
|
this.reference.setLength(((BoundedInputStream) this.in).getCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,7 +134,7 @@ public class StreamHelper {
|
||||||
* @param stream the stream
|
* @param stream the stream
|
||||||
* @return a wrapped stream
|
* @return a wrapped stream
|
||||||
*/
|
*/
|
||||||
public static InputStream wrapCount(final LazyReadInput input, final InputStream stream) {
|
public static InputStream wrapCount(final LazyReadInput input, final InputStream stream) throws IOException {
|
||||||
return new CountInputStream(input, stream);
|
return new CountInputStream(input, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ public class CreateReportAction implements CheckAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void check(final Bag results) {
|
public void check(final Bag results) {
|
||||||
final DocumentBuilder documentBuilder = this.processor.newDocumentBuilder();
|
final DocumentBuilder documentBuilder = this.processor.newDocumentBuilder();
|
||||||
try {
|
try {
|
||||||
|
|
@ -95,8 +96,9 @@ public class CreateReportAction implements CheckAction {
|
||||||
final XsltTransformer transformer = getTransformation(results).load();
|
final XsltTransformer transformer = getTransformation(results).load();
|
||||||
transformer.setInitialContextNode(root);
|
transformer.setInitialContextNode(root);
|
||||||
final CollectingErrorEventHandler e = new CollectingErrorEventHandler();
|
final CollectingErrorEventHandler e = new CollectingErrorEventHandler();
|
||||||
transformer.setMessageListener(e);
|
transformer.setErrorReporter(er -> log.error(e.getErrorDescription()));
|
||||||
final Scenario scenario = results.getScenarioSelectionResult().getObject();
|
final Scenario scenario = results.getScenarioSelectionResult().getObject();
|
||||||
|
// TODO: Replace call to deprecated method.
|
||||||
transformer.setURIResolver(scenario.getUriResolver());
|
transformer.setURIResolver(scenario.getUriResolver());
|
||||||
|
|
||||||
if (scenario.getUnparsedTextURIResolver() != null) {
|
if (scenario.getUnparsedTextURIResolver() != null) {
|
||||||
|
|
|
||||||
|
|
@ -55,16 +55,18 @@ public class SchematronValidationAction implements CheckAction {
|
||||||
return scenario.getSchematronValidations().stream().map(v -> validate(scenario, results, document, v)).collect(Collectors.toList());
|
return scenario.getSchematronValidations().stream().map(v -> validate(scenario, results, document, v)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private ValidationResultsSchematron validate(final Scenario scenario, final Bag results, final XdmNode document,
|
private ValidationResultsSchematron validate(final Scenario scenario, final Bag results, final XdmNode document,
|
||||||
final Transformation validation) {
|
final Transformation validation) {
|
||||||
final ValidationResultsSchematron s = new ValidationResultsSchematron();
|
final ValidationResultsSchematron s = new ValidationResultsSchematron();
|
||||||
s.setResource(validation.getResourceType());
|
s.setResource(validation.getResourceType());
|
||||||
try {
|
try {
|
||||||
final XsltTransformer transformer = validation.getExecutable().load();
|
final XsltTransformer transformer = validation.getExecutable().load();
|
||||||
// resolving nur relative zum Repository
|
// Resolving nur relativ zum Repository
|
||||||
|
// TODO: Replace call to deprecated method.
|
||||||
transformer.setURIResolver(scenario.getUriResolver());
|
transformer.setURIResolver(scenario.getUriResolver());
|
||||||
final CollectingErrorEventHandler e = new CollectingErrorEventHandler();
|
final CollectingErrorEventHandler e = new CollectingErrorEventHandler();
|
||||||
transformer.setMessageListener(e);
|
transformer.setErrorReporter(er -> log.error(e.getErrorDescription()));
|
||||||
|
|
||||||
final XdmDestination result = new XdmDestination();
|
final XdmDestination result = new XdmDestination();
|
||||||
transformer.setDestination(result);
|
transformer.setDestination(result);
|
||||||
|
|
|
||||||
|
|
@ -93,12 +93,14 @@ public class ProcessorProvider {
|
||||||
return processor;
|
return processor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private static Processor createProcessor() {
|
private static Processor createProcessor() {
|
||||||
final Processor processor = new Processor(false);
|
final Processor processor = new Processor(false);
|
||||||
// verhindere global im Prinzip alle resolving strategien
|
// verhindere global im Prinzip alle resolving strategien
|
||||||
final SecureUriResolver resolver = new SecureUriResolver();
|
final SecureUriResolver resolver = new SecureUriResolver();
|
||||||
processor.getUnderlyingConfiguration().setCollectionFinder(resolver);
|
processor.getUnderlyingConfiguration().setCollectionFinder(resolver);
|
||||||
processor.getUnderlyingConfiguration().setOutputURIResolver(resolver);// NOSONAR
|
// TODO: Replace call to deprecated method.
|
||||||
|
processor.getUnderlyingConfiguration().setOutputURIResolver(resolver); // NOSONAR
|
||||||
processor.getUnderlyingConfiguration().setUnparsedTextURIResolver(resolver);
|
processor.getUnderlyingConfiguration().setUnparsedTextURIResolver(resolver);
|
||||||
|
|
||||||
// grundsätzlich Feature-konfiguration:
|
// grundsätzlich Feature-konfiguration:
|
||||||
|
|
@ -108,10 +110,14 @@ public class ProcessorProvider {
|
||||||
processor.setConfigurationProperty(Feature.ALLOW_EXTERNAL_FUNCTIONS, false);
|
processor.setConfigurationProperty(Feature.ALLOW_EXTERNAL_FUNCTIONS, false);
|
||||||
|
|
||||||
// Konfiguration des zu verwendenden Parsers, wenn Saxon selbst einen erzeugen muss, bspw. beim XSL parsen
|
// Konfiguration des zu verwendenden Parsers, wenn Saxon selbst einen erzeugen muss, bspw. beim XSL parsen
|
||||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(FEATURE_SECURE_PROCESSING), true); // NOSONAR
|
processor.getUnderlyingConfiguration().setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(FEATURE_SECURE_PROCESSING),
|
||||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(DISSALLOW_DOCTYPE_DECL_FEATURE), true);// NOSONAR
|
true); // NOSONAR
|
||||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(LOAD_EXTERNAL_DTD_FEATURE), false);// NOSONAR
|
processor.getUnderlyingConfiguration()
|
||||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(XMLConstants.ACCESS_EXTERNAL_DTD), false);// NOSONAR
|
.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(DISSALLOW_DOCTYPE_DECL_FEATURE), true); // NOSONAR
|
||||||
|
processor.getUnderlyingConfiguration().setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(LOAD_EXTERNAL_DTD_FEATURE),
|
||||||
|
false); // NOSONAR
|
||||||
|
processor.getUnderlyingConfiguration()
|
||||||
|
.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(XMLConstants.ACCESS_EXTERNAL_DTD), false); // NOSONAR
|
||||||
return processor;
|
return processor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,13 +55,13 @@ public class ConversionServiceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarshalNull() {
|
public void testMarshalNull() {
|
||||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
this.exception.expect(ConversionService.ConversionException.class);
|
||||||
this.service.writeXml(null);
|
this.service.writeXml(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarshalUnknown() {
|
public void testMarshalUnknown() {
|
||||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
this.exception.expect(ConversionService.ConversionException.class);
|
||||||
this.service.writeXml(new Serializable() {
|
this.service.writeXml(new Serializable() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -82,31 +82,31 @@ public class ConversionServiceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalInvalidXml() {
|
public void testUnmarshalInvalidXml() {
|
||||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
this.exception.expect(ConversionService.ConversionException.class);
|
||||||
this.service.readXml(Invalid.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA));
|
this.service.readXml(Invalid.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalIllFormed() {
|
public void testUnmarshalIllFormed() {
|
||||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
this.exception.expect(ConversionService.ConversionException.class);
|
||||||
this.service.readXml(Invalid.SCENARIOS_ILLFORMED, Scenarios.class, this.repository.createSchema(SCHEMA));
|
this.service.readXml(Invalid.SCENARIOS_ILLFORMED, Scenarios.class, this.repository.createSchema(SCHEMA));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalEmpty() {
|
public void testUnmarshalEmpty() {
|
||||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
this.exception.expect(ConversionService.ConversionException.class);
|
||||||
this.service.readXml(null, Scenarios.class);
|
this.service.readXml(null, Scenarios.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalUnknownType() throws URISyntaxException {
|
public void testUnmarshalUnknownType() throws URISyntaxException {
|
||||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
this.exception.expect(ConversionService.ConversionException.class);
|
||||||
this.service.readXml(Simple.SCENARIOS, ConversionService.class);
|
this.service.readXml(Simple.SCENARIOS, ConversionService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshalWithoutType() throws URISyntaxException {
|
public void testUnmarshalWithoutType() throws URISyntaxException {
|
||||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
this.exception.expect(ConversionService.ConversionException.class);
|
||||||
this.service.readXml(Simple.SCENARIOS, null);
|
this.service.readXml(Simple.SCENARIOS, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,13 +71,13 @@ public class VersioningTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewFeature() throws URISyntaxException {
|
public void testNewFeature() throws URISyntaxException {
|
||||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
this.exception.expect(ConversionService.ConversionException.class);
|
||||||
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewVersion() throws URISyntaxException {
|
public void testNewVersion() throws URISyntaxException {
|
||||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
this.exception.expect(ConversionService.ConversionException.class);
|
||||||
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue