Skip to content

Commit 49aeac1

Browse files
committed
Support for XML Schema 1.1 validation
1 parent af9c9b5 commit 49aeac1

38 files changed

Lines changed: 2692 additions & 1203 deletions

etc/build.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<project name="xml-validator">
2+
<description>
3+
Ant build file with extensions used in the maven build (via the antrun plugin).
4+
</description>
5+
<target name="check-and-install-xerces-jars" depends="xerces-install-xercesImpl,xerces-install-xpath2,xerces-install-cupv10k,xerces-install-icu4j">
6+
<echo level="info" message="Finished setup of xerces JARs."/>
7+
</target>
8+
<target name="xerces-check-xercesImpl">
9+
<available file="${settings.localRepository}/eu/europa/ec/itb/xerces/xercesImpl/${version.xercesBuild}/xercesImpl-${version.xercesBuild}.jar" property="xercesImpl.exists"/>
10+
</target>
11+
<target name="xerces-check-xpath2">
12+
<available file="${settings.localRepository}/eu/europa/ec/itb/xerces/org.eclipse.wst.xml.xpath2.processor_1.2.1/${version.xercesBuild}/org.eclipse.wst.xml.xpath2.processor_1.2.1-${version.xercesBuild}.jar" property="xpath2.exists"/>
13+
</target>
14+
<target name="xerces-check-cupv10k">
15+
<available file="${settings.localRepository}/eu/europa/ec/itb/xerces/cupv10k-runtime/${version.xercesBuild}/cupv10k-runtime-${version.xercesBuild}.jar" property="cupv10k.exists"/>
16+
</target>
17+
<target name="xerces-check-icu4j">
18+
<available file="${settings.localRepository}/eu/europa/ec/itb/xerces/icu4j/${version.xercesBuild}/icu4j-${version.xercesBuild}.jar" property="icu4j.exists"/>
19+
</target>
20+
<target name="xerces-install-xercesImpl" depends="xerces-check-xercesImpl" unless="xercesImpl.exists">
21+
<echo level="info" message="xercesImpl not found - installing..."/>
22+
<exec executable="cmd" failonerror="true" failifexecutionfails="true" osfamily="windows">
23+
<arg line="/c mvn install:install-file -Dfile=${project.basedir}/etc/xerces/xercesImpl.jar -DgroupId=eu.europa.ec.itb.xerces -DartifactId=xercesImpl -Dversion=${version.xercesBuild} -Dpackaging=jar"/>
24+
</exec>
25+
<exec executable="sh" failonerror="true" failifexecutionfails="true" osfamily="unix">
26+
<arg line="-c 'mvn install:install-file -Dfile=${project.basedir}/etc/xerces/xercesImpl.jar -DgroupId=eu.europa.ec.itb.xerces -DartifactId=xercesImpl -Dversion=${version.xercesBuild} -Dpackaging=jar'"/>
27+
</exec>
28+
</target>
29+
<target name="xerces-install-xpath2" depends="xerces-check-xpath2" unless="xpath2.exists">
30+
<echo level="info" message="xpath2 not found - installing..."/>
31+
<exec executable="cmd" failonerror="true" failifexecutionfails="true" osfamily="windows">
32+
<arg line="/c mvn install:install-file -Dfile=${project.basedir}/etc/xerces/org.eclipse.wst.xml.xpath2.processor_1.2.1.jar -DgroupId=eu.europa.ec.itb.xerces -DartifactId=org.eclipse.wst.xml.xpath2.processor_1.2.1 -Dversion=${version.xercesBuild} -Dpackaging=jar"/>
33+
</exec>
34+
<exec executable="sh" failonerror="true" failifexecutionfails="true" osfamily="unix">
35+
<arg line="-c 'mvn install:install-file -Dfile=${project.basedir}/etc/xerces/org.eclipse.wst.xml.xpath2.processor_1.2.1.jar -DgroupId=eu.europa.ec.itb.xerces -DartifactId=org.eclipse.wst.xml.xpath2.processor_1.2.1 -Dversion=${version.xercesBuild} -Dpackaging=jar'"/>
36+
</exec>
37+
</target>
38+
<target name="xerces-install-cupv10k" depends="xerces-check-cupv10k" unless="cupv10k.exists">
39+
<echo level="info" message="cupv10k not found - installing..."/>
40+
<exec executable="cmd" failonerror="true" failifexecutionfails="true" osfamily="windows">
41+
<arg line="/c mvn install:install-file -Dfile=${project.basedir}/etc/xerces/cupv10k-runtime.jar -DgroupId=eu.europa.ec.itb.xerces -DartifactId=cupv10k-runtime -Dversion=${version.xercesBuild} -Dpackaging=jar"/>
42+
</exec>
43+
<exec executable="sh" failonerror="true" failifexecutionfails="true" osfamily="unix">
44+
<arg line="-c 'mvn install:install-file -Dfile=${project.basedir}/etc/xerces/cupv10k-runtime.jar -DgroupId=eu.europa.ec.itb.xerces -DartifactId=cupv10k-runtime -Dversion=${version.xercesBuild} -Dpackaging=jar'"/>
45+
</exec>
46+
</target>
47+
<target name="xerces-install-icu4j" depends="xerces-check-icu4j" unless="icu4j.exists">
48+
<echo level="info" message="icu4j not found - installing..."/>
49+
<exec executable="cmd" failonerror="true" failifexecutionfails="true" osfamily="windows">
50+
<arg line="/c mvn install:install-file -Dfile=${project.basedir}/etc/xerces/icu4j.jar -DgroupId=eu.europa.ec.itb.xerces -DartifactId=icu4j -Dversion=${version.xercesBuild} -Dpackaging=jar"/>
51+
</exec>
52+
<exec executable="sh" failonerror="true" failifexecutionfails="true" osfamily="unix">
53+
<arg line="-c 'mvn install:install-file -Dfile=${project.basedir}/etc/xerces/icu4j.jar -DgroupId=eu.europa.ec.itb.xerces -DartifactId=icu4j -Dversion=${version.xercesBuild} -Dpackaging=jar'"/>
54+
</exec>
55+
</target>
56+
</project>

etc/xerces/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This directory contains JAR files obtained as part of the [Xerces binary distribution](https://xerces.apache.org/mirrors.cgi#binary)
2+
that supports XML Schema 1.1 validation. The Xerces distribution is not published on Maven Central (or another repository)
3+
whereas the other JARs included in this folder are either not available, or not available at the specifically required
4+
versions.
5+
6+
To avoid incompatibilities for Xerces these libraries are installed manually in the local Maven repository as part of the
7+
current project's `validate` phase.

etc/xerces/cupv10k-runtime.jar

8.77 KB
Binary file not shown.

etc/xerces/icu4j.jar

507 KB
Binary file not shown.
674 KB
Binary file not shown.

etc/xerces/xercesImpl.jar

1.54 MB
Binary file not shown.

pom.xml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<parent>
2727
<groupId>eu.europa.ec.itb.commons</groupId>
2828
<artifactId>validator-parent</artifactId>
29-
<version>1.10.0</version>
29+
<version>1.11.0-SNAPSHOT</version>
3030
<relativePath/>
3131
</parent>
3232
<modules>
@@ -40,7 +40,7 @@
4040
</modules>
4141
<properties>
4242
<validatorBuild.resourceJar>validator-resources</validatorBuild.resourceJar>
43-
<version.itbCommons>1.10.0</version.itbCommons>
43+
<version.itbCommons>1.11.0-SNAPSHOT</version.itbCommons>
4444
</properties>
4545
<dependencyManagement>
4646
<dependencies>
@@ -113,6 +113,28 @@
113113
</dependencyManagement>
114114
<build>
115115
<plugins>
116+
<!-- Check and conditionally install Xerces JARs -->
117+
<plugin>
118+
<groupId>org.apache.maven.plugins</groupId>
119+
<artifactId>maven-antrun-plugin</artifactId>
120+
<executions>
121+
<execution>
122+
<id>check-and-install-xerces-jars</id>
123+
<phase>validate</phase>
124+
<goals>
125+
<goal>run</goal>
126+
</goals>
127+
<configuration>
128+
<target>
129+
<ant antfile="etc/build.xml" dir=".">
130+
<target name="check-and-install-xerces-jars"/>
131+
</ant>
132+
</target>
133+
</configuration>
134+
<inherited>false</inherited>
135+
</execution>
136+
</executions>
137+
</plugin>
116138
<plugin>
117139
<groupId>org.apache.maven.plugins</groupId>
118140
<artifactId>maven-enforcer-plugin</artifactId>

xmlvalidator-common/pom.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,33 @@
2929
<artifactId>tika-core</artifactId>
3030
</dependency>
3131
<dependency>
32-
<groupId>xerces</groupId>
32+
<groupId>eu.europa.ec.itb.xerces</groupId>
3333
<artifactId>xercesImpl</artifactId>
3434
</dependency>
35+
<dependency>
36+
<groupId>eu.europa.ec.itb.xerces</groupId>
37+
<artifactId>org.eclipse.wst.xml.xpath2.processor_1.2.1</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>eu.europa.ec.itb.xerces</groupId>
41+
<artifactId>cupv10k-runtime</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>eu.europa.ec.itb.xerces</groupId>
45+
<artifactId>icu4j</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>xml-resolver</groupId>
49+
<artifactId>xml-resolver</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>xalan</groupId>
53+
<artifactId>serializer</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>xml-apis</groupId>
57+
<artifactId>xml-apis</artifactId>
58+
</dependency>
3559
<dependency>
3660
<groupId>org.springframework.boot</groupId>
3761
<artifactId>spring-boot-starter</artifactId>

xmlvalidator-common/src/main/java/eu/europa/ec/itb/xml/DomainConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class DomainConfig extends WebDomainConfig {
5656
private Map<String, Boolean> stopOnXsdErrors;
5757
private Map<String, Path> remoteSchemaImportMappings;
5858
private Map<String, Boolean> preloadRemoteSchemaImports;
59+
private Map<String, XmlSchemaVersion> schemaVersion;
5960
private boolean skipRemoteSchemaImportCaching = false;
6061

6162
/**
@@ -468,4 +469,21 @@ public void setMailInboundFolder(String mailInboundFolder) {
468469
this.mailInboundFolder = mailInboundFolder;
469470
}
470471

472+
/**
473+
* @param validationType The validation type.
474+
* @return The XML Schema version to use for the provided validation type (default being v1.0).
475+
*/
476+
public XmlSchemaVersion getSchemaVersionForValidationType(String validationType) {
477+
if (validationType != null) {
478+
return schemaVersion.getOrDefault(validationType, XmlSchemaVersion.VERSION_1_0);
479+
}
480+
return XmlSchemaVersion.VERSION_1_0;
481+
}
482+
483+
/**
484+
* @param schemaVersion The XML Schema version to use for the provided validation type.
485+
*/
486+
public void setSchemaVersion(Map<String, XmlSchemaVersion> schemaVersion) {
487+
this.schemaVersion = schemaVersion;
488+
}
471489
}

xmlvalidator-common/src/main/java/eu/europa/ec/itb/xml/DomainConfigCache.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ protected void addDomainConfiguration(DomainConfig domainConfig, Configuration c
121121
domainConfig.setPreloadRemoteSchemaImports(ParseUtils.parseBooleanMap("validator.preloadRemoteSchemaImports", config, domainConfig.getType(), config.getBoolean("validator.preloadRemoteSchemaImports", false)));
122122
}
123123
// Local mappings for remote schema imports and caching - end
124+
// XML Schema version - start
125+
domainConfig.setSchemaVersion(ParseUtils.parseEnumMap("validator.schemaVersion", XmlSchemaVersion.from(config.getString("validator.schemaVersion", "1.0")), config, domainConfig.getType(), XmlSchemaVersion::from));
126+
// XML Schema version - end
124127
}
125128

126129
/**

0 commit comments

Comments
 (0)