1 57 58 package com.sun.org.apache.xerces.internal.util; 59 60 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 61 import com.sun.org.apache.xerces.internal.xni.XNIException; 62 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; 63 import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException; 64 import org.xml.sax.ErrorHandler ; 65 import org.xml.sax.SAXException ; 66 import org.xml.sax.SAXParseException ; 67 68 77 public class ErrorHandlerWrapper 78 implements XMLErrorHandler { 79 80 84 85 protected ErrorHandler fErrorHandler; 86 87 91 92 public ErrorHandlerWrapper() {} 93 94 95 public ErrorHandlerWrapper(ErrorHandler errorHandler) { 96 setErrorHandler(errorHandler); 97 } 99 103 104 public void setErrorHandler(ErrorHandler errorHandler) { 105 fErrorHandler = errorHandler; 106 } 108 109 public ErrorHandler getErrorHandler() { 110 return fErrorHandler; 111 } 113 117 133 public void warning(String domain, String key, 134 XMLParseException exception) throws XNIException { 135 136 if (fErrorHandler != null) { 137 SAXParseException saxException = createSAXParseException(exception); 138 139 try { 140 fErrorHandler.warning(saxException); 141 } 142 catch (SAXParseException e) { 143 throw createXMLParseException(e); 144 } 145 catch (SAXException e) { 146 throw createXNIException(e); 147 } 148 } 149 150 } 152 168 public void error(String domain, String key, 169 XMLParseException exception) throws XNIException { 170 171 if (fErrorHandler != null) { 172 SAXParseException saxException = createSAXParseException(exception); 173 174 try { 175 fErrorHandler.error(saxException); 176 } 177 catch (SAXParseException e) { 178 throw createXMLParseException(e); 179 } 180 catch (SAXException e) { 181 throw createXNIException(e); 182 } 183 } 184 185 } 187 211 public void fatalError(String domain, String key, 212 XMLParseException exception) throws XNIException { 213 214 if (fErrorHandler != null) { 215 SAXParseException saxException = createSAXParseException(exception); 216 217 try { 218 fErrorHandler.fatalError(saxException); 219 } 220 catch (SAXParseException e) { 221 throw createXMLParseException(e); 222 } 223 catch (SAXException e) { 224 throw createXNIException(e); 225 } 226 } 227 228 } 230 234 235 protected static SAXParseException createSAXParseException(XMLParseException exception) { 236 return new SAXParseException (exception.getMessage(), 237 exception.getPublicId(), 238 exception.getExpandedSystemId(), 239 exception.getLineNumber(), 240 exception.getColumnNumber(), 241 exception.getException()); 242 } 244 245 protected static XMLParseException createXMLParseException(SAXParseException exception) { 246 final String fPublicId = exception.getPublicId(); 247 final String fExpandedSystemId = exception.getSystemId(); 248 final int fLineNumber = exception.getLineNumber(); 249 final int fColumnNumber = exception.getColumnNumber(); 250 XMLLocator location = new XMLLocator() { 251 public void setPublicId(String id) {} 252 public String getPublicId() { return fPublicId; } 253 public void setExpandedSystemId( String id) {} 254 public String getExpandedSystemId() { return fExpandedSystemId; } 255 public void setBaseSystemId(String id) {} 256 public String getBaseSystemId() { return null; } 257 public void setLiteralSystemId(String id) {} 258 public String getLiteralSystemId() { return null; } 259 public int getColumnNumber() { return fColumnNumber; } 260 public void setColumnNumber(int col) {} 261 public int getLineNumber() { return fLineNumber; } 262 public void setLineNumber(int line) {} 263 public String getEncoding() { return null; } 264 }; 265 return new XMLParseException(location, exception.getMessage(),exception); 266 } 268 271 protected static XNIException createXNIException(SAXException exception) { 272 return new XNIException(exception.getMessage(),exception); 273 } } | Popular Tags |