Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #34. Handle relative href in xml-model processing instructions #35

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@
<dependency>
<groupId>com.componentcorp.xml.validation</groupId>
<artifactId>jxvc</artifactId>
<version>0.9.3</version>
<version>0.9.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.componentcorp.xml.validation</groupId>
<artifactId>relaxng-compact</artifactId>
<version>0.9.3</version>
<version>0.9.4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
80 changes: 72 additions & 8 deletions src/main/java/org/codehaus/mojo/xml/Resolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public Source resolve( String pHref, String pBase )

if ( null == url )
{
url = resolve( pHref );
url = resolve( pHref ); //probably should call new method resolve(String,URI) but left alone for legacy reasons.
}

if ( url != null )
Expand Down Expand Up @@ -245,8 +245,19 @@ public LSInput resolveResource( String pType, String pNamespaceURI, String pPubl
{
return newLSInput( isource );
}
URI baseURI = null;
if (pBaseURI!=null){
try
{
baseURI = new URI(pBaseURI);
}
catch ( URISyntaxException ex )
{
baseURI=null; //or perhaps this should be an UndeclaredThrowableException
}
}

URL url = resolve( pSystemId );
URL url = resolve( pSystemId ,baseURI);
if ( url != null )
{
try
Expand Down Expand Up @@ -305,7 +316,7 @@ private URL resolveAsFile( String pResource )
}
}

private URL resolveAsURL( String pResource )
private URL resolveAsURL( String pResource,URI pBaseURI )
{
InputStream stream = null;
try
Expand All @@ -318,7 +329,41 @@ private URL resolveAsURL( String pResource )
}
catch ( IOException e )
{
return null;
//fall through to relative URI resolution
}
finally
{
if ( stream != null )
{
try
{
stream.close();
}
catch ( Throwable t )
{
// Ignore me
}
}
}
try{
URI resourceASURI = new URI (pResource);
if (pBaseURI!=null &&!resourceASURI.isAbsolute() && pBaseURI.isAbsolute()){
resourceASURI=pBaseURI.resolve( resourceASURI );
final URL url = resourceASURI.toURL();
stream = url.openStream();
stream.close();
stream = null;
return url;

}
}
catch ( URISyntaxException ex )
{
//ignore
}
catch ( IOException e )
{
//ignore
}
finally
{
Expand All @@ -334,6 +379,7 @@ private URL resolveAsURL( String pResource )
}
}
}
return null;
}

/**
Expand All @@ -343,6 +389,11 @@ private URL resolveAsURL( String pResource )
*/
public URL resolve( String pResource )
{
return resolve(pResource,(URI)null);
}


private URL resolve(String pResource,URI pBaseURI){
if ( pResource == null )
{
return null;
Expand All @@ -357,16 +408,19 @@ public URL resolve( String pResource )
URL url = resolveAsResource( pResource );
if ( url == null )
{
url = resolveAsURL( pResource );
url = resolveAsURL( pResource,null ); //original style resolution
if ( url == null )
{
url = resolveAsFile( pResource );
}
if (url == null){ //relative URL resolution
url = resolveAsURL( pResource,pBaseURI );
}
}

try
{
return locator.getResource( pResource ).getURL();
return locator.getResource( url.toExternalForm()).getURL();
}
catch ( ResourceNotFoundException e )
{
Expand Down Expand Up @@ -398,8 +452,18 @@ public InputSource resolveEntity( String pName, String pPublicId, String pBaseUR
{
return source;
}

URL url = resolve( pSystemId );
URI baseURI = null;
if (pBaseURI!=null){
try
{
baseURI = new URI(pBaseURI);
}
catch ( URISyntaxException ex )
{
throw new SAXException("Incorrectly formatted base URI", ex);
}
}
URL url = resolve( pSystemId ,baseURI);
if ( url != null )
{
return asInputSource( url );
Expand Down
43 changes: 43 additions & 0 deletions src/test/it18/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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>
</configuration>
</plugin>
</plugins>
</build>
</project>
5 changes: 5 additions & 0 deletions src/test/it18/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/it18/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="../schema.rnc" schematypens="http://www.iana.org/assignments/media-types/application/relax-ng-compact-syntax" ?>
<counter ><item/><item/><item/></counter>

17 changes: 17 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 @@ -142,6 +142,23 @@ public void testIt15()
}


/**
* Builds, and runs the it18 project.
* @throws Exception The test failed.
*/
public void testIt18()
throws Exception
{
try{
runTest( "src/test/it18" );
}
catch(Exception e){
e.printStackTrace();
fail();
}
}


/**
* Builds and runs the xinclude test project
* @throws Exception The test failed.
Expand Down