1 57 58 package com.sun.org.apache.xerces.internal.util; 59 60 import java.io.PrintWriter ; 61 62 import com.sun.org.apache.xerces.internal.xni.XNIException; 63 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; 64 import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException; 65 66 73 public class DefaultErrorHandler 74 implements XMLErrorHandler { 75 76 80 81 protected PrintWriter fOut; 82 83 87 91 public DefaultErrorHandler() { 92 this(new PrintWriter (System.err)); 93 } 95 99 public DefaultErrorHandler(PrintWriter out) { 100 fOut = out; 101 } 103 107 108 public void warning(String domain, String key, XMLParseException ex) 109 throws XNIException { 110 printError("Warning", ex); 111 } 113 114 public void error(String domain, String key, XMLParseException ex) 115 throws XNIException { 116 printError("Error", ex); 117 } 119 120 public void fatalError(String domain, String key, XMLParseException ex) 121 throws XNIException { 122 printError("Fatal Error", ex); 123 throw ex; 124 } 126 130 131 private void printError(String type, XMLParseException ex) { 132 133 fOut.print("["); 134 fOut.print(type); 135 fOut.print("] "); 136 String systemId = ex.getExpandedSystemId(); 137 if (systemId != null) { 138 int index = systemId.lastIndexOf('/'); 139 if (index != -1) 140 systemId = systemId.substring(index + 1); 141 fOut.print(systemId); 142 } 143 fOut.print(':'); 144 fOut.print(ex.getLineNumber()); 145 fOut.print(':'); 146 fOut.print(ex.getColumnNumber()); 147 fOut.print(": "); 148 fOut.print(ex.getMessage()); 149 fOut.println(); 150 fOut.flush(); 151 152 } 154 } | Popular Tags |