1
package com.thaiopensource.relaxng.output.common;
3
import org.xml.sax.ErrorHandler;
4
import org.xml.sax.SAXParseException;
5
import org.xml.sax.SAXException;
6
import com.thaiopensource.relaxng.edit.SourceLocation;
7
import com.thaiopensource.util.Localizer;
9
public class ErrorReporter {
10
private final Localizer localizer;
11
private final ErrorHandler eh;
12
private boolean hadError = false;
14
static public class WrappedSAXException extends RuntimeException {
15
private final SAXException exception;
17
private WrappedSAXException(SAXException exception) {
18
this.exception = exception;
21
public SAXException getException() {
26
public ErrorReporter(ErrorHandler eh, Class<?> cls) {
28
this.localizer = new Localizer(cls);
31
public void error(String key, SourceLocation loc) {
36
eh.error(makeParseException(localizer.message(key), loc));
38
catch (SAXException e) {
39
throw new WrappedSAXException(e);
43
public void error(String key, String arg, SourceLocation loc) {
48
eh.error(makeParseException(localizer.message(key, arg), loc));
50
catch (SAXException e) {
51
throw new WrappedSAXException(e);
55
public void error(String key, String arg1, String arg2, SourceLocation loc) {
60
eh.error(makeParseException(localizer.message(key, arg1, arg2), loc));
62
catch (SAXException e) {
63
throw new WrappedSAXException(e);
67
public void warning(String key, SourceLocation loc) {
71
eh.warning(makeParseException(localizer.message(key), loc));
73
catch (SAXException e) {
74
throw new WrappedSAXException(e);
78
public void warning(String key, String arg, SourceLocation loc) {
82
eh.warning(makeParseException(localizer.message(key, arg), loc));
84
catch (SAXException e) {
85
throw new WrappedSAXException(e);
89
public void warning(String key, String arg1, String arg2, SourceLocation loc) {
93
eh.warning(makeParseException(localizer.message(key, arg1, arg2), loc));
95
catch (SAXException e) {
96
throw new WrappedSAXException(e);
100
public boolean getHadError() {
104
private static SAXParseException makeParseException(String message, SourceLocation loc) {
106
return new SAXParseException(message, null);
107
return new SAXParseException(message,
111
loc.getColumnNumber());
114
public Localizer getLocalizer() {