Skip to content

Commit

Permalink
Issue mojohaus#20 completed (support for ISO/IEC 19757-11:2011 xml-mo…
Browse files Browse the repository at this point in the history
…del processing instruction)
  • Loading branch information
rosslamont committed Aug 13, 2017
1 parent b579e88 commit a94160a
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 28 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@
<version>2.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.componentcorp.xml.validation</groupId>
<artifactId>jxvc</artifactId>
<version>0.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.componentcorp.xml.validation</groupId>
<artifactId>relaxng-compact</artifactId>
<version>0.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand Down
63 changes: 35 additions & 28 deletions src/main/java/org/codehaus/mojo/xml/ValidateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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
{
Expand All @@ -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 )
{
Expand Down
21 changes: 21 additions & 0 deletions src/test/it15/catalog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system systemId="http://mojohaus.org/schema/maven-xml/schema.rnc"
uri="schema.rnc"/>
</catalog>
46 changes: 46 additions & 0 deletions src/test/it15/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.xml</groupId>
<artifactId>it15</artifactId>
<version>0.1</version>
<name>Maven XML Plugin IT 15</name>
<description>Integration Test 15 for the Maven XML Plugin</description>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>0.2</version>
<configuration>
<validationSets>
<validationSet>
<dir>xml</dir>
<schemaLanguage>http://componentcorp.com/xml/ns/xml-model/1.0</schemaLanguage>
</validationSet>
</validationSets>
<catalogs>
<catalog>catalog.xml</catalog>
</catalogs>
</configuration>
</plugin>
</plugins>
</build>
</project>
5 changes: 5 additions & 0 deletions src/test/it15/schema.rnc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

element counter {

element item { empty }*
}
21 changes: 21 additions & 0 deletions src/test/it15/xml/doc1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<?xml-model href="http://mojohaus.org/schema/maven-xml/schema.rnc" schematypens="http://www.iana.org/assignments/media-types/application/relax-ng-compact-syntax" ?>
<counter ><item/><item/><item/></counter>

13 changes: 13 additions & 0 deletions src/test/java/org/codehaus/mojo/xml/test/ValidateMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit a94160a

Please sign in to comment.