Improve error handling
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@292988 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fe4a78733e
commit
dc2fcbc202
@ -53,9 +53,13 @@ public class JaxpMsvBean
|
||||
private Log log = LogFactory.getLog(JaxpMsvBean.class);
|
||||
|
||||
private static String EMPTY = "";
|
||||
private static ByteArrayInputStream bais =
|
||||
private static ByteArrayInputStream EMPTY_STREAM =
|
||||
new ByteArrayInputStream(EMPTY.getBytes());
|
||||
|
||||
private static int MSV_WARNING = 0;
|
||||
private static int MSV_ERROR = 1;
|
||||
private static int MSV_FATAL_ERROR = 2;
|
||||
|
||||
//~ Methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@ -72,16 +76,16 @@ public class JaxpMsvBean
|
||||
boolean isValid = true;
|
||||
public void warning(SAXParseException e) throws SAXException
|
||||
{
|
||||
log.warn(e);
|
||||
errorMessage(e, MSV_WARNING);
|
||||
}
|
||||
public void error(SAXParseException e) throws SAXException
|
||||
{
|
||||
log.error(e);
|
||||
errorMessage(e, MSV_ERROR);
|
||||
isValid = false;
|
||||
}
|
||||
public void fatalError(SAXParseException e) throws SAXException
|
||||
{
|
||||
log.error(e);
|
||||
errorMessage(e, MSV_FATAL_ERROR);
|
||||
isValid = false;
|
||||
}
|
||||
public InputSource resolveEntity(String publicId,
|
||||
@ -89,7 +93,7 @@ public class JaxpMsvBean
|
||||
{
|
||||
log.warn("WARNING: External entity " + systemId
|
||||
+ " won't be resolved!");
|
||||
return new InputSource(bais);
|
||||
return new InputSource(EMPTY_STREAM);
|
||||
}
|
||||
public void endDocument()
|
||||
{
|
||||
@ -103,6 +107,28 @@ public class JaxpMsvBean
|
||||
});
|
||||
}
|
||||
|
||||
private void errorMessage(SAXParseException e, int type)
|
||||
{
|
||||
File xmlFile = new File(file);
|
||||
|
||||
if (type == MSV_ERROR)
|
||||
{
|
||||
log.error( "com.sun.msv.verifier.ValidityViolation on line "
|
||||
+ e.getLineNumber() + " of " + xmlFile.getName() + ":" );
|
||||
log.error( e.getMessage() );
|
||||
} else if (type == MSV_FATAL_ERROR)
|
||||
{
|
||||
log.error( "Non-recoverable parsing error on line "
|
||||
+ e.getLineNumber() + " of " + xmlFile.getName() + ":" );
|
||||
log.error( e.getMessage() );
|
||||
} else if (type == MSV_WARNING)
|
||||
{
|
||||
log.warn( "Warning on line "
|
||||
+ e.getLineNumber() + " of " + xmlFile.getName() + ":" );
|
||||
log.warn( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the schema.
|
||||
*
|
||||
@ -143,6 +169,5 @@ public class JaxpMsvBean
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user