You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2007/05/20 22:17:24 UTC
svn commit: r539929 - in /xerces/java/trunk/src/org/apache/xerces: impl/
parsers/ xinclude/
Author: mrglavas
Date: Sun May 20 13:17:23 2007
New Revision: 539929
URL: http://svn.apache.org/viewvc?view=rev&rev=539929
Log:
JIRA Issue #1189:
http://issues.apache.org/jira/browse/XERCESJ-1189
To make it easier for applications to recognize encoding errors, wrap the
java.io.CharConversionException in the SAXException instead of dropping it
on the floor.
Modified:
xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java
xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java
xerces/java/trunk/src/org/apache/xerces/impl/XMLErrorReporter.java
xerces/java/trunk/src/org/apache/xerces/impl/XMLVersionDetector.java
xerces/java/trunk/src/org/apache/xerces/parsers/AbstractSAXParser.java
xerces/java/trunk/src/org/apache/xerces/parsers/DOMParser.java
xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeHandler.java
Modified: xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java?view=diff&rev=539929&r1=539928&r2=539929
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java Sun May 20 13:17:23 2007
@@ -1771,11 +1771,15 @@
// encoding errors
catch (MalformedByteSequenceException e) {
fErrorReporter.reportError(e.getDomain(), e.getKey(),
- e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
catch (CharConversionException e) {
- reportFatalError("CharConversionFailure", null);
+ fErrorReporter.reportError(
+ XMLMessageFormatter.XML_DOMAIN,
+ "CharConversionFailure",
+ null,
+ XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
// premature end of file
Modified: xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java?view=diff&rev=539929&r1=539928&r2=539929
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java Sun May 20 13:17:23 2007
@@ -23,6 +23,7 @@
import org.apache.xerces.impl.dtd.XMLDTDDescription;
import org.apache.xerces.impl.io.MalformedByteSequenceException;
+import org.apache.xerces.impl.msg.XMLMessageFormatter;
import org.apache.xerces.impl.validation.ValidationManager;
import org.apache.xerces.util.NamespaceSupport;
import org.apache.xerces.util.XMLChar;
@@ -693,11 +694,15 @@
// encoding errors
catch (MalformedByteSequenceException e) {
fErrorReporter.reportError(e.getDomain(), e.getKey(),
- e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
catch (CharConversionException e) {
- reportFatalError("CharConversionFailure", null);
+ fErrorReporter.reportError(
+ XMLMessageFormatter.XML_DOMAIN,
+ "CharConversionFailure",
+ null,
+ XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
// premature end of file
@@ -882,11 +887,15 @@
// encoding errors
catch (MalformedByteSequenceException e) {
fErrorReporter.reportError(e.getDomain(), e.getKey(),
- e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
catch (CharConversionException e) {
- reportFatalError("CharConversionFailure", null);
+ fErrorReporter.reportError(
+ XMLMessageFormatter.XML_DOMAIN,
+ "CharConversionFailure",
+ null,
+ XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
// premature end of file
@@ -1016,11 +1025,15 @@
// encoding errors
catch (MalformedByteSequenceException e) {
fErrorReporter.reportError(e.getDomain(), e.getKey(),
- e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
catch (CharConversionException e) {
- reportFatalError("CharConversionFailure", null);
+ fErrorReporter.reportError(
+ XMLMessageFormatter.XML_DOMAIN,
+ "CharConversionFailure",
+ null,
+ XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
// premature end of file
@@ -1307,11 +1320,15 @@
// encoding errors
catch (MalformedByteSequenceException e) {
fErrorReporter.reportError(e.getDomain(), e.getKey(),
- e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
catch (CharConversionException e) {
- reportFatalError("CharConversionFailure", null);
+ fErrorReporter.reportError(
+ XMLMessageFormatter.XML_DOMAIN,
+ "CharConversionFailure",
+ null,
+ XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return false;
}
catch (EOFException e) {
Modified: xerces/java/trunk/src/org/apache/xerces/impl/XMLErrorReporter.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/XMLErrorReporter.java?view=diff&rev=539929&r1=539928&r2=539929
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/XMLErrorReporter.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/XMLErrorReporter.java Sun May 20 13:17:23 2007
@@ -280,6 +280,47 @@
short severity) throws XNIException {
reportError(fLocator, domain, key, arguments, severity);
} // reportError(String,String,Object[],short)
+
+ /**
+ * Reports an error. The error message passed to the error handler
+ * is formatted for the locale by the message formatter installed
+ * for the specified error domain.
+ *
+ * @param domain The error domain.
+ * @param key The key of the error message.
+ * @param arguments The replacement arguments for the error message,
+ * if needed.
+ * @param severity The severity of the error.
+ * @param exception The exception to wrap.
+ *
+ * @see #SEVERITY_WARNING
+ * @see #SEVERITY_ERROR
+ * @see #SEVERITY_FATAL_ERROR
+ */
+ public void reportError(String domain, String key, Object[] arguments,
+ short severity, Exception exception) throws XNIException {
+ reportError(fLocator, domain, key, arguments, severity, exception);
+ } // reportError(String,String,Object[],short,Exception)
+
+ /**
+ * Reports an error at a specific location.
+ *
+ * @param location The error location.
+ * @param domain The error domain.
+ * @param key The key of the error message.
+ * @param arguments The replacement arguments for the error message,
+ * if needed.
+ * @param severity The severity of the error.
+ *
+ * @see #SEVERITY_WARNING
+ * @see #SEVERITY_ERROR
+ * @see #SEVERITY_FATAL_ERROR
+ */
+ public void reportError(XMLLocator location,
+ String domain, String key, Object[] arguments,
+ short severity) throws XNIException {
+ reportError(fLocator, domain, key, arguments, severity, null);
+ } // reportError(XMLLocator,String,String,Object[],short)
/**
* Reports an error at a specific location.
@@ -290,6 +331,7 @@
* @param arguments The replacement arguments for the error message,
* if needed.
* @param severity The severity of the error.
+ * @param exception The exception to wrap.
*
* @see #SEVERITY_WARNING
* @see #SEVERITY_ERROR
@@ -297,7 +339,7 @@
*/
public void reportError(XMLLocator location,
String domain, String key, Object[] arguments,
- short severity) throws XNIException {
+ short severity, Exception exception) throws XNIException {
// REVISIT: [Q] Should we do anything about invalid severity
// parameter? -Ac
@@ -325,7 +367,8 @@
}
message = str.toString();
}
- XMLParseException parseException =
+ XMLParseException parseException = (exception != null) ?
+ new XMLParseException(location, message, exception) :
new XMLParseException(location, message);
// get error handler
@@ -356,7 +399,7 @@
}
}
- } // reportError(XMLLocator,String,String,Object[],short)
+ } // reportError(XMLLocator,String,String,Object[],short,Exception)
//
// XMLComponent methods
Modified: xerces/java/trunk/src/org/apache/xerces/impl/XMLVersionDetector.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/XMLVersionDetector.java?view=diff&rev=539929&r1=539928&r2=539929
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/XMLVersionDetector.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/XMLVersionDetector.java Sun May 20 13:17:23 2007
@@ -188,7 +188,7 @@
// encoding errors
catch (MalformedByteSequenceException e) {
fErrorReporter.reportError(e.getDomain(), e.getKey(),
- e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return Constants.XML_VERSION_ERROR;
}
catch (CharConversionException e) {
@@ -196,7 +196,7 @@
XMLMessageFormatter.XML_DOMAIN,
"CharConversionFailure",
null,
- XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
return Constants.XML_VERSION_ERROR;
}
// premature end of file
Modified: xerces/java/trunk/src/org/apache/xerces/parsers/AbstractSAXParser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/parsers/AbstractSAXParser.java?view=diff&rev=539929&r1=539928&r2=539929
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/AbstractSAXParser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/AbstractSAXParser.java Sun May 20 13:17:23 2007
@@ -17,6 +17,7 @@
package org.apache.xerces.parsers;
+import java.io.CharConversionException;
import java.io.IOException;
import java.util.Locale;
@@ -1131,7 +1132,7 @@
// wrap XNI exceptions as SAX exceptions
catch (XMLParseException e) {
Exception ex = e.getException();
- if (ex == null) {
+ if (ex == null || ex instanceof CharConversionException) {
// must be a parser exception; mine it for locator info and throw
// a SAXParseException
LocatorImpl locatorImpl = new LocatorImpl(){
@@ -1151,7 +1152,9 @@
locatorImpl.setSystemId(e.getExpandedSystemId());
locatorImpl.setLineNumber(e.getLineNumber());
locatorImpl.setColumnNumber(e.getColumnNumber());
- throw new SAXParseException(e.getMessage(), locatorImpl);
+ throw (ex == null) ?
+ new SAXParseException(e.getMessage(), locatorImpl) :
+ new SAXParseException(e.getMessage(), locatorImpl, ex);
}
if (ex instanceof SAXException) {
// why did we create an XMLParseException?
@@ -1204,7 +1207,7 @@
// wrap XNI exceptions as SAX exceptions
catch (XMLParseException e) {
Exception ex = e.getException();
- if (ex == null) {
+ if (ex == null || ex instanceof CharConversionException) {
// must be a parser exception; mine it for locator info and throw
// a SAXParseException
LocatorImpl locatorImpl = new LocatorImpl() {
@@ -1224,7 +1227,9 @@
locatorImpl.setSystemId(e.getExpandedSystemId());
locatorImpl.setLineNumber(e.getLineNumber());
locatorImpl.setColumnNumber(e.getColumnNumber());
- throw new SAXParseException(e.getMessage(), locatorImpl);
+ throw (ex == null) ?
+ new SAXParseException(e.getMessage(), locatorImpl) :
+ new SAXParseException(e.getMessage(), locatorImpl, ex);
}
if (ex instanceof SAXException) {
// why did we create an XMLParseException?
Modified: xerces/java/trunk/src/org/apache/xerces/parsers/DOMParser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/parsers/DOMParser.java?view=diff&rev=539929&r1=539928&r2=539929
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/DOMParser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/DOMParser.java Sun May 20 13:17:23 2007
@@ -17,6 +17,7 @@
package org.apache.xerces.parsers;
+import java.io.CharConversionException;
import java.io.IOException;
import org.apache.xerces.impl.Constants;
@@ -167,7 +168,7 @@
// wrap XNI exceptions as SAX exceptions
catch (XMLParseException e) {
Exception ex = e.getException();
- if (ex == null) {
+ if (ex == null || ex instanceof CharConversionException) {
// must be a parser exception; mine it for locator info and throw
// a SAXParseException
LocatorImpl locatorImpl = new LocatorImpl();
@@ -175,7 +176,9 @@
locatorImpl.setSystemId(e.getExpandedSystemId());
locatorImpl.setLineNumber(e.getLineNumber());
locatorImpl.setColumnNumber(e.getColumnNumber());
- throw new SAXParseException(e.getMessage(), locatorImpl);
+ throw (ex == null) ?
+ new SAXParseException(e.getMessage(), locatorImpl) :
+ new SAXParseException(e.getMessage(), locatorImpl, ex);
}
if (ex instanceof SAXException) {
// why did we create an XMLParseException?
@@ -229,7 +232,7 @@
// wrap XNI exceptions as SAX exceptions
catch (XMLParseException e) {
Exception ex = e.getException();
- if (ex == null) {
+ if (ex == null || ex instanceof CharConversionException) {
// must be a parser exception; mine it for locator info and throw
// a SAXParseException
LocatorImpl locatorImpl = new LocatorImpl();
@@ -237,7 +240,9 @@
locatorImpl.setSystemId(e.getExpandedSystemId());
locatorImpl.setLineNumber(e.getLineNumber());
locatorImpl.setColumnNumber(e.getColumnNumber());
- throw new SAXParseException(e.getMessage(), locatorImpl);
+ throw (ex == null) ?
+ new SAXParseException(e.getMessage(), locatorImpl) :
+ new SAXParseException(e.getMessage(), locatorImpl, ex);
}
if (ex instanceof SAXException) {
// why did we create an XMLParseException?
Modified: xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeHandler.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeHandler.java?view=diff&rev=539929&r1=539928&r2=539929
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeHandler.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/xinclude/XIncludeHandler.java Sun May 20 13:17:23 2007
@@ -1783,11 +1783,11 @@
// encoding errors
catch (MalformedByteSequenceException ex) {
fErrorReporter.reportError(ex.getDomain(), ex.getKey(),
- ex.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ ex.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, ex);
}
catch (CharConversionException e) {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
- "CharConversionFailure", null, XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ "CharConversionFailure", null, XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
}
catch (IOException e) {
// If a characters event has already been sent down the pipeline it
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org