Make namespace aware. Fail the build in case of namespace mismatch to avoid msv hanging. Code formatting.
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@345548 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b0bd6ac521
commit
1141d95fc6
@ -76,21 +76,22 @@ public class JaxpMsvBean
|
||||
*/
|
||||
public void validate() throws Exception
|
||||
{
|
||||
|
||||
VerifierFactory verifierFactory = new TheFactoryImpl();
|
||||
|
||||
Verifier verifier = verifierFactory.newVerifier( new File( schema ) );
|
||||
|
||||
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
factory.setNamespaceAware(false);
|
||||
factory.setValidating(false);
|
||||
XMLReader reader = factory.newSAXParser().getXMLReader();
|
||||
verifier.setErrorHandler( new ErrorHandlerImpl() );
|
||||
|
||||
VerifierHandler handler = verifier.getVerifierHandler();
|
||||
tracker = new XPathLocationTracker( handler );
|
||||
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
factory.setNamespaceAware( true );
|
||||
factory.setValidating( false );
|
||||
|
||||
|
||||
XMLReader reader = factory.newSAXParser().getXMLReader();
|
||||
reader.setContentHandler( tracker );
|
||||
reader.setEntityResolver( new EntityResolverImpl() );
|
||||
verifier.setErrorHandler( new ErrorHandlerImpl() );
|
||||
|
||||
reader.parse( new InputSource( new FileInputStream( file ) ) );
|
||||
endMessage();
|
||||
@ -181,16 +182,25 @@ public class JaxpMsvBean
|
||||
|
||||
public void error(SAXParseException e) throws SAXException
|
||||
{
|
||||
if (e.getMessage() != null && e.getMessage().indexOf("xsi:schemaLocation") > -1)
|
||||
/*if (e.getMessage() != null && e.getMessage().indexOf("xsi:schemaLocation") > -1)
|
||||
{
|
||||
// unexpected attribute "xsi:schemaLocation"
|
||||
// ignore, this is due to a valid xsd declaration
|
||||
// Jaxp ignores additionals namespaces declared in the xml file (xmlns:xsi) and it can't validate
|
||||
// using multiple schema at once
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
errorMessage( e, MSV_ERROR) ;
|
||||
setValid( false );
|
||||
|
||||
if ( e.getMessage() != null
|
||||
&& e.getMessage().startsWith("namespace URI of tag") )
|
||||
{
|
||||
// Fail the build if namespace declaration is wrong.
|
||||
// Otherwise parsing seems to hang after the first element.
|
||||
throw new SAXException( e );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void fatalError(SAXParseException e) throws SAXException
|
||||
@ -200,7 +210,6 @@ public class JaxpMsvBean
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class EntityResolverImpl implements EntityResolver
|
||||
{
|
||||
public InputSource resolveEntity(String publicId,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user