| SimpleErrorHandler |

    1   /*
    2    *  SimpleErrorHandle.java
    3    *
    4    *  Copyright (c) 1998-2001, The University of Sheffield.
    5    *
    6    *  This file is part of GATE (see http://gate.ac.uk/), and is free
    7    *  software, licenced under the GNU Library General Public License,
    8    *  Version 2, June 1991 (in the distribution as file licence.html,
    9    *  and also available at http://gate.ac.uk/gate/licence.html).
    10   *
    11   *  Cristian URSU,  8/May/2000
    12   *
    13   *  $Id: SimpleErrorHandler.java,v 1.11 2001/11/01 13:11:33 cursu Exp $
    14   */
    15
    16  package gate.xml;
    17
    18  import java.io.*;
    19  import org.xml.sax.*;
    20
    21  import gate.util.*;
    22
    23  public class SimpleErrorHandler implements ErrorHandler {
    24
    25    /** Debug flag */
    26    private static final boolean DEBUG = false;
    27
    28    /**
    29      * SimpleErrorHandler constructor comment.
    30      */
    31    public SimpleErrorHandler() {
    32      super();
    33    }
    34
    35    /**
    36      * This error method is called by the SAX parser when it encounts a
    37      * recoverable(can continue parsing) error.
    38      */
    39    public void error(SAXParseException ex) throws SAXException {
    40      String systemId = "not available";
    41      String publicId = "not available";
    42      if (ex.getSystemId() != null) systemId = ex.getSystemId();
    43      if (ex.getPublicId() != null) publicId = ex.getPublicId();
    44      Out.prln("\nSAX parser recoverable error. Error details: \n"+
    45                                  " Message: " + ex.getMessage() + "\n" +
    46                                  " System ID: " + systemId +  "\n" +
    47                                  " Public ID: " + publicId +  "\n" +
    48                                  " Line: " + ex.getLineNumber() + "\n" +
    49                                  " Column: "+ ex.getColumnNumber() + "\n");
    50    }// error
    51    /**
    52      * This fatalError method is called by the SAX parser when it encounts a
    53      * fatal(can't continue parsing) error.
    54      */
    55    public void fatalError(SAXParseException ex) throws SAXException{
    56      String systemId = "not available";
    57      String publicId = "not available";
    58      if (ex.getSystemId() != null) systemId = ex.getSystemId();
    59      if (ex.getPublicId() != null) publicId = ex.getPublicId();
    60      throw new GateSaxException("Fatal XML parse error. Error details: \n"+
    61                                  " Message: " + ex.getMessage() + "\n" +
    62                                  " System ID: " + systemId +  "\n" +
    63                                  " Public ID: " + publicId +  "\n" +
    64                                  " Line: " + ex.getLineNumber() + "\n" +
    65                                  " Column: "+ ex.getColumnNumber());
    66    }// fatalError
    67    /**
    68      * This warning is called by the SAX parser when there is the danger of a
    69      * confusion.
    70      */
    71    public void warning(SAXParseException ex) throws SAXException {
    72      String systemId = "not available";
    73      String publicId = "not available";
    74      if (ex.getSystemId() != null) systemId = ex.getSystemId();
    75      if (ex.getPublicId() != null) publicId = ex.getPublicId();
    76      Out.prln("SAX parser warning. Warning details: \n"+
    77                                  " Message: " + ex.getMessage() + "\n" +
    78                                  " System ID: " + systemId +  "\n" +
    79                                  " Public ID: " + publicId +  "\n" +
    80                                  " Line: " + ex.getLineNumber() + "\n" +
    81                                  " Column: "+ ex.getColumnNumber());
    82    }// warning
    83  }// end class SimpleErrorHandler
    84

| SimpleErrorHandler |