mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-26 01:05:38 +00:00
#21 Umsetzung der API Rückgabe, erste version
This commit is contained in:
parent
a424fbbcfe
commit
ab31ed71b1
21 changed files with 532 additions and 147 deletions
|
|
@ -0,0 +1,21 @@
|
|||
package de.kosit.validationtool.api;
|
||||
|
||||
/**
|
||||
* Status der Empfehlung.
|
||||
*/
|
||||
public enum AcceptRecommendation {
|
||||
/**
|
||||
* Nicht definiert, weil eine Evaluierung nicht durchgeführt wurde, oder nicht durchgeführt werden konnte.
|
||||
*/
|
||||
UNDEFINED,
|
||||
|
||||
/**
|
||||
* Das Dokument ist gemäß Konfiguration valide und kann akzeptiert werden.
|
||||
*/
|
||||
ACCEPTABLE,
|
||||
|
||||
/**
|
||||
* Das Dokuemnt ist gemäß Konfiguration invalide und sollte NICHT akzeptiert werden.
|
||||
*/
|
||||
REJECT
|
||||
}
|
||||
|
|
@ -24,9 +24,6 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import net.sf.saxon.dom.NodeOverNodeInfo;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
|
||||
/**
|
||||
* Zentrale Schnittstellendefinition für das Prüf-Tool.
|
||||
|
|
@ -42,10 +39,10 @@ public interface Check {
|
|||
* @param input die Resource / XML-Datei, die geprüft werden soll.
|
||||
* @return ein Ergebnis-{@link Document} (readonly)
|
||||
*/
|
||||
default Document check(Input input) {
|
||||
final XdmNode node = checkInput(input);
|
||||
default Document check(final Input input) {
|
||||
final Result result = checkInput(input);
|
||||
// readonly view of the document!!!
|
||||
return (Document) NodeOverNodeInfo.wrap(node.getUnderlyingNode());
|
||||
return result.getReportDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,7 +51,7 @@ public interface Check {
|
|||
* @param input die Resource / XML-Datei, die geprüft werden soll.
|
||||
* @return ein Ergebnis-{@link Document}
|
||||
*/
|
||||
XdmNode checkInput(Input input);
|
||||
Result checkInput(Input input);
|
||||
|
||||
/**
|
||||
* Führt eine Prüfung im Batch-Mode durch. Die Default-Implementierung führt die Prüfung sequentiell aus. Die Ergebnis
|
||||
|
|
@ -63,7 +60,7 @@ public interface Check {
|
|||
* @param input die Eingabe
|
||||
* @return Liste mit Ergebnis-Dokumenten (readonly)
|
||||
*/
|
||||
default List<Document> check(List<Input> input) {
|
||||
default List<Document> check(final List<Input> input) {
|
||||
return input.stream().map(this::check).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
|
@ -73,8 +70,9 @@ public interface Check {
|
|||
* @param input die Eingabe
|
||||
* @return Liste mit Ergebnis-Dokumenten
|
||||
*/
|
||||
default List<XdmNode> checkInput(List<Input> input) {
|
||||
default List<Result> checkInput(final List<Input> input) {
|
||||
return input.stream().map(this::checkInput).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
44
src/main/java/de/kosit/validationtool/api/Result.java
Normal file
44
src/main/java/de/kosit/validationtool/api/Result.java
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package de.kosit.validationtool.api;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import net.sf.saxon.dom.NodeOverNodeInfo;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
/**
|
||||
* API Rückgabe Objekt des Ergebnisses des Validierungsprozesses.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class Result {
|
||||
|
||||
/** Der generierte Report. */
|
||||
private final XdmNode report;
|
||||
|
||||
/** Das evaluierte Ergebnis. */
|
||||
private final AcceptRecommendation acceptRecommendation;
|
||||
|
||||
/**
|
||||
* Gibt den Report als W3C-{@link Document} zurück.
|
||||
*
|
||||
* @return der Report
|
||||
*/
|
||||
public Document getReportDocument() {
|
||||
return (Document) NodeOverNodeInfo.wrap(getReport().getUnderlyingNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Schnellzugriff auf die Empfehlung zur Weiterverarbeitung des Dokuments.
|
||||
*
|
||||
* @return true wenn {@link AcceptRecommendation#ACCEPTABLE}
|
||||
*/
|
||||
public boolean isAcceptable() {
|
||||
return AcceptRecommendation.ACCEPTABLE.equals(acceptRecommendation);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue