mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
Compare commits
No commits in common. "d4d1aaea51b3dfa39166354f0568d3db29263b01" and "edde0f5134cba4f00e76c0fc52adab761130b59d" have entirely different histories.
d4d1aaea51
...
edde0f5134
9 changed files with 53 additions and 228 deletions
100
docs/api.md
100
docs/api.md
|
|
@ -12,8 +12,8 @@ Then you can declare the dependency as follows:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.kosit</groupId>
|
<groupId>de.kosit</groupId>
|
||||||
<artifactId>validator</artifactId>
|
<artifactId>validationtool</artifactId>
|
||||||
<version>${validator.version}</version>
|
<version>${validator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
@ -22,12 +22,10 @@ Then you can declare the dependency as follows:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
dependencies {
|
dependencies {
|
||||||
compile group: 'org.kosit', name: 'validator', version: '1.5.1'
|
compile group: 'de.kosit', name: 'validationtool', version: '1.1.0'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
||||||
|
|
@ -35,39 +33,34 @@ 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 de.kosit.validationtool.docs;
|
package org.kosit.validator.example;
|
||||||
|
|
||||||
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 de.kosit.validationtool.impl.xml.ProcessorProvider;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
/**
|
|
||||||
* Example code that is used in the docs/api.md file
|
|
||||||
*/
|
|
||||||
public class StandardExample {
|
public class StandardExample {
|
||||||
|
|
||||||
public void run(final Path testDocument) throws URISyntaxException {
|
public void run(Path testDocument) throws URISyntaxException {
|
||||||
// Load scenarios.xml from classpath
|
// Load scenarios.xml from classpath
|
||||||
final URL scenarios = this.getClass().getClassLoader().getResource("examples/simple/scenarios-with-relative-paths.xml");
|
URL scenarios = this.getClass().getClassLoader().getResource("scenarios.xml");
|
||||||
// Load the rest of the specific Validator configuration from classpath
|
// Load the rest of the specific Validator configuration from classpath
|
||||||
final Configuration config = Configuration.load(scenarios.toURI()).build(ProcessorProvider.getProcessor());
|
Configuration config = Configuration.load(scenarios.toURI()).build();
|
||||||
// Use the default validation procedure
|
// Use the default validation procedure
|
||||||
final Check validator = new DefaultCheck(config);
|
Check validator = new DefaultCheck(config);
|
||||||
// Validate a single document
|
// Validate a single document
|
||||||
final Input document = InputFactory.read(testDocument);
|
Input document = InputFactory.read(testDocument);
|
||||||
// Get Result including information about the whole validation
|
// Get Result including information about the whole validation
|
||||||
final Result report = validator.checkInput(document);
|
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;
|
||||||
|
|
@ -77,16 +70,13 @@ public class StandardExample {
|
||||||
// continue processing results...
|
// continue processing results...
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(final String[] args) throws Exception {
|
public static void main(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
|
||||||
final Path testDoc = Paths.get(args[0]);
|
Path testDoc = Paths.get(args[0]);
|
||||||
final StandardExample example = new StandardExample();
|
StandardExample example = new StandardExample();
|
||||||
// run example validation
|
// run example validation
|
||||||
example.run(testDoc);
|
example.run(testDoc);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
@ -144,36 +134,26 @@ 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
|
||||||
package de.kosit.validationtool.docs;
|
import static de.kosit.validationtool.config.ConfigurationBuilder.*;
|
||||||
|
|
||||||
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.api.Configuration;
|
||||||
import de.kosit.validationtool.impl.DefaultCheck;
|
import java.net.URI;
|
||||||
import de.kosit.validationtool.impl.xml.ProcessorProvider;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
/**
|
|
||||||
* Example code that is used in the docs/api.md file
|
|
||||||
*/
|
|
||||||
public class MyValidator {
|
public class MyValidator {
|
||||||
|
|
||||||
public static void main(final String[] args) {
|
public static void main(String[] args) {
|
||||||
final Configuration config = Configuration.create().name("myconfiguration")
|
Configuration config = Configuration.create().name("myconfiguration")
|
||||||
.with(scenario("firstScenario").match("//myNode").validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
|
.with(scenario("firstScenario")
|
||||||
.validate(schematron("my rules").source("myRules.xsl")).with(report("my report").source("report.xsl")))
|
.match("//myNode")
|
||||||
.with(fallback().name("default-report").source("fallback.xsl")).useRepository(Paths.get("/opt/myrepository"))
|
.validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
|
||||||
.build(ProcessorProvider.getProcessor());
|
.validate(schematron("my rules").source("myRules.xsl"))
|
||||||
final Check validator = new DefaultCheck(config);
|
.with(report("my report").source("report.xsl")))
|
||||||
// .. run your checks
|
.with(fallback().name("default-report").source("fallback.xsl"))
|
||||||
}
|
.useRepository(Paths.get("/opt/myrepository"))
|
||||||
|
.build();
|
||||||
|
Check validator = new DefaultCheck(config);
|
||||||
|
// .. run your checks
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -208,17 +188,19 @@ 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
|
||||||
final Configuration config = Configuration.load(URI.create("myscenarios.xml")).setResolvingMode(ResolvingMode.STRICT_LOCAL)
|
Conifuguration config = Configuration.load(URI.create("myscenarios.xml"))
|
||||||
.build(ProcessorProvider.getProcessor());
|
.resolvingMode(ResolvingMode.STRICT_LOCAL)
|
||||||
```
|
.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
|
||||||
final Configuration config = Configuration.load(URI.create("myscenarios.xml"))
|
Conifuguration config = Configuration.load(URI.create("myscenarios.xml"))
|
||||||
.setResolvingStrategy(new MyCustomResolvingConfigurationStrategy()).build(ProcessorProvider.getProcessor());
|
.resolvingStrategy(new MyCustomResolvingConfigurationStrategy())
|
||||||
```
|
.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>validator</artifactId>
|
<artifactId>validationtool</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,12 +464,6 @@
|
||||||
<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,6 +25,7 @@ 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;
|
||||||
|
|
||||||
|
|
@ -78,11 +79,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);
|
||||||
final int cmdlineRetVal = commandLine.execute(args);
|
commandLine.execute(args);
|
||||||
if (commandLine.isUsageHelpRequested() || cmdlineRetVal == CommandLine.ExitCode.USAGE) {
|
if (commandLine.isUsageHelpRequested()) {
|
||||||
resultStatus = ReturnValue.HELP_REQUEST;
|
resultStatus = ReturnValue.HELP_REQUEST;
|
||||||
} else {
|
} else {
|
||||||
resultStatus = ObjectUtils.getIfNull(commandLine.getExecutionResult(), ReturnValue.PARSING_ERROR);
|
resultStatus = ObjectUtils.defaultIfNull(commandLine.getExecutionResult(), ReturnValue.PARSING_ERROR);
|
||||||
if (resultStatus.isError()) {
|
if (resultStatus.isError()) {
|
||||||
commandLine.usage(System.out);
|
commandLine.usage(System.out);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,12 @@ 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;
|
||||||
|
|
@ -36,12 +38,10 @@ 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 = " ", synopsisHeading = CommandLineOptions.SYNOSIS_HEADING)
|
separator = " ")
|
||||||
@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,11 +38,7 @@ 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) {
|
||||||
try {
|
System.out.println(new MessageFormat(message, Locale.ENGLISH).format(params));
|
||||||
System.out.println(new MessageFormat(message, Locale.ENGLISH).format(params));
|
|
||||||
} catch (final RuntimeException ex) {
|
|
||||||
System.err.println("[Format error!] <" + message + "> with params <" + params + ">");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -52,11 +48,7 @@ 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) {
|
||||||
try {
|
System.err.println(new MessageFormat(message, Locale.ENGLISH).format(params));
|
||||||
System.err.println(new MessageFormat(message, Locale.ENGLISH).format(params));
|
|
||||||
} catch (final RuntimeException ex) {
|
|
||||||
System.err.println("[Format error!] <" + message + "> with params <" + params + ">");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -81,15 +81,7 @@ 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(CommandLineOptions.SYNOSIS_HEADING))).hasSize(1);
|
assertThat(outputLines.stream().filter(l -> l.startsWith("Usage: KoSIT Validator"))).hasSize(1);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNoArguments() {
|
|
||||||
final String[] args = {};
|
|
||||||
CommandLineApplication.mainProgram(args);
|
|
||||||
assertThat(CommandLine.getErrorOutput()).isNotEmpty();
|
|
||||||
checkForHelp(CommandLine.getErrorLines());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
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