KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > jaxp > DefaultValidationErrorHandler


1 /*
2  * Copyright 2000-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.jaxp;
18
19 import org.xml.sax.SAXException JavaDoc;
20 import org.xml.sax.SAXParseException JavaDoc;
21 import org.xml.sax.helpers.DefaultHandler JavaDoc;
22
23 /**
24  * @version $Id: DefaultValidationErrorHandler.java,v 1.5 2004/02/24 23:15:58 mrglavas Exp $
25  */

26
27 class DefaultValidationErrorHandler extends DefaultHandler JavaDoc {
28     static private int ERROR_COUNT_LIMIT = 10;
29     private int errorCount = 0;
30
31     // XXX Fix message i18n
32
public void error(SAXParseException JavaDoc e) throws SAXException JavaDoc {
33         if (errorCount >= ERROR_COUNT_LIMIT) {
34             // Ignore all errors after reaching the limit
35
return;
36         } else if (errorCount == 0) {
37             // Print a warning before the first error
38
System.err.println("Warning: validation was turned on but an org.xml.sax.ErrorHandler was not");
39             System.err.println("set, which is probably not what is desired. Parser will use a default");
40             System.err.println("ErrorHandler to print the first " +
41                                ERROR_COUNT_LIMIT + " errors. Please call");
42             System.err.println("the 'setErrorHandler' method to fix this.");
43         }
44
45         String JavaDoc systemId = e.getSystemId();
46         if (systemId == null) {
47             systemId = "null";
48         }
49         String JavaDoc message = "Error: URI=" + systemId +
50             " Line=" + e.getLineNumber() +
51             ": " + e.getMessage();
52         System.err.println(message);
53         errorCount++;
54     }
55 }
56
Popular Tags