1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
30
* (C)opyright 2003-2005, by Thomas Morgner and Contributors.
32
* Original Author: Thomas Morgner;
33
* Contributor(s): David Gilbert (for Object Refinery Limited);
35
* $Id: ParseException.java,v 1.4 2005/10/18 13:25:44 mungady Exp $
38
* -------------------------
39
* 10.06.2003 : Initial version
43
package org.jfree.xml;
45
import java.io.PrintStream;
46
import java.io.PrintWriter;
48
import org.xml.sax.Locator;
49
import org.xml.sax.SAXException;
54
* @author Thomas Morgner
56
public class ParseException extends SAXException {
58
/** The line, where the error occured. */
61
/** The column, where the error occured. */
65
* Creates a new ParseException with the given message.
67
* @param message the message
69
public ParseException(final String message) {
75
* Creates a new ParseException with the given root exception.
77
* @param e the exception
79
public ParseException(final Exception e) {
85
* Creates a new ParseException with the given message and root exception.
87
* @param s the message
88
* @param e the exception
90
public ParseException(final String s, final Exception e) {
96
* Creates a new ParseException with the given message and the locator.
98
* @param message the message
99
* @param locator the locator of the parser
101
public ParseException(final String message, final Locator locator) {
103
fillLocation(locator);
107
* Creates a new ParseException with the given root exception
110
* @param e the exception
111
* @param locator the locator of the parser
113
public ParseException(final Exception e, final Locator locator) {
115
fillLocation(locator);
119
* Creates a new ParseException with the given message, root exception
122
* @param s the message
123
* @param e the exception
124
* @param locator the locator of the parser
126
public ParseException(final String s, final Exception e, final Locator locator) {
128
fillLocation(locator);
132
* Modifies the message to give more detailed location information.
134
* @return the modified exception message.
136
public String getMessage() {
137
final StringBuffer message = new StringBuffer(String.valueOf(super.getMessage()));
138
message.append(" [Location: Line=");
139
message.append(this.line);
140
message.append(" Column=");
141
message.append(this.column);
142
message.append("] ");
143
return message.toString();
147
* Fills the location with the given locator.
149
* @param locator the locator or null.
151
protected void fillLocation (final Locator locator) {
152
if (locator == null) {
157
this.line = locator.getLineNumber();
158
this.column = locator.getColumnNumber();
163
* Returns the line of the parse position where the error occured.
165
* @return the line number or -1 if not known.
167
public int getLine() {
172
* Returns the column of the parse position where the error occured.
174
* @return the column number or -1 if not known.
176
public int getColumn() {
182
* Prints the stack trace to the specified stream.
184
* @param stream the output stream.
186
public void printStackTrace(final PrintStream stream) {
187
super.printStackTrace(stream);
188
if (getException() != null) {
189
stream.println("ParentException: ");
190
getException().printStackTrace(stream);
195
* Override toString to pick up any embedded exception.
197
* @return A string representation of this exception.
199
public String toString() {
200
return getClass().getName() + ": " + getMessage();
204
* Prints the stack trace to the specified writer.
206
* @param writer the writer.
208
public void printStackTrace(final PrintWriter writer) {
209
super.printStackTrace(writer);
210
if (getException() != null) {
211
writer.println("ParentException: ");
212
getException().printStackTrace(writer);