mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-26 01:05:38 +00:00
Resolve "Validator new feature: Pruefbericht Gesamtuebersicht bei Batch Verarbeitung"
This commit is contained in:
parent
c781316509
commit
e265667f25
31 changed files with 791 additions and 110 deletions
|
|
@ -114,8 +114,9 @@ class ClassPathResourceResolver implements LSResourceResolver {
|
|||
try {
|
||||
final URL resource = resolved.isAbsolute() ? resolved.toURL()
|
||||
: ClassPathResourceResolver.class.getResource(resolved.toASCIIString());
|
||||
final InputStream in = resource.openStream();
|
||||
final LSInputImpl input = new LSInputImpl(publicId, systemId, resolved.toASCIIString());
|
||||
// intentionally not closed, since xml stack wants it open upon return
|
||||
final InputStream in = resource.openStream();
|
||||
input.setByteStream(in);
|
||||
return input;
|
||||
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ public class CollectingErrorEventHandler implements ValidationEventHandler, Erro
|
|||
|
||||
private static final int DEFAULT_ABORT_COUNT = 50;
|
||||
|
||||
private final Collection<XMLSyntaxError> errors = new ArrayList<>();
|
||||
private static final int stopProcessCount = DEFAULT_ABORT_COUNT;
|
||||
|
||||
private final int stopProcessCount = DEFAULT_ABORT_COUNT;
|
||||
private final Collection<XMLSyntaxError> errors = new ArrayList<>();
|
||||
|
||||
private static XMLSyntaxError createError(final XMLSyntaxErrorSeverity severity, final String message) {
|
||||
final XMLSyntaxError e = new XMLSyntaxError();
|
||||
|
|
@ -97,7 +97,7 @@ public class CollectingErrorEventHandler implements ValidationEventHandler, Erro
|
|||
e.setColumnNumber(event.getLocator().getColumnNumber());
|
||||
e.setRowNumber(event.getLocator().getLineNumber());
|
||||
this.errors.add(e);
|
||||
return this.stopProcessCount != this.errors.size();
|
||||
return stopProcessCount != this.errors.size();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,9 +161,8 @@ public class CollectingErrorEventHandler implements ValidationEventHandler, Erro
|
|||
|
||||
public String getErrorDescription() {
|
||||
final StringJoiner joiner = new StringJoiner("\n");
|
||||
this.errors.forEach(e -> joiner
|
||||
.add(e.getSeverityCode().value() + " " + e.getMessage() + " At row " + e.getRowNumber() + " at pos "
|
||||
+ e.getColumnNumber()));
|
||||
this.errors.forEach(e -> joiner.add(
|
||||
e.getSeverityCode().value() + " " + e.getMessage() + " At row " + e.getRowNumber() + " at pos " + e.getColumnNumber()));
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ public class ContentRepository {
|
|||
this.schemaFactory = this.resolvingConfigurationStrategy.createSchemaFactory();
|
||||
}
|
||||
|
||||
@SuppressWarnings("java:S2095")
|
||||
@SuppressWarnings("squid:S2095")
|
||||
private static Source resolve(final URL resource) {
|
||||
try {
|
||||
return new StreamSource(resource.openStream(), resource.toURI().getRawPath());
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public class ConversionService {
|
|||
public void initialize(final Collection<Package> context) {
|
||||
final String[] packages = context != null ? context.stream().map(Package::getName).toArray(String[]::new) : new String[0];
|
||||
final StringJoiner joiner = new StringJoiner(":");
|
||||
Arrays.stream(packages).forEach(p -> joiner.add(p));
|
||||
Arrays.stream(packages).forEach(joiner::add);
|
||||
initialize(joiner.toString());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class SourceInput extends AbstractInput {
|
|||
}
|
||||
|
||||
private void validate() {
|
||||
if (!isHashcodeComputed() && !isSupported()) {
|
||||
if (!isHashcodeComputed() && isNotSupported()) {
|
||||
throw new IllegalStateException("Unsupported source. Only StreamSource supported yet");
|
||||
}
|
||||
if (!isHashcodeComputed() && ((StreamSource) this.source).getInputStream() == null) {
|
||||
|
|
@ -62,7 +62,7 @@ public class SourceInput extends AbstractInput {
|
|||
|
||||
@Override
|
||||
public Source getSource() throws IOException {
|
||||
if (!isHashcodeComputed() && !isSupported()) {
|
||||
if (!isHashcodeComputed() && isNotSupported()) {
|
||||
throw new IllegalStateException("Unsupported source. Only InputStream-based StreamSource supported yet");
|
||||
}
|
||||
if (isConsumed()) {
|
||||
|
|
@ -71,8 +71,8 @@ public class SourceInput extends AbstractInput {
|
|||
return isHashcodeComputed() ? this.source : wrappedSource();
|
||||
}
|
||||
|
||||
private boolean isSupported() {
|
||||
return isStreamSource();
|
||||
private boolean isNotSupported() {
|
||||
return !isStreamSource();
|
||||
}
|
||||
|
||||
private boolean isConsumed() throws IOException {
|
||||
|
|
@ -107,9 +107,7 @@ public class SourceInput extends AbstractInput {
|
|||
return result;
|
||||
}
|
||||
|
||||
private boolean isWrappingRequired() {
|
||||
return !isHashcodeComputed();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsMultipleReads() {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public class StreamHelper {
|
|||
* 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.
|
||||
*/
|
||||
@SuppressWarnings("squid:S4929") // efficient read is done by internally used stream
|
||||
private static class DigestingInputStream extends FilterInputStream {
|
||||
|
||||
private final MessageDigest digest;
|
||||
|
|
@ -44,6 +45,7 @@ public class StreamHelper {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings("squid:S4929") // efficient read is done by internally used stream
|
||||
private static class CountInputStream extends FilterInputStream {
|
||||
|
||||
private final LazyReadInput reference;
|
||||
|
|
@ -123,10 +125,12 @@ public class StreamHelper {
|
|||
* @param input the input
|
||||
* @throws IOException on I/O errors
|
||||
*/
|
||||
@SuppressWarnings("squid:S1854")
|
||||
public static void drain(final InputStream input) throws IOException {
|
||||
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
|
||||
|
||||
int n;
|
||||
|
||||
while (EOF != (n = input.read(buffer))) {
|
||||
// nothing
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public abstract class BaseOutput {
|
|||
* @return true wenn mindestens ein {@link FailedAssert} vorhanden ist
|
||||
*/
|
||||
public boolean hasFailedAsserts() {
|
||||
return getFailedAsserts().size() > 0;
|
||||
return !getFailedAsserts().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,4 +69,8 @@ public abstract class BaseOutput {
|
|||
return getFailedAsserts().stream().filter(e -> e.getId().equals(name)).findAny();
|
||||
}
|
||||
|
||||
public List<String> getMessages() {
|
||||
return getFailedAsserts().stream().map(FailedAssert::getText).flatMap(e -> e.getContent().stream()).map(Object::toString)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,30 +53,6 @@ public abstract class BaseXMLSyntaxError implements XmlError {
|
|||
return String.format("%s At row %s at pos %s", getMessage(), getRowNumber(), getColumnNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter aus dem schema
|
||||
*
|
||||
* @return Spalte des Fehlers
|
||||
*/
|
||||
@Override
|
||||
public abstract Integer getColumnNumber();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema
|
||||
*
|
||||
* @return Zeile des Fehlers
|
||||
*/
|
||||
@Override
|
||||
public abstract Integer getRowNumber();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema
|
||||
*
|
||||
* @return Fehlermeldung
|
||||
*/
|
||||
@Override
|
||||
public abstract String getMessage();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema
|
||||
*
|
||||
|
|
|
|||
|
|
@ -191,9 +191,11 @@ public class SchemaValidationAction implements CheckAction {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings("squid:S2095") // intentionally return open stream/autoclosable here
|
||||
private SerializedDocument serialize(final Input input, final XdmNode object) throws IOException, SaxonApiException {
|
||||
final SerializedDocument doc;
|
||||
if (input instanceof AbstractInput && ((AbstractInput) input).getLength() < getInMemoryLimit()) {
|
||||
|
||||
doc = new ByteArraySerializedDocument(this.processor);
|
||||
} else {
|
||||
doc = new FileSerializedDocument(this.processor);
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ public class StrictRelativeResolvingStrategy extends BaseResolvingStrategy {
|
|||
|
||||
@Override
|
||||
public SchemaFactory createSchemaFactory() {
|
||||
forceOpenJdkXmlImplementation();
|
||||
final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
disableExternalEntities(sf);
|
||||
allowExternalSchema(sf, "file");
|
||||
|
|
@ -82,7 +83,7 @@ public class StrictRelativeResolvingStrategy extends BaseResolvingStrategy {
|
|||
// verhindere global im Prinzip alle resolving strategien
|
||||
final SecureUriResolver resolver = new SecureUriResolver();
|
||||
processor.getUnderlyingConfiguration().setCollectionFinder(resolver);
|
||||
processor.getUnderlyingConfiguration().setOutputURIResolver(resolver);
|
||||
processor.getUnderlyingConfiguration().setOutputURIResolver(resolver);// NOSONAR
|
||||
processor.getUnderlyingConfiguration().setUnparsedTextURIResolver(resolver);
|
||||
|
||||
// grundsätzlich Feature-konfiguration:
|
||||
|
|
@ -92,10 +93,10 @@ public class StrictRelativeResolvingStrategy extends BaseResolvingStrategy {
|
|||
processor.setConfigurationProperty(Feature.ALLOW_EXTERNAL_FUNCTIONS, false);
|
||||
|
||||
// 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);
|
||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(DISSALLOW_DOCTYPE_DECL_FEATURE), true);
|
||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(LOAD_EXTERNAL_DTD_FEATURE), false);
|
||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(XMLConstants.ACCESS_EXTERNAL_DTD), false);
|
||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(FEATURE_SECURE_PROCESSING), true); // NOSONAR
|
||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(DISSALLOW_DOCTYPE_DECL_FEATURE), true);// NOSONAR
|
||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(LOAD_EXTERNAL_DTD_FEATURE), false);// NOSONAR
|
||||
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(XMLConstants.ACCESS_EXTERNAL_DTD), false);// NOSONAR
|
||||
return processor;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue