You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2001/11/16 15:23:00 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/parsers AbstractSAXParser.java DOMParser.java

neilg       01/11/16 06:23:00

  Modified:    java/src/org/apache/xerces/parsers AbstractSAXParser.java
                        DOMParser.java
  Log:
  when a parser receives an XMLParseException that is not wrapping another exception, throw a SAXParseException to the application instead of a SAXExcption so that the application can extract locator information if it chooses to do so.
  
  Revision  Changes    Path
  1.6       +46 -1     xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java
  
  Index: AbstractSAXParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractSAXParser.java	2001/11/06 19:23:33	1.5
  +++ AbstractSAXParser.java	2001/11/16 14:22:59	1.6
  @@ -74,6 +74,7 @@
   import org.apache.xerces.xni.XMLLocator;
   import org.apache.xerces.xni.XMLString;
   import org.apache.xerces.xni.XNIException;
  +import org.apache.xerces.xni.parser.XMLParseException;
   import org.apache.xerces.xni.parser.XMLConfigurationException;
   import org.apache.xerces.xni.parser.XMLEntityResolver;
   import org.apache.xerces.xni.parser.XMLErrorHandler;
  @@ -91,11 +92,13 @@
   import org.xml.sax.Locator;
   import org.xml.sax.Parser;
   import org.xml.sax.SAXException;
  +import org.xml.sax.SAXParseException;
   import org.xml.sax.SAXNotRecognizedException;
   import org.xml.sax.SAXNotSupportedException;
   import org.xml.sax.XMLReader;
   import org.xml.sax.ext.DeclHandler;
   import org.xml.sax.ext.LexicalHandler;
  +import org.xml.sax.helpers.LocatorImpl;
   
   /**
    * This is the base class of all SAX parsers. It implements both the
  @@ -106,7 +109,7 @@
    * @author Arnaud Le Hors, IBM
    * @author Andy Clark, IBM
    *
  - * @version $Id: AbstractSAXParser.java,v 1.5 2001/11/06 19:23:33 sandygao Exp $
  + * @version $Id: AbstractSAXParser.java,v 1.6 2001/11/16 14:22:59 neilg Exp $
    */
   public abstract class AbstractSAXParser
       extends AbstractXMLDocumentParser
  @@ -914,6 +917,27 @@
           }
   
           // wrap XNI exceptions as SAX exceptions
  +        catch (XMLParseException e) {
  +            Exception ex = e.getException();
  +            if (ex == null) {
  +                // must be a parser exception; mine it for locator info and throw
  +                // a SAXParseException
  +                LocatorImpl locatorImpl = new LocatorImpl();
  +                locatorImpl.setPublicId(e.getPublicId());
  +                locatorImpl.setSystemId(e.getSystemId());
  +                locatorImpl.setLineNumber(e.getLineNumber());
  +                locatorImpl.setColumnNumber(e.getColumnNumber());
  +                throw new SAXParseException(e.getMessage(), locatorImpl);
  +            }
  +            if (ex instanceof SAXException) {
  +                // why did we create an XMLParseException?
  +                throw (SAXException)ex;
  +            }
  +            if (ex instanceof IOException) {
  +                throw (IOException)ex;
  +            }
  +            throw new SAXException(ex);
  +        }
           catch (XNIException e) {
               Exception ex = e.getException();
               if (ex == null) {
  @@ -973,6 +997,27 @@
           }
   
           // wrap XNI exceptions as SAX exceptions
  +        catch (XMLParseException e) {
  +            Exception ex = e.getException();
  +            if (ex == null) {
  +                // must be a parser exception; mine it for locator info and throw
  +                // a SAXParseException
  +                LocatorImpl locatorImpl = new LocatorImpl();
  +                locatorImpl.setPublicId(e.getPublicId());
  +                locatorImpl.setSystemId(e.getSystemId());
  +                locatorImpl.setLineNumber(e.getLineNumber());
  +                locatorImpl.setColumnNumber(e.getColumnNumber());
  +                throw new SAXParseException(e.getMessage(), locatorImpl);
  +            }
  +            if (ex instanceof SAXException) {
  +                // why did we create an XMLParseException?
  +                throw (SAXException)ex;
  +            }
  +            if (ex instanceof IOException) {
  +                throw (IOException)ex;
  +            }
  +            throw new SAXException(ex);
  +        }
           catch (XNIException e) {
               Exception ex = e.getException();
               if (ex == null) {
  
  
  
  1.54      +48 -3     xml-xerces/java/src/org/apache/xerces/parsers/DOMParser.java
  
  Index: DOMParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/DOMParser.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- DOMParser.java	2001/10/25 14:19:46	1.53
  +++ DOMParser.java	2001/11/16 14:22:59	1.54
  @@ -66,6 +66,7 @@
   import org.apache.xerces.util.ErrorHandlerWrapper;
   import org.apache.xerces.util.SymbolTable;
   import org.apache.xerces.xni.XNIException;
  +import org.apache.xerces.xni.parser.XMLParseException;
   import org.apache.xerces.xni.parser.XMLConfigurationException;
   import org.apache.xerces.xni.parser.XMLEntityResolver;
   import org.apache.xerces.xni.parser.XMLErrorHandler;
  @@ -76,8 +77,10 @@
   import org.xml.sax.ErrorHandler;
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  +import org.xml.sax.SAXParseException;
   import org.xml.sax.SAXNotRecognizedException;
   import org.xml.sax.SAXNotSupportedException;
  +import org.xml.sax.helpers.LocatorImpl;
   
   /**
    * This is the main Xerces DOM parser class. It uses the abstract DOM
  @@ -88,7 +91,7 @@
    * @author Arnaud  Le Hors, IBM
    * @author Andy Clark, IBM
    *
  - * @version $Id: DOMParser.java,v 1.53 2001/10/25 14:19:46 elena Exp $ 
  + * @version $Id: DOMParser.java,v 1.54 2001/11/16 14:22:59 neilg Exp $ 
    */
   public class DOMParser
       extends AbstractDOMParser {
  @@ -152,7 +155,28 @@
               parse(source);
           }
   
  -        // wrap XNI exceptions as SAX exceptions
  +        // wrap XNI exceptions as SAX exceptions 
  +        catch (XMLParseException e) {
  +            Exception ex = e.getException();
  +            if (ex == null) {
  +                // must be a parser exception; mine it for locator info and throw
  +                // a SAXParseException
  +                LocatorImpl locatorImpl = new LocatorImpl();
  +                locatorImpl.setPublicId(e.getPublicId());
  +                locatorImpl.setSystemId(e.getSystemId());
  +                locatorImpl.setLineNumber(e.getLineNumber());
  +                locatorImpl.setColumnNumber(e.getColumnNumber());
  +                throw new SAXParseException(e.getMessage(), locatorImpl);
  +            }
  +            if (ex instanceof SAXException) {
  +                // why did we create an XMLParseException?
  +                throw (SAXException)ex;
  +            }
  +            if (ex instanceof IOException) {
  +                throw (IOException)ex;
  +            }
  +            throw new SAXException(ex);
  +        }
           catch (XNIException e) {
               Exception ex = e.getException();
               if (ex == null) {
  @@ -211,7 +235,28 @@
               parse(xmlInputSource);
           }
   
  -        // wrap XNI exceptions as SAX exceptions
  +        // wrap XNI exceptions as SAX exceptions 
  +        catch (XMLParseException e) {
  +            Exception ex = e.getException();
  +            if (ex == null) {
  +                // must be a parser exception; mine it for locator info and throw
  +                // a SAXParseException
  +                LocatorImpl locatorImpl = new LocatorImpl();
  +                locatorImpl.setPublicId(e.getPublicId());
  +                locatorImpl.setSystemId(e.getSystemId());
  +                locatorImpl.setLineNumber(e.getLineNumber());
  +                locatorImpl.setColumnNumber(e.getColumnNumber());
  +                throw new SAXParseException(e.getMessage(), locatorImpl);
  +            }
  +            if (ex instanceof SAXException) {
  +                // why did we create an XMLParseException?
  +                throw (SAXException)ex;
  +            }
  +            if (ex instanceof IOException) {
  +                throw (IOException)ex;
  +            }
  +            throw new SAXException(ex);
  +        }
           catch (XNIException e) {
               Exception ex = e.getException();
               if (ex == null) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org