01: /*
02: * (C) Copyright Simulacra Media Ltd, 2004. All rights reserved.
03: *
04: * The program is provided "AS IS" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * Simulacra Media Ltd will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will Simulacra Media Ltd be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * Simulacra Media Ltd has been advised of the possibility of their occurrence.
11: * Simulacra Media Ltd will not be liable for any third party claims against you.
12: *
13: */
14:
15: package com.ibm.webdav.impl;
16:
17: import org.xml.sax.SAXParseException;
18:
19: public class WebDAVErrorHandler extends
20: org.xml.sax.helpers.DefaultHandler {
21:
22: private String resourceName = null;
23: private int errorCount = 0;
24:
25: /** Create an error listener for handling XML parsing errors in entity request
26: * or response bodies, or properties files.
27: *
28: * @param resourceName the URL of the resource involved in the request or response
29: */
30: public WebDAVErrorHandler(String resourceName) {
31: super ();
32: this .resourceName = resourceName;
33: }
34:
35: /**
36: * This method is called by the XML Parser when some error occurs.
37: * <p>
38: * This implementation prints the error to standard error and counts the errors
39: * detected. Applications can then access the number of errors in order to raise
40: * an exception after parsing.
41: * </p>
42: * @see org.xml.sax.helpers.DefaultHandler
43: */
44: public void error(SAXParseException e) throws SAXParseException {
45: errorCount++;
46:
47: System.err.println(resourceName + ":" + e.getLineNumber() + ":"
48: + e.getColumnNumber() + ": " + e.getMessage());
49: }
50:
51: public void warning(SAXParseException e) throws SAXParseException {
52: errorCount++;
53:
54: System.err.println(resourceName + ":" + e.getLineNumber() + ":"
55: + e.getColumnNumber() + ": " + e.getMessage());
56: }
57:
58: public void fatalError(SAXParseException e)
59: throws SAXParseException {
60: errorCount++;
61:
62: System.err.println(resourceName + ":" + e.getLineNumber() + ":"
63: + e.getColumnNumber() + ": " + e.getMessage());
64:
65: throw e;
66: }
67:
68: /** Return the nuber of errors counted by this error listener.
69: */
70: public int getErrorCount() {
71: return errorCount;
72: }
73: }
|