01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.xerces.jaxp;
19:
20: import org.xml.sax.SAXException;
21: import org.xml.sax.SAXParseException;
22: import org.xml.sax.helpers.DefaultHandler;
23:
24: /**
25: * @version $Id: DefaultValidationErrorHandler.java 447237 2006-09-18 05:03:10Z mrglavas $
26: */
27:
28: class DefaultValidationErrorHandler extends DefaultHandler {
29: static private int ERROR_COUNT_LIMIT = 10;
30: private int errorCount = 0;
31:
32: // XXX Fix message i18n
33: public void error(SAXParseException e) throws SAXException {
34: if (errorCount >= ERROR_COUNT_LIMIT) {
35: // Ignore all errors after reaching the limit
36: return;
37: } else if (errorCount == 0) {
38: // Print a warning before the first error
39: System.err
40: .println("Warning: validation was turned on but an org.xml.sax.ErrorHandler was not");
41: System.err
42: .println("set, which is probably not what is desired. Parser will use a default");
43: System.err.println("ErrorHandler to print the first "
44: + ERROR_COUNT_LIMIT + " errors. Please call");
45: System.err
46: .println("the 'setErrorHandler' method to fix this.");
47: }
48:
49: String systemId = e.getSystemId();
50: if (systemId == null) {
51: systemId = "null";
52: }
53: String message = "Error: URI=" + systemId + " Line="
54: + e.getLineNumber() + ": " + e.getMessage();
55: System.err.println(message);
56: errorCount++;
57: }
58: }
|