mrglavas 2004/02/12 15:26:06
Modified: java/src/org/apache/xerces/parsers AbstractDOMParser.java
DOMParserImpl.java
Log:
Fixing behaviour for interrupts and abort. We were
throwing a RuntimeException to stop parsing but
this bubbled up to the user. Instead throw a
unique instance of RuntimeException and consume
it in the parse methods.
Revision Changes Path
1.105 +14 -9
xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java
Index: AbstractDOMParser.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- AbstractDOMParser.java 10 Feb 2004 19:14:06 -0000 1.104
+++ AbstractDOMParser.java 12 Feb 2004 23:26:06 -0000 1.105
@@ -195,6 +195,11 @@
protected static final String PSVI_DOCUMENT_CLASS_NAME =
"org.apache.xerces.dom.PSVIDocumentImpl";
+ /**
+ * If the user stops the process, this exception will be thrown.
+ */
+ public static final RuntimeException abort = new RuntimeException();
+
// debugging
private static final boolean DEBUG_EVENTS = false;
@@ -628,7 +633,7 @@
short code = fDOMFilter.acceptNode (comment);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
- throw new RuntimeException ("The normal processing of the
document was interrupted.");
+ throw abort;
}
case LSParserFilter.FILTER_REJECT:{
// REVISIT: the constant FILTER_REJECT should be changed
when new
@@ -710,7 +715,7 @@
short code = fDOMFilter.acceptNode (pi);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
- throw new RuntimeException ("The normal processing of the
document was interrupted.");
+ throw abort;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since PI has no children.
@@ -1012,7 +1017,7 @@
switch (code) {
case LSParserFilter.FILTER_INTERRUPT :
{
- throw new RuntimeException("The normal processing
of the document was interrupted.");
+ throw abort;
}
case LSParserFilter.FILTER_REJECT :
{
@@ -1295,7 +1300,7 @@
short code = fDOMFilter.acceptNode (fCurrentNode);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
- throw new RuntimeException ("The normal processing of
the document was interrupted.");
+ throw abort;
}
case LSParserFilter.FILTER_REJECT:{
Node parent = fCurrentNode.getParentNode ();
@@ -1387,7 +1392,7 @@
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
- throw new RuntimeException ("The normal processing of
the document was interrupted.");
+ throw abort;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no
children.
@@ -1499,7 +1504,7 @@
short code = fDOMFilter.acceptNode (fCurrentNode);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
- throw new RuntimeException ("The normal processing of
the document was interrupted.");
+ throw abort;
}
case LSParserFilter.FILTER_REJECT:{
Node parent = fCurrentNode.getParentNode ();
@@ -2548,7 +2553,7 @@
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
- throw new RuntimeException ("The normal processing of
the document was interrupted.");
+ throw abort;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
@@ -2572,7 +2577,7 @@
* @see org.w3c.dom.ls.LSParser#abort()
*/
public void abort () {
- throw new RuntimeException ();
+ throw abort;
}
1.15 +32 -25 xml-xerces/java/src/org/apache/xerces/parsers/DOMParserImpl.java
Index: DOMParserImpl.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/DOMParserImpl.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DOMParserImpl.java 30 Jan 2004 00:16:27 -0000 1.14
+++ DOMParserImpl.java 12 Feb 2004 23:26:06 -0000 1.15
@@ -853,17 +853,21 @@
fBusy = false;
} catch (Exception e){
fBusy = false;
- if (fErrorHandler != null) {
- DOMErrorImpl error = new DOMErrorImpl ();
- error.fException = e;
- error.fMessage = e.getMessage ();
- error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
- fErrorHandler.getErrorHandler ().handleError (error);
+ // Consume this exception if the user
+ // issued an interrupt or an abort.
+ if (e != abort) {
+ if (fErrorHandler != null) {
+ DOMErrorImpl error = new DOMErrorImpl ();
+ error.fException = e;
+ error.fMessage = e.getMessage ();
+ error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
+ fErrorHandler.getErrorHandler ().handleError (error);
+ }
+ if (DEBUG) {
+ e.printStackTrace ();
+ }
+ throw new LSException(LSException.PARSE_ERR, e.getMessage());
}
- if (DEBUG) {
- e.printStackTrace ();
- }
- throw new LSException(LSException.PARSE_ERR, e.getMessage());
}
return getDocument ();
}
@@ -890,19 +894,22 @@
fBusy = false;
} catch (Exception e) {
fBusy = false;
- if (fErrorHandler != null) {
- DOMErrorImpl error = new DOMErrorImpl ();
- error.fException = e;
- error.fMessage = e.getMessage ();
- error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
- fErrorHandler.getErrorHandler ().handleError (error);
- }
- if (DEBUG) {
- e.printStackTrace ();
- }
- throw new LSException(LSException.PARSE_ERR, e.getMessage());
+ // Consume this exception if the user
+ // issued an interrupt or an abort.
+ if (e != abort) {
+ if (fErrorHandler != null) {
+ DOMErrorImpl error = new DOMErrorImpl ();
+ error.fException = e;
+ error.fMessage = e.getMessage ();
+ error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
+ fErrorHandler.getErrorHandler().handleError (error);
+ }
+ if (DEBUG) {
+ e.printStackTrace ();
+ }
+ throw new LSException(LSException.PARSE_ERR, e.getMessage());
+ }
}
-
return getDocument ();
}
@@ -990,8 +997,8 @@
public void abort () {
// If parse operation is in progress then reset it
if ( fBusy ) {
- fBusy = false;
- throw new RuntimeException("Stopped at user request");
+ fBusy = false;
+ throw abort;
}
return; // If not busy then this is noop
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]