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:
ltheussl 2005-10-01 14:29:57 +00:00
parent fe4a78733e
commit dc2fcbc202

View File

@ -53,9 +53,13 @@ public class JaxpMsvBean
private Log log = LogFactory.getLog(JaxpMsvBean.class); private Log log = LogFactory.getLog(JaxpMsvBean.class);
private static String EMPTY = ""; private static String EMPTY = "";
private static ByteArrayInputStream bais = private static ByteArrayInputStream EMPTY_STREAM =
new ByteArrayInputStream(EMPTY.getBytes()); new ByteArrayInputStream(EMPTY.getBytes());
private static int MSV_WARNING = 0;
private static int MSV_ERROR = 1;
private static int MSV_FATAL_ERROR = 2;
//~ Methods -------------------------------------------------------------- //~ Methods --------------------------------------------------------------
/** /**
@ -72,16 +76,16 @@ public class JaxpMsvBean
boolean isValid = true; boolean isValid = true;
public void warning(SAXParseException e) throws SAXException public void warning(SAXParseException e) throws SAXException
{ {
log.warn(e); errorMessage(e, MSV_WARNING);
} }
public void error(SAXParseException e) throws SAXException public void error(SAXParseException e) throws SAXException
{ {
log.error(e); errorMessage(e, MSV_ERROR);
isValid = false; isValid = false;
} }
public void fatalError(SAXParseException e) throws SAXException public void fatalError(SAXParseException e) throws SAXException
{ {
log.error(e); errorMessage(e, MSV_FATAL_ERROR);
isValid = false; isValid = false;
} }
public InputSource resolveEntity(String publicId, public InputSource resolveEntity(String publicId,
@ -89,7 +93,7 @@ public class JaxpMsvBean
{ {
log.warn("WARNING: External entity " + systemId log.warn("WARNING: External entity " + systemId
+ " won't be resolved!"); + " won't be resolved!");
return new InputSource(bais); return new InputSource(EMPTY_STREAM);
} }
public void endDocument() 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. * Sets the schema.
* *
@ -144,5 +170,4 @@ public class JaxpMsvBean
} }
} }