From a94160a1b6b3f915ac95cf263a2c83f21344e414 Mon Sep 17 00:00:00 2001 From: Ross Lamont Date: Mon, 14 Aug 2017 09:01:49 +1000 Subject: [PATCH] Issue #20 completed (support for ISO/IEC 19757-11:2011 xml-model processing instruction) --- pom.xml | 12 ++++ .../org/codehaus/mojo/xml/ValidateMojo.java | 63 ++++++++++--------- src/test/it15/catalog.xml | 21 +++++++ src/test/it15/pom.xml | 46 ++++++++++++++ src/test/it15/schema.rnc | 5 ++ src/test/it15/xml/doc1.xml | 21 +++++++ .../mojo/xml/test/ValidateMojoTest.java | 13 ++++ 7 files changed, 153 insertions(+), 28 deletions(-) create mode 100644 src/test/it15/catalog.xml create mode 100644 src/test/it15/pom.xml create mode 100644 src/test/it15/schema.rnc create mode 100644 src/test/it15/xml/doc1.xml diff --git a/pom.xml b/pom.xml index f19bc4a..8429c39 100644 --- a/pom.xml +++ b/pom.xml @@ -160,6 +160,18 @@ 2.7.1 test + + com.componentcorp.xml.validation + jxvc + 0.9.1 + test + + + com.componentcorp.xml.validation + relaxng-compact + 0.9.1 + test + org.apache.maven.plugin-tools maven-plugin-annotations diff --git a/src/main/java/org/codehaus/mojo/xml/ValidateMojo.java b/src/main/java/org/codehaus/mojo/xml/ValidateMojo.java index 43e9312..454ff0b 100644 --- a/src/main/java/org/codehaus/mojo/xml/ValidateMojo.java +++ b/src/main/java/org/codehaus/mojo/xml/ValidateMojo.java @@ -52,6 +52,8 @@ public class ValidateMojo extends AbstractXmlMojo { + private static final String INTRINSIC_NS_URI="http://componentcorp.com/xml/ns/xml-model/1.0"; + /** * Specifies a set of document types, which are being validated. */ @@ -69,42 +71,47 @@ public class ValidateMojo private Schema getSchema( Resolver pResolver, ValidationSet pValidationSet ) throws MojoExecutionException { + String schemaLanguage = pValidationSet.getSchemaLanguage(); + if ( schemaLanguage == null || "".equals( schemaLanguage ) ) + { + schemaLanguage = XMLConstants.W3C_XML_SCHEMA_NS_URI; + } final String publicId = pValidationSet.getPublicId(); final String systemId = pValidationSet.getSystemId(); - if ( ( publicId == null || "".equals( publicId ) ) && ( systemId == null || "".equals( systemId ) ) ) + if ( ( publicId == null || "".equals( publicId ) ) && ( systemId == null || "".equals( systemId ) ) && !INTRINSIC_NS_URI.equals(schemaLanguage)) { return null; } - - getLog().debug( "Loading schema with public Id " + publicId + ", system Id " + systemId ); - InputSource inputSource = null; - if ( pResolver != null ) - { - try - { - inputSource = pResolver.resolveEntity( publicId, systemId ); - } - catch ( SAXException e ) + final SAXSource saxSource; + if (INTRINSIC_NS_URI.equals(schemaLanguage) && ( publicId == null || "".equals( publicId ) ) && ( systemId == null || "".equals( systemId ) ) ){ + //publicId and systemID make no sense for the IntrinsicSchemaValidator. + saxSource=null; + } + else{ + getLog().debug( "Loading schema with public Id " + publicId + ", system Id " + systemId ); + InputSource inputSource = null; + if ( pResolver != null ) { - throw new MojoExecutionException( e.getMessage(), e ); + try + { + inputSource = pResolver.resolveEntity( publicId, systemId ); + } + catch ( SAXException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } } - catch ( IOException e ) + if ( inputSource == null ) { - throw new MojoExecutionException( e.getMessage(), e ); + inputSource = new InputSource(); + inputSource.setPublicId( publicId ); + inputSource.setSystemId( systemId ); } - } - if ( inputSource == null ) - { - inputSource = new InputSource(); - inputSource.setPublicId( publicId ); - inputSource.setSystemId( systemId ); - } - final SAXSource saxSource = new SAXSource( inputSource ); - - String schemaLanguage = pValidationSet.getSchemaLanguage(); - if ( schemaLanguage == null || "".equals( schemaLanguage ) ) - { - schemaLanguage = XMLConstants.W3C_XML_SCHEMA_NS_URI; + saxSource = new SAXSource( inputSource ); } try { @@ -113,7 +120,7 @@ private Schema getSchema( Resolver pResolver, ValidationSet pValidationSet ) { schemaFactory.setResourceResolver( pResolver ); } - return schemaFactory.newSchema( saxSource ); + return saxSource==null?schemaFactory.newSchema():schemaFactory.newSchema( saxSource ); } catch ( SAXException e ) { diff --git a/src/test/it15/catalog.xml b/src/test/it15/catalog.xml new file mode 100644 index 0000000..eed720c --- /dev/null +++ b/src/test/it15/catalog.xml @@ -0,0 +1,21 @@ + + + + diff --git a/src/test/it15/pom.xml b/src/test/it15/pom.xml new file mode 100644 index 0000000..a2d8430 --- /dev/null +++ b/src/test/it15/pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + org.codehaus.mojo.xml + it15 + 0.1 + Maven XML Plugin IT 15 + Integration Test 15 for the Maven XML Plugin + + + + org.codehaus.mojo + xml-maven-plugin + 0.2 + + + + xml + http://componentcorp.com/xml/ns/xml-model/1.0 + + + + catalog.xml + + + + + + diff --git a/src/test/it15/schema.rnc b/src/test/it15/schema.rnc new file mode 100644 index 0000000..6617337 --- /dev/null +++ b/src/test/it15/schema.rnc @@ -0,0 +1,5 @@ + +element counter { + + element item { empty }* +} diff --git a/src/test/it15/xml/doc1.xml b/src/test/it15/xml/doc1.xml new file mode 100644 index 0000000..0c11280 --- /dev/null +++ b/src/test/it15/xml/doc1.xml @@ -0,0 +1,21 @@ + + + + + diff --git a/src/test/java/org/codehaus/mojo/xml/test/ValidateMojoTest.java b/src/test/java/org/codehaus/mojo/xml/test/ValidateMojoTest.java index 7fb6988..987d14a 100644 --- a/src/test/java/org/codehaus/mojo/xml/test/ValidateMojoTest.java +++ b/src/test/java/org/codehaus/mojo/xml/test/ValidateMojoTest.java @@ -118,6 +118,19 @@ public void testIt14() } } + public void testIt15() + throws Exception + { + try{ + runTest( "src/test/it15" ); + } + catch(Exception e){ + e.printStackTrace(); + fail(); + } + } + + /** * Builds and runs the xinclude test project */