craigmcc 01/04/15 15:21:18
Modified: src/share/org/apache/struts/digester Digester.java
Log:
Allow the application to register an ErrorHandler so that it is notified when
the parser encounters warnings, errors, or fatal errors. If the error handler
methods throw an exception, the parse will be aborted.
Revision Changes Path
1.19 +50 -11
jakarta-struts/src/share/org/apache/struts/digester/Digester.java
Index: Digester.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Digester.java 2001/04/15 22:02:27 1.18
+++ Digester.java 2001/04/15 22:21:18 1.19
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v 1.18
2001/04/15 22:02:27 craigmcc Exp $
- * $Revision: 1.18 $
- * $Date: 2001/04/15 22:02:27 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v 1.19
2001/04/15 22:21:18 craigmcc Exp $
+ * $Revision: 1.19 $
+ * $Date: 2001/04/15 22:21:18 $
*
* ====================================================================
*
@@ -79,6 +79,7 @@
import org.xml.sax.AttributeList;
import org.xml.sax.DocumentHandler;
import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
import org.xml.sax.HandlerBase;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
@@ -102,7 +103,7 @@
* even from the same thread.</p>
*
* @author Craig McClanahan
- * @version $Revision: 1.18 $ $Date: 2001/04/15 22:02:27 $
+ * @version $Revision: 1.19 $ $Date: 2001/04/15 22:21:18 $
*/
public class Digester extends HandlerBase {
@@ -150,6 +151,13 @@
/**
+ * The application-supplied error handler that is notified when parsing
+ * warnings, errors, or fatal errors occur.
+ */
+ protected ErrorHandler errorHandler = null;
+
+
+ /**
* The Locator associated with our parser.
*/
protected Locator locator = null;
@@ -209,7 +217,7 @@
/**
- * Return the debugging detail level of this Context.
+ * Return the debugging detail level of this Digester.
*/
public int getDebug() {
@@ -219,7 +227,7 @@
/**
- * Set the debugging detail level of this Context.
+ * Set the debugging detail level of this Digester.
*
* @param debug The new debugging detail level
*/
@@ -231,6 +239,28 @@
/**
+ * Return the error handler for this Digester.
+ */
+ public ErrorHandler getErrorHandler() {
+
+ return (this.errorHandler);
+
+ }
+
+
+ /**
+ * Set the error handler for this Digester.
+ *
+ * @param errorHandler The new error handler
+ */
+ public void setErrorHandler(ErrorHandler errorHandler) {
+
+ this.errorHandler = errorHandler;
+
+ }
+
+
+ /**
* Return the SAXParser we will use to parse the input stream. If there
* is a problem creating the parser, return <code>null</code>.
*/
@@ -588,9 +618,10 @@
/**
- * Receive notification of a recoverable parsing error.
+ * Forward notification of a parsing error to the application supplied
+ * error handler (if any).
*
- * @param exception The warning information
+ * @param exception The error information
*
* @exception SAXException if a parsing exception occurs
*/
@@ -599,14 +630,17 @@
log("Parse Error at line " + exception.getLineNumber() +
" column " + exception.getColumnNumber() + ": " +
exception.getMessage(), exception);
+ if (errorHandler != null)
+ errorHandler.error(exception);
}
/**
- * Receive notification of a fatal parsing error.
+ * Forward notification of a fatal parsing error to the application
+ * supplied error handler (if any).
*
- * @param exception The warning information
+ * @param exception The fatal error information
*
* @exception SAXException if a parsing exception occurs
*/
@@ -615,12 +649,15 @@
log("Parse Fatal Error at line " + exception.getLineNumber() +
" column " + exception.getColumnNumber() + ": " +
exception.getMessage(), exception);
+ if (errorHandler != null)
+ errorHandler.fatalError(exception);
}
/**
- * Receive notification of a parsing warning.
+ * Forward notification of a parse warning to the application supplied
+ * error handler (if any).
*
* @param exception The warning information
*
@@ -631,6 +668,8 @@
log("Parse Warning at line " + exception.getLineNumber() +
" column " + exception.getColumnNumber() + ": " +
exception.getMessage(), exception);
+ if (errorHandler != null)
+ errorHandler.warning(exception);
}