notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r1975 - trunk/main/metro/part/src/main/dpml/lang
- Date: Mon, 16 Apr 2007 22:25:42 +0200
Author: mcconnell
Date: 2007-04-16 22:25:42 +0200 (Mon, 16 Apr 2007)
New Revision: 1975
Modified:
trunk/main/metro/part/src/main/dpml/lang/DOM3DocumentBuilder.java
Log:
improved error handling
Modified: trunk/main/metro/part/src/main/dpml/lang/DOM3DocumentBuilder.java
===================================================================
--- trunk/main/metro/part/src/main/dpml/lang/DOM3DocumentBuilder.java
2007-04-16 20:24:50 UTC (rev 1974)
+++ trunk/main/metro/part/src/main/dpml/lang/DOM3DocumentBuilder.java
2007-04-16 20:25:42 UTC (rev 1975)
@@ -38,6 +38,7 @@
import javax.xml.XMLConstants;
import net.dpml.lang.PartError;
+import net.dpml.lang.DecodingException;
import net.dpml.transit.Artifact;
import net.dpml.transit.InvalidArtifactException;
@@ -137,7 +138,8 @@
DOMConfiguration config = builder.getDomConfig();
URI uri = url.toURI();
- config.setParameter( "error-handler", new InternalErrorHandler(
m_logger, uri ) );
+ InternalErrorHandler errorHandler = new InternalErrorHandler(
m_logger, uri );
+ config.setParameter( "error-handler", errorHandler );
config.setParameter( "resource-resolver", new
InternalResourceResolver( m_logger ) );
config.setParameter( "validate", Boolean.TRUE );
DOMInput input = new DOMInput();
@@ -147,6 +149,14 @@
input.setCharacterStream( reader );
Document doc = builder.parse( input );
+ int n = errorHandler.getErrorCount();
+ if( n > 0 )
+ {
+ final String error =
+ "Document validation failure."
+ + "\nURL: " + url;
+ throw new DecodingException( error, null, null );
+ }
doc.setDocumentURI( uri.toASCIIString() );
return doc;
}
@@ -158,6 +168,10 @@
{
throw e;
}
+ catch( DecodingException e )
+ {
+ throw e;
+ }
catch( Throwable e )
{
final String error =
@@ -279,12 +293,19 @@
private final URI m_uri;
private final Logger m_logger;
+ private int m_count = 0;
+
InternalErrorHandler( Logger logger, URI uri )
{
m_uri = uri;
m_logger = logger;
}
+ int getErrorCount()
+ {
+ return m_count;
+ }
+
/**
* Handle the supplied error.
* @param error the error
@@ -292,6 +313,7 @@
*/
public boolean handleError( DOMError error )
{
+ m_count++;
DOMLocator locator = error.getLocation();
int line = locator.getLineNumber();
int column = locator.getColumnNumber();
@@ -314,12 +336,13 @@
short severity = error.getSeverity();
if( severity == DOMError.SEVERITY_WARNING )
{
- //m_logger.warn( notice );
+ m_logger.warn( notice );
//return true;
return false;
}
else
{
+ m_logger.warn( notice );
return false;
}
}
- r1975 - trunk/main/metro/part/src/main/dpml/lang, mcconnell at BerliOS, 04/16/2007
Archive powered by MHonArc 2.6.24.