mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
Compare commits
10 commits
edde0f5134
...
d4d1aaea51
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4d1aaea51 | ||
|
|
5e57c3e978 | ||
|
|
22910c1ca0 | ||
|
|
911b9a3291 | ||
|
|
7eaf9bcc09 | ||
|
|
122b647853 | ||
|
|
a8a3fd100c | ||
|
|
7a7712188d | ||
|
|
ce65c99f6c | ||
|
|
6698e6b865 |
9 changed files with 229 additions and 54 deletions
102
docs/api.md
102
docs/api.md
|
|
@ -12,8 +12,8 @@ Then you can declare the dependency as follows:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.kosit</groupId>
|
<groupId>org.kosit</groupId>
|
||||||
<artifactId>validationtool</artifactId>
|
<artifactId>validator</artifactId>
|
||||||
<version>${validator.version}</version>
|
<version>${validator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
@ -22,10 +22,12 @@ Then you can declare the dependency as follows:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
dependencies {
|
dependencies {
|
||||||
compile group: 'de.kosit', name: 'validationtool', version: '1.1.0'
|
compile group: 'org.kosit', name: 'validator', version: '1.5.1'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Hint: prior to v1.5.1 the group ID was `de.kosit` and the artifact ID was `validationtool`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Prerequisite for use is a valid [scenario definition](configurations.md) and the a folder with all necessary artifacts for validation (repository) either on the filesystem or on the classpath.
|
Prerequisite for use is a valid [scenario definition](configurations.md) and the a folder with all necessary artifacts for validation (repository) either on the filesystem or on the classpath.
|
||||||
|
|
@ -33,34 +35,39 @@ Prerequisite for use is a valid [scenario definition](configurations.md) and the
|
||||||
The following example demonstrates loading scenario.xml and whole configuration from classpath and validating one XML document:
|
The following example demonstrates loading scenario.xml and whole configuration from classpath and validating one XML document:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
package org.kosit.validator.example;
|
package de.kosit.validationtool.docs;
|
||||||
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import de.kosit.validationtool.api.Check;
|
import de.kosit.validationtool.api.Check;
|
||||||
import de.kosit.validationtool.api.Configuration;
|
import de.kosit.validationtool.api.Configuration;
|
||||||
import de.kosit.validationtool.api.Input;
|
import de.kosit.validationtool.api.Input;
|
||||||
import de.kosit.validationtool.api.InputFactory;
|
import de.kosit.validationtool.api.InputFactory;
|
||||||
import de.kosit.validationtool.api.Result;
|
import de.kosit.validationtool.api.Result;
|
||||||
import de.kosit.validationtool.impl.DefaultCheck;
|
import de.kosit.validationtool.impl.DefaultCheck;
|
||||||
import org.w3c.dom.Document;
|
import de.kosit.validationtool.impl.xml.ProcessorProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example code that is used in the docs/api.md file
|
||||||
|
*/
|
||||||
public class StandardExample {
|
public class StandardExample {
|
||||||
|
|
||||||
public void run(Path testDocument) throws URISyntaxException {
|
public void run(final Path testDocument) throws URISyntaxException {
|
||||||
// Load scenarios.xml from classpath
|
// Load scenarios.xml from classpath
|
||||||
URL scenarios = this.getClass().getClassLoader().getResource("scenarios.xml");
|
final URL scenarios = this.getClass().getClassLoader().getResource("examples/simple/scenarios-with-relative-paths.xml");
|
||||||
// Load the rest of the specific Validator configuration from classpath
|
// Load the rest of the specific Validator configuration from classpath
|
||||||
Configuration config = Configuration.load(scenarios.toURI()).build();
|
final Configuration config = Configuration.load(scenarios.toURI()).build(ProcessorProvider.getProcessor());
|
||||||
// Use the default validation procedure
|
// Use the default validation procedure
|
||||||
Check validator = new DefaultCheck(config);
|
final Check validator = new DefaultCheck(config);
|
||||||
// Validate a single document
|
// Validate a single document
|
||||||
Input document = InputFactory.read(testDocument);
|
final Input document = InputFactory.read(testDocument);
|
||||||
// Get Result including information about the whole validation
|
// Get Result including information about the whole validation
|
||||||
Result report = validator.checkInput(document);
|
final Result report = validator.checkInput(document);
|
||||||
System.out.println("Is processing succesful=" + report.isProcessingSuccessful());
|
System.out.println("Is processing succesful=" + report.isProcessingSuccessful());
|
||||||
// Get report document if processing was successful
|
// Get report document if processing was successful
|
||||||
Document result = null;
|
Document result = null;
|
||||||
|
|
@ -70,13 +77,16 @@ public class StandardExample {
|
||||||
// continue processing results...
|
// continue processing results...
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(final String[] args) throws Exception {
|
||||||
|
// Use e.g. "src/test/resources/examples/simple/input/foo.xml"
|
||||||
|
if (args.length == 0) {
|
||||||
|
throw new IllegalStateException("Provide a test document filename on the commandline");
|
||||||
|
}
|
||||||
// Path of document for validation
|
// Path of document for validation
|
||||||
Path testDoc = Paths.get(args[0]);
|
final Path testDoc = Paths.get(args[0]);
|
||||||
StandardExample example = new StandardExample();
|
final StandardExample example = new StandardExample();
|
||||||
// run example validation
|
// run example validation
|
||||||
example.run(testDoc);
|
example.run(testDoc);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
@ -134,26 +144,36 @@ Instead of pre-configured [scenario files](configurations.md) it is possible to
|
||||||
A simple configuration looks like this:
|
A simple configuration looks like this:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
import static de.kosit.validationtool.config.ConfigurationBuilder.*;
|
package de.kosit.validationtool.docs;
|
||||||
import de.kosit.validationtool.api.Configuration;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.fallback;
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.report;
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.scenario;
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.schema;
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.schematron;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import de.kosit.validationtool.api.Check;
|
||||||
|
import de.kosit.validationtool.api.Configuration;
|
||||||
|
import de.kosit.validationtool.impl.DefaultCheck;
|
||||||
|
import de.kosit.validationtool.impl.xml.ProcessorProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example code that is used in the docs/api.md file
|
||||||
|
*/
|
||||||
public class MyValidator {
|
public class MyValidator {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(final String[] args) {
|
||||||
Configuration config = Configuration.create().name("myconfiguration")
|
final Configuration config = Configuration.create().name("myconfiguration")
|
||||||
.with(scenario("firstScenario")
|
.with(scenario("firstScenario").match("//myNode").validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
|
||||||
.match("//myNode")
|
.validate(schematron("my rules").source("myRules.xsl")).with(report("my report").source("report.xsl")))
|
||||||
.validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
|
.with(fallback().name("default-report").source("fallback.xsl")).useRepository(Paths.get("/opt/myrepository"))
|
||||||
.validate(schematron("my rules").source("myRules.xsl"))
|
.build(ProcessorProvider.getProcessor());
|
||||||
.with(report("my report").source("report.xsl")))
|
final Check validator = new DefaultCheck(config);
|
||||||
.with(fallback().name("default-report").source("fallback.xsl"))
|
// .. run your checks
|
||||||
.useRepository(Paths.get("/opt/myrepository"))
|
}
|
||||||
.build();
|
|
||||||
Check validator = new DefaultCheck(config);
|
|
||||||
// .. run your checks
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -188,19 +208,17 @@ which further opens the second to load resources also from remote locations via
|
||||||
|
|
||||||
You can configure usage of one of these implementations using the `ResolvingMode` via
|
You can configure usage of one of these implementations using the `ResolvingMode` via
|
||||||
|
|
||||||
````java
|
```java
|
||||||
Conifuguration config = Configuration.load(URI.create("myscenarios.xml"))
|
final Configuration config = Configuration.load(URI.create("myscenarios.xml")).setResolvingMode(ResolvingMode.STRICT_LOCAL)
|
||||||
.resolvingMode(ResolvingMode.STRICT_LOCAL)
|
.build(ProcessorProvider.getProcessor());
|
||||||
.build();
|
```
|
||||||
````
|
|
||||||
|
|
||||||
If you decide to implement your own strategy, you can configure this via:
|
If you decide to implement your own strategy, you can configure this via:
|
||||||
|
|
||||||
````java
|
```java
|
||||||
Conifuguration config = Configuration.load(URI.create("myscenarios.xml"))
|
final Configuration config = Configuration.load(URI.create("myscenarios.xml"))
|
||||||
.resolvingStrategy(new MyCustomResolvingConfigurationStrategy())
|
.setResolvingStrategy(new MyCustomResolvingConfigurationStrategy()).build(ProcessorProvider.getProcessor());
|
||||||
.build();
|
```
|
||||||
````
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
8
pom.xml
8
pom.xml
|
|
@ -22,7 +22,7 @@
|
||||||
<name>KoSIT XML Prüftool Implementierung</name>
|
<name>KoSIT XML Prüftool Implementierung</name>
|
||||||
|
|
||||||
<groupId>org.kosit</groupId>
|
<groupId>org.kosit</groupId>
|
||||||
<artifactId>validationtool</artifactId>
|
<artifactId>validator</artifactId>
|
||||||
<version>1.5.1-SNAPSHOT</version>
|
<version>1.5.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<description>KoSIT XML Validator against XSD and Schematron based on defined scenarios.</description>
|
<description>KoSIT XML Validator against XSD and Schematron based on defined scenarios.</description>
|
||||||
|
|
@ -464,6 +464,12 @@
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.5.3</version>
|
<version>3.5.3</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<systemProperties>
|
||||||
|
<property>
|
||||||
|
<name>java.net.useSystemProxies</name>
|
||||||
|
<value>true</value>
|
||||||
|
</property>
|
||||||
|
</systemProperties>
|
||||||
<!--suppress MavenModelInspection -->
|
<!--suppress MavenModelInspection -->
|
||||||
<argLine>-Dfile.encoding=UTF-8 ${jacocoSurefire}</argLine>
|
<argLine>-Dfile.encoding=UTF-8 ${jacocoSurefire}</argLine>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import org.fusesource.jansi.AnsiRenderer.Code;
|
||||||
|
|
||||||
import de.kosit.validationtool.cmd.report.Line;
|
import de.kosit.validationtool.cmd.report.Line;
|
||||||
import de.kosit.validationtool.impl.Printer;
|
import de.kosit.validationtool.impl.Printer;
|
||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
import picocli.CommandLine.ParseResult;
|
import picocli.CommandLine.ParseResult;
|
||||||
|
|
||||||
|
|
@ -79,11 +78,11 @@ public class CommandLineApplication {
|
||||||
final CommandLine commandLine = new CommandLine(new CommandLineOptions());
|
final CommandLine commandLine = new CommandLine(new CommandLineOptions());
|
||||||
try {
|
try {
|
||||||
commandLine.setExecutionExceptionHandler(CommandLineApplication::logExecutionException);
|
commandLine.setExecutionExceptionHandler(CommandLineApplication::logExecutionException);
|
||||||
commandLine.execute(args);
|
final int cmdlineRetVal = commandLine.execute(args);
|
||||||
if (commandLine.isUsageHelpRequested()) {
|
if (commandLine.isUsageHelpRequested() || cmdlineRetVal == CommandLine.ExitCode.USAGE) {
|
||||||
resultStatus = ReturnValue.HELP_REQUEST;
|
resultStatus = ReturnValue.HELP_REQUEST;
|
||||||
} else {
|
} else {
|
||||||
resultStatus = ObjectUtils.defaultIfNull(commandLine.getExecutionResult(), ReturnValue.PARSING_ERROR);
|
resultStatus = ObjectUtils.getIfNull(commandLine.getExecutionResult(), ReturnValue.PARSING_ERROR);
|
||||||
if (resultStatus.isError()) {
|
if (resultStatus.isError()) {
|
||||||
commandLine.usage(System.out);
|
commandLine.usage(System.out);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,10 @@ import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import de.kosit.validationtool.cmd.CommandLineApplication.Level;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import de.kosit.validationtool.cmd.CommandLineApplication.Level;
|
|
||||||
|
|
||||||
import picocli.CommandLine.ArgGroup;
|
import picocli.CommandLine.ArgGroup;
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
import picocli.CommandLine.Help.Visibility;
|
import picocli.CommandLine.Help.Visibility;
|
||||||
|
|
@ -38,10 +36,12 @@ import picocli.CommandLine.Parameters;
|
||||||
* @author Andreas Penski
|
* @author Andreas Penski
|
||||||
*/
|
*/
|
||||||
@Command(description = "Structural and semantic validation of xml files", name = "KoSIT Validator", mixinStandardHelpOptions = false,
|
@Command(description = "Structural and semantic validation of xml files", name = "KoSIT Validator", mixinStandardHelpOptions = false,
|
||||||
separator = " ")
|
separator = " ", synopsisHeading = CommandLineOptions.SYNOSIS_HEADING)
|
||||||
@Getter
|
@Getter
|
||||||
public class CommandLineOptions implements Callable<ReturnValue> {
|
public class CommandLineOptions implements Callable<ReturnValue> {
|
||||||
|
|
||||||
|
static final String SYNOSIS_HEADING = "Usage: ";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Penski
|
* @author Andreas Penski
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,11 @@ public class Printer {
|
||||||
* @param params the params.
|
* @param params the params.
|
||||||
*/
|
*/
|
||||||
public static void writeOut(final String message, final Object... params) {
|
public static void writeOut(final String message, final Object... params) {
|
||||||
System.out.println(new MessageFormat(message, Locale.ENGLISH).format(params));
|
try {
|
||||||
|
System.out.println(new MessageFormat(message, Locale.ENGLISH).format(params));
|
||||||
|
} catch (final RuntimeException ex) {
|
||||||
|
System.err.println("[Format error!] <" + message + "> with params <" + params + ">");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -48,7 +52,11 @@ public class Printer {
|
||||||
* @param params the params.
|
* @param params the params.
|
||||||
*/
|
*/
|
||||||
public static void writeErr(final String message, final Object... params) {
|
public static void writeErr(final String message, final Object... params) {
|
||||||
System.err.println(new MessageFormat(message, Locale.ENGLISH).format(params));
|
try {
|
||||||
|
System.err.println(new MessageFormat(message, Locale.ENGLISH).format(params));
|
||||||
|
} catch (final RuntimeException ex) {
|
||||||
|
System.err.println("[Format error!] <" + message + "> with params <" + params + ">");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,15 @@ public class CommandlineApplicationTest {
|
||||||
|
|
||||||
private static void checkForHelp(final List<String> outputLines) {
|
private static void checkForHelp(final List<String> outputLines) {
|
||||||
assertThat(outputLines.size()).isPositive();
|
assertThat(outputLines.size()).isPositive();
|
||||||
assertThat(outputLines.stream().filter(l -> l.startsWith("Usage: KoSIT Validator"))).hasSize(1);
|
assertThat(outputLines.stream().filter(l -> l.startsWith(CommandLineOptions.SYNOSIS_HEADING))).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoArguments() {
|
||||||
|
final String[] args = {};
|
||||||
|
CommandLineApplication.mainProgram(args);
|
||||||
|
assertThat(CommandLine.getErrorOutput()).isNotEmpty();
|
||||||
|
checkForHelp(CommandLine.getErrorLines());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package de.kosit.validationtool.docs;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.xml.transform.URIResolver;
|
||||||
|
import javax.xml.validation.Schema;
|
||||||
|
import javax.xml.validation.SchemaFactory;
|
||||||
|
import javax.xml.validation.Validator;
|
||||||
|
|
||||||
|
import de.kosit.validationtool.api.Configuration;
|
||||||
|
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
|
||||||
|
import de.kosit.validationtool.impl.ResolvingMode;
|
||||||
|
import de.kosit.validationtool.impl.xml.ProcessorProvider;
|
||||||
|
import net.sf.saxon.lib.UnparsedTextURIResolver;
|
||||||
|
|
||||||
|
public class MiscDocExampleCodes {
|
||||||
|
|
||||||
|
void m1() {
|
||||||
|
final Configuration config = Configuration.load(URI.create("myscenarios.xml")).setResolvingMode(ResolvingMode.STRICT_LOCAL)
|
||||||
|
.build(ProcessorProvider.getProcessor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class MyCustomResolvingConfigurationStrategy implements ResolvingConfigurationStrategy {
|
||||||
|
|
||||||
|
public SchemaFactory createSchemaFactory() {
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URIResolver createResolver(final URI scenarioRepository) {
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnparsedTextURIResolver createUnparsedTextURIResolver(final URI scenarioRepository) {
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Validator createValidator(final Schema schema) {
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void m2() {
|
||||||
|
final Configuration config = Configuration.load(URI.create("myscenarios.xml"))
|
||||||
|
.setResolvingStrategy(new MyCustomResolvingConfigurationStrategy()).build(ProcessorProvider.getProcessor());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
src/test/java/de/kosit/validationtool/docs/MyValidator.java
Normal file
31
src/test/java/de/kosit/validationtool/docs/MyValidator.java
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
package de.kosit.validationtool.docs;
|
||||||
|
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.fallback;
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.report;
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.scenario;
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.schema;
|
||||||
|
import static de.kosit.validationtool.config.ConfigurationBuilder.schematron;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import de.kosit.validationtool.api.Check;
|
||||||
|
import de.kosit.validationtool.api.Configuration;
|
||||||
|
import de.kosit.validationtool.impl.DefaultCheck;
|
||||||
|
import de.kosit.validationtool.impl.xml.ProcessorProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example code that is used in the docs/api.md file
|
||||||
|
*/
|
||||||
|
public class MyValidator {
|
||||||
|
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
final Configuration config = Configuration.create().name("myconfiguration")
|
||||||
|
.with(scenario("firstScenario").match("//myNode").validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
|
||||||
|
.validate(schematron("my rules").source("myRules.xsl")).with(report("my report").source("report.xsl")))
|
||||||
|
.with(fallback().name("default-report").source("fallback.xsl")).useRepository(Paths.get("/opt/myrepository"))
|
||||||
|
.build(ProcessorProvider.getProcessor());
|
||||||
|
final Check validator = new DefaultCheck(config);
|
||||||
|
// .. run your checks
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
package de.kosit.validationtool.docs;
|
||||||
|
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
|
import de.kosit.validationtool.api.Check;
|
||||||
|
import de.kosit.validationtool.api.Configuration;
|
||||||
|
import de.kosit.validationtool.api.Input;
|
||||||
|
import de.kosit.validationtool.api.InputFactory;
|
||||||
|
import de.kosit.validationtool.api.Result;
|
||||||
|
import de.kosit.validationtool.impl.DefaultCheck;
|
||||||
|
import de.kosit.validationtool.impl.xml.ProcessorProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example code that is used in the docs/api.md file
|
||||||
|
*/
|
||||||
|
public class StandardExample {
|
||||||
|
|
||||||
|
public void run(final Path testDocument) throws URISyntaxException {
|
||||||
|
// Load scenarios.xml from classpath
|
||||||
|
final URL scenarios = this.getClass().getClassLoader().getResource("examples/simple/scenarios-with-relative-paths.xml");
|
||||||
|
// Load the rest of the specific Validator configuration from classpath
|
||||||
|
final Configuration config = Configuration.load(scenarios.toURI()).build(ProcessorProvider.getProcessor());
|
||||||
|
// Use the default validation procedure
|
||||||
|
final Check validator = new DefaultCheck(config);
|
||||||
|
// Validate a single document
|
||||||
|
final Input document = InputFactory.read(testDocument);
|
||||||
|
// Get Result including information about the whole validation
|
||||||
|
final Result report = validator.checkInput(document);
|
||||||
|
System.out.println("Is processing succesful=" + report.isProcessingSuccessful());
|
||||||
|
// Get report document if processing was successful
|
||||||
|
Document result = null;
|
||||||
|
if (report.isProcessingSuccessful()) {
|
||||||
|
result = report.getReportDocument();
|
||||||
|
}
|
||||||
|
// continue processing results...
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(final String[] args) throws Exception {
|
||||||
|
// Use e.g. "src/test/resources/examples/simple/input/foo.xml"
|
||||||
|
if (args.length == 0) {
|
||||||
|
throw new IllegalStateException("Provide a test document filename on the commandline");
|
||||||
|
}
|
||||||
|
// Path of document for validation
|
||||||
|
final Path testDoc = Paths.get(args[0]);
|
||||||
|
final StandardExample example = new StandardExample();
|
||||||
|
// run example validation
|
||||||
|
example.run(testDoc);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue