1 /**
2 * AUTOHIT 2003
3 * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Additional license information can be found in the documentation.
19 * @author Erich P Gatejen
20 */
21 package autohit.creator.compiler;
22
23 import org.xml.sax.ErrorHandler;
24 import org.xml.sax.SAXException;
25 import org.xml.sax.SAXParseException;
26
27 /**
28 * Parse Error Handler. It will just collect the errors in a list for use later.
29 *
30 * WARNING!!! An instance of this must be registered with the parser
31 * before EACH compile.
32 *
33 * @author Erich P. Gatejen
34 * @version 1.1
35 * <i>Version History</i>
36 * <code>EPG - Initial - 10Apr03</code>
37 *
38 */
39 public class XmlParseErrorHandler implements ErrorHandler {
40
41 /**
42 * Keep a reference to the Xml compiler, so we can get
43 * to the logging funktions.
44 */
45 public XmlCompiler xc;
46
47 /**
48 * Constructor. Takes a reference to the XmlCompiler so
49 * we can get to the logging functions. You can use the default
50 * constructor, but you better set xc or you will get undefined
51 * results.
52 * @param xcp A valid XmlCompiler
53 * @see autohit.creator.compiler.XmlCompiler
54 */
55 public XmlParseErrorHandler(XmlCompiler xcp) throws Exception {
56 super(); // Call constructor for HandlerBase()
57 xc = xcp;
58 }
59
60 /**
61 * Default constructor.
62 */
63 public XmlParseErrorHandler() throws Exception {
64 super(); // Call constructor for HandlerBase()
65 }
66
67 /**
68 * Add an error to the error log.
69 */
70 public void emitError(String text) {
71 xc.runtimeError(text);
72 }
73
74 /**
75 * Add an debug notice to the error log.
76 */
77 public void emitWarning(String text) {
78 xc.runtimeWarning(text);
79 }
80
81 /**
82 * Add an warning to the error log.
83 */
84 public void emitDebug(String text) {
85 xc.runtimeDebug(text);
86 }
87
88 /**
89 * Receive an error from the compiler. Do not call this method directly.
90 *
91 * @throws SAXException Send back to document builder
92 */
93 public void error(SAXParseException e) throws SAXException {
94
95 String entry =
96 "ParseError @line #" + e.getLineNumber() + ":" + e.getMessage();
97 emitError(entry);
98
99 //throw e; // Do I want to can these?
100 }
101
102 /**
103 * Receive a fatal error from the compiler. Do not call this method directly.
104 *
105 * @throws SAXException Send back to document builder
106 */
107 public void fatalError(SAXParseException e) throws SAXException {
108
109 String entry =
110 "FATAL ParseError @line #"
111 + e.getLineNumber()
112 + ":"
113 + e.getMessage();
114 emitError(entry);
115
116 //throw e; // Do I want to can these?
117 }
118
119 /**
120 * Receive a warning from the compiler. Do not call this method directly.
121 *
122 * @throws SAXException Send back to document builder
123 */
124 public void warning(SAXParseException e) throws SAXException {
125
126 // trap a "!DOCTYPE" error and let the user know
127 // if (e.getMessage().indexOf("<!DOCTYPE", 0) > 0) {
128 // BIG No
129 // errors.add(
130 // "Does not have a proper <!DOCTYPE>. Add or fix it. It should look something like <!DOCTYPE sim SYSTEM \"file:sim.dtd\">");
131 // throw e;
132
133 // } else {
134
135 String entry =
136 "ParseWarning @line #" + e.getLineNumber() + ":" + e.getMessage();
137 emitWarning(entry);
138 // }
139 // throw e; // Keep chugging on a warning.
140 }
141
142 }
|