1 package com.thaiopensource.xml.sax; 2 3 import org.xml.sax.ErrorHandler ; 4 import org.xml.sax.SAXParseException ; 5 import org.xml.sax.SAXException ; 6 7 public class CountingErrorHandler implements ErrorHandler { 8 private ErrorHandler errorHandler; 9 private int fatalErrorCount = 0; 10 private int errorCount = 0; 11 private int warningCount = 0; 12 private boolean hadErrorOrFatalError = false; 13 14 public CountingErrorHandler() { 15 this(null); 16 } 17 18 public CountingErrorHandler(ErrorHandler errorHandler) { 19 this.errorHandler = errorHandler; 20 } 21 22 public void reset() { 23 fatalErrorCount = 0; 24 errorCount = 0; 25 warningCount = 0; 26 hadErrorOrFatalError = false; 27 } 28 29 public boolean getHadErrorOrFatalError() { 30 return hadErrorOrFatalError; 31 } 32 33 public int getFatalErrorCount() { 34 return fatalErrorCount; 35 } 36 37 public int getErrorCount() { 38 return errorCount; 39 } 40 41 public int getWarningCount() { 42 return warningCount; 43 } 44 45 public ErrorHandler getErrorHandler() { 46 return errorHandler; 47 } 48 49 public void setErrorHandler(ErrorHandler errorHandler) { 50 this.errorHandler = errorHandler; 51 } 52 53 public void warning(SAXParseException exception) 54 throws SAXException { 55 warningCount++; 56 if (errorHandler != null) 57 errorHandler.warning(exception); 58 } 59 60 public void error(SAXParseException exception) 61 throws SAXException { 62 errorCount++; 63 hadErrorOrFatalError = true; 64 if (errorHandler != null) 65 errorHandler.error(exception); 66 } 67 68 public void fatalError(SAXParseException exception) 69 throws SAXException { 70 fatalErrorCount++; 71 hadErrorOrFatalError = true; 72 if (errorHandler != null) 73 errorHandler.fatalError(exception); 74 } 75 } 76 | Popular Tags |