1 16 17 package org.apache.xerces.util; 18 19 import java.io.PrintWriter ; 20 21 import org.apache.xerces.xni.XNIException; 22 import org.apache.xerces.xni.parser.XMLErrorHandler; 23 import org.apache.xerces.xni.parser.XMLParseException; 24 25 32 public class DefaultErrorHandler 33 implements XMLErrorHandler { 34 35 39 40 protected PrintWriter fOut; 41 42 46 50 public DefaultErrorHandler() { 51 this(new PrintWriter (System.err)); 52 } 54 58 public DefaultErrorHandler(PrintWriter out) { 59 fOut = out; 60 } 62 66 67 public void warning(String domain, String key, XMLParseException ex) 68 throws XNIException { 69 printError("Warning", ex); 70 } 72 73 public void error(String domain, String key, XMLParseException ex) 74 throws XNIException { 75 printError("Error", ex); 76 } 78 79 public void fatalError(String domain, String key, XMLParseException ex) 80 throws XNIException { 81 printError("Fatal Error", ex); 82 throw ex; 83 } 85 89 90 private void printError(String type, XMLParseException ex) { 91 92 fOut.print("["); 93 fOut.print(type); 94 fOut.print("] "); 95 String systemId = ex.getExpandedSystemId(); 96 if (systemId != null) { 97 int index = systemId.lastIndexOf('/'); 98 if (index != -1) 99 systemId = systemId.substring(index + 1); 100 fOut.print(systemId); 101 } 102 fOut.print(':'); 103 fOut.print(ex.getLineNumber()); 104 fOut.print(':'); 105 fOut.print(ex.getColumnNumber()); 106 fOut.print(": "); 107 fOut.print(ex.getMessage()); 108 fOut.println(); 109 fOut.flush(); 110 111 } 113 } | Popular Tags |